Skip to content

Commit

Permalink
Fixed ClassFilterAwareUnionMethodMatcher equals implementation
Browse files Browse the repository at this point in the history
Issue: SPR-10604
  • Loading branch information
jhoeller committed Aug 2, 2013
1 parent 9e20a25 commit f329140
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -102,8 +102,9 @@ public static boolean matches(MethodMatcher mm, Method method, Class targetClass
@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");
Expand Down Expand Up @@ -172,6 +173,7 @@ public int hashCode() {
private static class ClassFilterAwareUnionMethodMatcher extends UnionMethodMatcher {

private final ClassFilter cf1;

private final ClassFilter cf2;

public ClassFilterAwareUnionMethodMatcher(MethodMatcher mm1, ClassFilter cf1, MethodMatcher mm2, ClassFilter cf2) {
Expand All @@ -195,11 +197,17 @@ public boolean equals(Object other) {
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));
}
}

Expand All @@ -210,8 +218,9 @@ public boolean equals(Object other) {
@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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ 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);
ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", new Class[] { int.class });
IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null);
}


@Test
public void testDefaultMatchesAll() throws Exception {
MethodMatcher defaultMm = MethodMatcher.TRUE;
Expand Down Expand Up @@ -99,30 +101,41 @@ public void testStaticMethodMatcherUnion() throws Exception {
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;
}
}

private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher {

@Override
public boolean matches(Method m, Class<?> targetClass, Object[] args) {
return false;
Expand Down

0 comments on commit f329140

Please sign in to comment.