Introduce reverse on ClassFilter and MethodFilter

See gh-26725
This commit is contained in:
Jinhui-Z
2021-03-25 14:06:34 +08:00
committed by Stephane Nicoll
parent c91841883c
commit 13e62d0b8e
4 changed files with 132 additions and 0 deletions

View File

@@ -66,4 +66,13 @@ class ClassFiltersTests {
.matches("^.+IntersectionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+NestedRuntimeException\\]$");
}
@Test
void reversion() {
assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
ClassFilter reversion = ClassFilters.reversion(exceptionFilter);
assertThat(reversion.matches(RuntimeException.class)).isFalse();
assertThat(reversion.toString())
.matches("^.+ReversionClassFilter: .+RootClassFilter: .+Exception$");
}
}

View File

@@ -111,6 +111,19 @@ public class MethodMatchersTests {
assertThat(second.equals(first)).isTrue();
}
@Test
public void testDynamicAndStaticMethodMatcherReversion() throws Exception {
MethodMatcher getterMatcher = new StartsWithMatcher("get");
MethodMatcher reversion = MethodMatchers.reversion(getterMatcher);
assertThat(reversion.isRuntime()).as("Reversion is a static matcher").isFalse();
assertThat(reversion.matches(ITESTBEAN_GETAGE, TestBean.class)).as("Didn't matched getAge method").isFalse();
assertThat(reversion.matches(IOTHER_ABSQUATULATE, TestBean.class)).as("Matched absquatulate method").isTrue();
reversion = MethodMatchers.reversion(new TestDynamicMethodMatcherWhichDoesNotMatch());
assertThat(reversion.isRuntime()).as("Intersection is a dynamic matcher").isTrue();
assertThat(reversion.matches(ITESTBEAN_SETAGE, TestBean.class)).as("Didn't matched setAge method").isFalse();
assertThat(reversion.matches(ITESTBEAN_SETAGE, TestBean.class, 5)).as("Matched setAge method").isTrue();
}
public static class StartsWithMatcher extends StaticMethodMatcher {