Fixed ClassFilterAwareUnionMethodMatcher equals implementation
Issue: SPR-10604
This commit is contained in:
parent
9e20a25607
commit
f329140dd4
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -102,8 +102,9 @@ public abstract class MethodMatchers {
|
|||
@SuppressWarnings("serial")
|
||||
private static class UnionMethodMatcher implements IntroductionAwareMethodMatcher, Serializable {
|
||||
|
||||
private MethodMatcher mm1;
|
||||
private MethodMatcher mm2;
|
||||
private final MethodMatcher mm1;
|
||||
|
||||
private final MethodMatcher mm2;
|
||||
|
||||
public UnionMethodMatcher(MethodMatcher mm1, MethodMatcher mm2) {
|
||||
Assert.notNull(mm1, "First MethodMatcher must not be null");
|
||||
|
@ -172,6 +173,7 @@ public abstract class MethodMatchers {
|
|||
private static class ClassFilterAwareUnionMethodMatcher extends UnionMethodMatcher {
|
||||
|
||||
private final ClassFilter cf1;
|
||||
|
||||
private final ClassFilter cf2;
|
||||
|
||||
public ClassFilterAwareUnionMethodMatcher(MethodMatcher mm1, ClassFilter cf1, MethodMatcher mm2, ClassFilter cf2) {
|
||||
|
@ -195,11 +197,17 @@ public abstract class MethodMatchers {
|
|||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof ClassFilterAwareUnionMethodMatcher)) {
|
||||
if (!super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
ClassFilterAwareUnionMethodMatcher that = (ClassFilterAwareUnionMethodMatcher) other;
|
||||
return (this.cf1.equals(that.cf1) && this.cf2.equals(that.cf2) && super.equals(other));
|
||||
ClassFilter otherCf1 = ClassFilter.TRUE;
|
||||
ClassFilter otherCf2 = ClassFilter.TRUE;
|
||||
if (other instanceof ClassFilterAwareUnionMethodMatcher) {
|
||||
ClassFilterAwareUnionMethodMatcher cfa = (ClassFilterAwareUnionMethodMatcher) other;
|
||||
otherCf1 = cfa.cf1;
|
||||
otherCf2 = cfa.cf2;
|
||||
}
|
||||
return (this.cf1.equals(otherCf1) && this.cf2.equals(otherCf2));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,8 +218,9 @@ public abstract class MethodMatchers {
|
|||
@SuppressWarnings("serial")
|
||||
private static class IntersectionMethodMatcher implements IntroductionAwareMethodMatcher, Serializable {
|
||||
|
||||
private MethodMatcher mm1;
|
||||
private MethodMatcher mm2;
|
||||
private final MethodMatcher mm1;
|
||||
|
||||
private final MethodMatcher mm2;
|
||||
|
||||
public IntersectionMethodMatcher(MethodMatcher mm1, MethodMatcher mm2) {
|
||||
Assert.notNull(mm1, "First MethodMatcher must not be null");
|
||||
|
|
|
@ -43,6 +43,7 @@ public final class MethodMatchersTests {
|
|||
|
||||
private final Method IOTHER_ABSQUATULATE;
|
||||
|
||||
|
||||
public MethodMatchersTests() throws Exception {
|
||||
EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage", (Class[]) null);
|
||||
ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge", (Class[]) null);
|
||||
|
@ -50,6 +51,7 @@ public final class MethodMatchersTests {
|
|||
IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultMatchesAll() throws Exception {
|
||||
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
||||
|
@ -99,23 +101,33 @@ public final class MethodMatchersTests {
|
|||
assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class));
|
||||
assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionEquals() {
|
||||
MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE);
|
||||
MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher();
|
||||
assertTrue(first.equals(second));
|
||||
assertTrue(second.equals(first));
|
||||
}
|
||||
|
||||
|
||||
public static class StartsWithMatcher extends StaticMethodMatcher {
|
||||
private String prefix;
|
||||
|
||||
private final String prefix;
|
||||
|
||||
public StartsWithMatcher(String s) {
|
||||
this.prefix = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method m, Class<?> targetClass) {
|
||||
return m.getName().startsWith(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher {
|
||||
|
||||
@Override
|
||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
||||
return true;
|
||||
|
@ -123,6 +135,7 @@ public final class MethodMatchersTests {
|
|||
}
|
||||
|
||||
private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher {
|
||||
|
||||
@Override
|
||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue