Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MethodUtil to make hasProperty() work for Java Records #426

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Commits on Nov 10, 2024

  1. Add MethodUtil to make hasProperty() work for Java Records

    The current `hasProperty()` matcher can't deal with
    Java Records, as they are not compatible with JavaBeans
    specification.
    
    In this change, `HasProperty` first tries to do
    the original thing and then tries to find a method
    of which name is equivalent to the given property name,
    if there's no matching property.
    
    So for example,
    if the class has a getter method named `property()`,
    `hasProperty()` would regard it as the class has
    a property named `property`.
    
    I hope this change might be properly and easily removed
    when the time comes and Hamcrest starts to support Java 17.
    djkeh committed Nov 10, 2024
    Configuration menu
    Copy the full SHA
    8201577 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f71c10b View commit details
    Browse the repository at this point in the history
  3. Fix MethodUtil to see if a method is a getter

    There is a flaw in 8201577, which is that
    the logic can't distinguish if the found method is a getter.
    Let's put a simple additional rule:
    The property must be a getter,
    so it should return something.
    djkeh committed Nov 10, 2024
    Configuration menu
    Copy the full SHA
    b1809a2 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    587ca12 View commit details
    Browse the repository at this point in the history