Introduce and() methods in MethodFilter & FieldFilter for composition
This commit introduces `and()` default methods in the MethodFilter and FieldFilter functional interfaces in ReflectionUtils in order to simplify uses cases that need to compose filter logic. Closes gh-26063
This commit is contained in:
@@ -186,12 +186,7 @@ class ReflectionUtilsTests {
|
||||
@Test
|
||||
void doWithProtectedMethods() {
|
||||
ListSavingMethodCallback mc = new ListSavingMethodCallback();
|
||||
ReflectionUtils.doWithMethods(TestObject.class, mc, new ReflectionUtils.MethodFilter() {
|
||||
@Override
|
||||
public boolean matches(Method m) {
|
||||
return Modifier.isProtected(m.getModifiers());
|
||||
}
|
||||
});
|
||||
ReflectionUtils.doWithMethods(TestObject.class, mc, method -> Modifier.isProtected(method.getModifiers()));
|
||||
assertThat(mc.getMethodNames().isEmpty()).isFalse();
|
||||
assertThat(mc.getMethodNames().contains("clone")).as("Must find protected method on Object").isTrue();
|
||||
assertThat(mc.getMethodNames().contains("finalize")).as("Must find protected method on Object").isTrue();
|
||||
|
||||
Reference in New Issue
Block a user