Fixed ClassFilterAwareUnionMethodMatcher equals implementation
Issue: SPR-10604
(cherry picked from commit f329140)
This commit is contained in:
parent
b0675c031e
commit
e30b842316
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -102,8 +102,9 @@ public abstract class MethodMatchers {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class UnionMethodMatcher implements IntroductionAwareMethodMatcher, Serializable {
|
private static class UnionMethodMatcher implements IntroductionAwareMethodMatcher, Serializable {
|
||||||
|
|
||||||
private MethodMatcher mm1;
|
private final MethodMatcher mm1;
|
||||||
private MethodMatcher mm2;
|
|
||||||
|
private final MethodMatcher mm2;
|
||||||
|
|
||||||
public UnionMethodMatcher(MethodMatcher mm1, MethodMatcher mm2) {
|
public UnionMethodMatcher(MethodMatcher mm1, MethodMatcher mm2) {
|
||||||
Assert.notNull(mm1, "First MethodMatcher must not be null");
|
Assert.notNull(mm1, "First MethodMatcher must not be null");
|
||||||
|
|
@ -168,6 +169,7 @@ public abstract class MethodMatchers {
|
||||||
private static class ClassFilterAwareUnionMethodMatcher extends UnionMethodMatcher {
|
private static class ClassFilterAwareUnionMethodMatcher extends UnionMethodMatcher {
|
||||||
|
|
||||||
private final ClassFilter cf1;
|
private final ClassFilter cf1;
|
||||||
|
|
||||||
private final ClassFilter cf2;
|
private final ClassFilter cf2;
|
||||||
|
|
||||||
public ClassFilterAwareUnionMethodMatcher(MethodMatcher mm1, ClassFilter cf1, MethodMatcher mm2, ClassFilter cf2) {
|
public ClassFilterAwareUnionMethodMatcher(MethodMatcher mm1, ClassFilter cf1, MethodMatcher mm2, ClassFilter cf2) {
|
||||||
|
|
@ -191,11 +193,17 @@ public abstract class MethodMatchers {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(other instanceof ClassFilterAwareUnionMethodMatcher)) {
|
if (!super.equals(other)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ClassFilterAwareUnionMethodMatcher that = (ClassFilterAwareUnionMethodMatcher) other;
|
ClassFilter otherCf1 = ClassFilter.TRUE;
|
||||||
return (this.cf1.equals(that.cf1) && this.cf2.equals(that.cf2) && super.equals(other));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,8 +214,9 @@ public abstract class MethodMatchers {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class IntersectionMethodMatcher implements IntroductionAwareMethodMatcher, Serializable {
|
private static class IntersectionMethodMatcher implements IntroductionAwareMethodMatcher, Serializable {
|
||||||
|
|
||||||
private MethodMatcher mm1;
|
private final MethodMatcher mm1;
|
||||||
private MethodMatcher mm2;
|
|
||||||
|
private final MethodMatcher mm2;
|
||||||
|
|
||||||
public IntersectionMethodMatcher(MethodMatcher mm1, MethodMatcher mm2) {
|
public IntersectionMethodMatcher(MethodMatcher mm1, MethodMatcher mm2) {
|
||||||
Assert.notNull(mm1, "First MethodMatcher must not be null");
|
Assert.notNull(mm1, "First MethodMatcher must not be null");
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ public final class MethodMatchersTests {
|
||||||
|
|
||||||
private final Method IOTHER_ABSQUATULATE;
|
private final Method IOTHER_ABSQUATULATE;
|
||||||
|
|
||||||
|
|
||||||
public MethodMatchersTests() throws Exception {
|
public MethodMatchersTests() throws Exception {
|
||||||
EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage", (Class[]) null);
|
EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage", (Class[]) null);
|
||||||
ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge", (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);
|
IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultMatchesAll() throws Exception {
|
public void testDefaultMatchesAll() throws Exception {
|
||||||
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
||||||
|
|
@ -99,23 +101,33 @@ public final class MethodMatchersTests {
|
||||||
assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class));
|
assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||||
assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class));
|
assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class));
|
||||||
assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, 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 {
|
public static class StartsWithMatcher extends StaticMethodMatcher {
|
||||||
private String prefix;
|
|
||||||
|
private final String prefix;
|
||||||
|
|
||||||
public StartsWithMatcher(String s) {
|
public StartsWithMatcher(String s) {
|
||||||
this.prefix = s;
|
this.prefix = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass) {
|
public boolean matches(Method m, Class<?> targetClass) {
|
||||||
return m.getName().startsWith(prefix);
|
return m.getName().startsWith(prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher {
|
private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -123,6 +135,7 @@ public final class MethodMatchersTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher {
|
private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue