-
Notifications
You must be signed in to change notification settings - Fork 379
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
Make hasProperty()
, hasPropertyAtPath()
, samePropertyValuesAs()
work for Java Records
#426
base: master
Are you sure you want to change the base?
Commits on Nov 10, 2024
-
Add
MethodUtil
to makehasProperty()
work for Java RecordsThe 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.
Configuration menu - View commit details
-
Copy full SHA for 8201577 - Browse repository at this point
Copy the full SHA 8201577View commit details -
Configuration menu - View commit details
-
Copy full SHA for f71c10b - Browse repository at this point
Copy the full SHA f71c10bView commit details -
Fix
MethodUtil
to see if a method is a getterThere 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.
Configuration menu - View commit details
-
Copy full SHA for b1809a2 - Browse repository at this point
Copy the full SHA b1809a2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 587ca12 - Browse repository at this point
Copy the full SHA 587ca12View commit details
Commits on Nov 18, 2024
-
Move functionalities of
MethodUtil
toPropertyUtil
After the debate of pr hamcrest#426, We decided to move all the methods of `MethodUtil` to `PropertyUtil`. There was a confusion of understanding the name of the class `PropertyUtil`. First I thought it was kind of a technical name indicating that `PropertyUtil` deals with java beans property. But actually it wasn't just a technical name. `PropertyUtil` means a tool to find out some properties in the target class. So to say, it is like a `PropertyFindingUtil`. We don't have to change the utility name even if it finds some methods of the target class, not properties of it, as it does what it is meant to do.
Configuration menu - View commit details
-
Copy full SHA for 958682e - Browse repository at this point
Copy the full SHA 958682eView commit details
Commits on Nov 19, 2024
-
Refactor
HasPropertyWithValue
using lambda expressionand polished its javadoc.
Configuration menu - View commit details
-
Copy full SHA for dbe26b4 - Browse repository at this point
Copy the full SHA dbe26b4View commit details
Commits on Nov 20, 2024
-
Implement matching conditions of
HasPropertyWithValue
for Java RecordsThe basic approach is as same as the `HasProperty` in 8201577. `hasProperty(propertyName, valueMatcher)` will recognize properties in java record classes if: 1. There's a method of which name is same to the given property name 2. The found method returns something If it doesn't meet condition 1, the property does not exist. If it doesn't meet condition 2, the property is write-only.
Configuration menu - View commit details
-
Copy full SHA for 84c238b - Browse repository at this point
Copy the full SHA 84c238bView commit details
Commits on Nov 24, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 0fb657c - Browse repository at this point
Copy the full SHA 0fb657cView commit details -
Implement matching conditions of
SamePropertyValuesAs
for Java RecordsTo achieve this goal I needed a different approach from 8201577. `samePropertyValuesAs(expectedBean, ignoredProperties)` will recognize properties in java record classes if: * There's a read accessor method of which name is same to the given property name A read accessor method is a method which acts like a getter for a field. To check if the method is a read accessor method, the algorithm filters the following: 1. The name of it should be identical to the name of the field. 2. It should return something. 3. It should not have any method parameters. In this manner, we can now assure that the collected methods are getters. ## Reference * https://docs.oracle.com/en/java/javase/14/language/records.html
Configuration menu - View commit details
-
Copy full SHA for 5068e67 - Browse repository at this point
Copy the full SHA 5068e67View commit details -
Remove unused method in
PropertyUtil
The former implementation `methodDescriptorsFor()` can be replaced to the new method `recordReadAccessorMethodDescriptorsFor()`. This doesn't change current behavior except one, the case for the non-readable property. Actually, there can't be any non-readable property in Java Records by its specification.
Configuration menu - View commit details
-
Copy full SHA for c397cbf - Browse repository at this point
Copy the full SHA c397cbfView commit details