diff --git a/spring-aop/src/main/java/org/springframework/aop/ClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/ClassFilter.java index 7409f77d91..fa8e2066c0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/ClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/ClassFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -23,6 +23,11 @@ package org.springframework.aop; *

Can be used as part of a {@link Pointcut} or for the entire * targeting of an {@link IntroductionAdvisor}. * + *

Concrete implementations of this interface typically should provide proper + * implementations of {@link Object#equals(Object)} and {@link Object#hashCode()} + * in order to allow the filter to be used in caching scenarios — for + * example, in proxies generated by CGLIB. + * * @author Rod Johnson * @see Pointcut * @see MethodMatcher diff --git a/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java index 9599922718..29127c73d4 100644 --- a/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -40,6 +40,11 @@ import java.lang.reflect.Method; * in an interceptor chain, will have run, so any state changes they have produced in * parameters or ThreadLocal state will be available at the time of evaluation. * + *

Concrete implementations of this interface typically should provide proper + * implementations of {@link Object#equals(Object)} and {@link Object#hashCode()} + * in order to allow the matcher to be used in caching scenarios — for + * example, in proxies generated by CGLIB. + * * @author Rod Johnson * @since 11.11.2003 * @see Pointcut diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java index 5d8d0919e5..32b691f441 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -735,6 +735,11 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence public int hashCode() { return this.adviceMethod.hashCode(); } + + @Override + public String toString() { + return getClass().getName() + ": " + this.adviceMethod; + } } } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java index e319bec4b8..cf1dcd929b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -22,6 +22,7 @@ import org.aspectj.weaver.tools.TypePatternMatcher; import org.springframework.aop.ClassFilter; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** @@ -29,6 +30,7 @@ import org.springframework.util.StringUtils; * * @author Rod Johnson * @author Juergen Hoeller + * @author Sam Brannen * @since 2.0 */ public class TypePatternClassFilter implements ClassFilter { @@ -113,4 +115,21 @@ public class TypePatternClassFilter implements ClassFilter { result = StringUtils.replace(result, " or ", " || "); return StringUtils.replace(result, " not ", " ! "); } + + @Override + public boolean equals(Object other) { + return (this == other || (other instanceof TypePatternClassFilter && + ObjectUtils.nullSafeEquals(this.typePattern, ((TypePatternClassFilter) other).typePattern))); + } + + @Override + public int hashCode() { + return ObjectUtils.nullSafeHashCode(this.typePattern); + } + + @Override + public String toString() { + return getClass().getName() + ": " + this.typePattern; + } + } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java index 0d9dbc05e8..6f624ca14b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -17,6 +17,7 @@ package org.springframework.aop.support; import java.io.Serializable; +import java.util.Arrays; import org.springframework.aop.ClassFilter; import org.springframework.lang.Nullable; @@ -29,6 +30,7 @@ import org.springframework.util.ObjectUtils; * @author Rod Johnson * @author Rob Harrop * @author Juergen Hoeller + * @author Sam Brannen * @since 11.11.2003 * @see MethodMatchers * @see Pointcuts @@ -90,9 +92,9 @@ public abstract class ClassFilters { @SuppressWarnings("serial") private static class UnionClassFilter implements ClassFilter, Serializable { - private ClassFilter[] filters; + private final ClassFilter[] filters; - public UnionClassFilter(ClassFilter[] filters) { + UnionClassFilter(ClassFilter[] filters) { this.filters = filters; } @@ -116,6 +118,12 @@ public abstract class ClassFilters { public int hashCode() { return ObjectUtils.nullSafeHashCode(this.filters); } + + @Override + public String toString() { + return getClass().getName() + ": " + Arrays.toString(this.filters); + } + } @@ -125,9 +133,9 @@ public abstract class ClassFilters { @SuppressWarnings("serial") private static class IntersectionClassFilter implements ClassFilter, Serializable { - private ClassFilter[] filters; + private final ClassFilter[] filters; - public IntersectionClassFilter(ClassFilter[] filters) { + IntersectionClassFilter(ClassFilter[] filters) { this.filters = filters; } @@ -151,6 +159,12 @@ public abstract class ClassFilters { public int hashCode() { return ObjectUtils.nullSafeHashCode(this.filters); } + + @Override + public String toString() { + return getClass().getName() + ": " + Arrays.toString(this.filters); + } + } } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java index caaebfa1f8..0246c1772a 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -25,12 +25,15 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** - * Convenient class for building up pointcuts. All methods return - * ComposablePointcut, so we can use a concise idiom like: + * Convenient class for building up pointcuts. * - * {@code - * Pointcut pc = new ComposablePointcut().union(classFilter).intersection(methodMatcher).intersection(pointcut); - * } + *

All methods return {@code ComposablePointcut}, so we can use concise idioms + * like in the following example. + * + *

Pointcut pc = new ComposablePointcut()
+ *                      .union(classFilter)
+ *                      .intersection(methodMatcher)
+ *                      .intersection(pointcut);
* * @author Rod Johnson * @author Juergen Hoeller @@ -200,7 +203,7 @@ public class ComposablePointcut implements Pointcut, Serializable { @Override public String toString() { - return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher; + return "ComposablePointcut: " + this.classFilter + ", " + this.methodMatcher; } } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java index 657acbc64a..56b9f034ee 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java @@ -35,14 +35,15 @@ import org.springframework.util.ObjectUtils; * @author Rod Johnson * @author Rob Harrop * @author Juergen Hoeller + * @author Sam Brannen */ @SuppressWarnings("serial") public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher, Serializable { - private Class clazz; + private final Class clazz; @Nullable - private String methodName; + private final String methodName; private final AtomicInteger evaluations = new AtomicInteger(0); @@ -143,4 +144,9 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher return code; } + @Override + public String toString() { + return getClass().getName() + ": class = " + this.clazz.getName() + "; methodName = " + methodName; + } + } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java index 259adc8fe2..6c6deed99c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -168,7 +168,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil @Override public String toString() { - return ClassUtils.getShortName(getClass()) + ": advice [" + this.advice + "]; interfaces " + + return getClass().getName() + ": advice [" + this.advice + "]; interfaces " + ClassUtils.classNamesToString(this.interfaces); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java index 598d1ca58b..23b4d9b78d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -35,6 +35,7 @@ import org.springframework.util.Assert; * @author Rod Johnson * @author Rob Harrop * @author Juergen Hoeller + * @author Sam Brannen * @since 11.11.2003 * @see ClassFilters * @see Pointcuts @@ -156,6 +157,11 @@ public abstract class MethodMatchers { public int hashCode() { return 37 * this.mm1.hashCode() + this.mm2.hashCode(); } + + @Override + public String toString() { + return getClass().getName() + ": " + this.mm1 + ", " + this.mm2; + } } @@ -230,6 +236,11 @@ public abstract class MethodMatchers { // Allow for matching with regular UnionMethodMatcher by providing same hash... return super.hashCode(); } + + @Override + public String toString() { + return getClass().getName() + ": " + this.cf1 + ", " + this.mm1 + ", " + this.cf2 + ", " + this.mm2; + } } @@ -312,6 +323,11 @@ public abstract class MethodMatchers { public int hashCode() { return 37 * this.mm1.hashCode() + this.mm2.hashCode(); } + + @Override + public String toString() { + return getClass().getName() + ": " + this.mm1 + ", " + this.mm2; + } } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java index fc11e8ab2d..8d51a287aa 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -26,8 +26,8 @@ import org.springframework.lang.Nullable; import org.springframework.util.PatternMatchUtils; /** - * Pointcut bean for simple method name matches, as alternative to regexp patterns. - * Does not handle overloaded methods: all methods with a given name will be eligible. + * Pointcut bean for simple method name matches, as an alternative to regexp patterns. + *

Does not handle overloaded methods: all methods with a given name will be eligible. * * @author Juergen Hoeller * @author Rod Johnson @@ -109,4 +109,9 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme return this.mappedNames.hashCode(); } + @Override + public String toString() { + return getClass().getName() + ": " + this.mappedNames; + } + } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java b/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java index 826594f030..39c7e8c0ed 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -26,7 +26,7 @@ import org.springframework.util.Assert; /** * Pointcut constants for matching getters and setters, * and static methods useful for manipulating and evaluating pointcuts. - * These methods are particularly useful for composing pointcuts + *

These methods are particularly useful for composing pointcuts * using the union and intersection methods. * * @author Rod Johnson @@ -106,6 +106,11 @@ public abstract class Pointcuts { private Object readResolve() { return INSTANCE; } + + @Override + public String toString() { + return "Pointcuts.SETTERS"; + } } @@ -126,6 +131,11 @@ public abstract class Pointcuts { private Object readResolve() { return INSTANCE; } + + @Override + public String toString() { + return "Pointcuts.GETTERS"; + } } } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java index ad559261e5..3809a30379 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -19,19 +19,22 @@ package org.springframework.aop.support; import java.io.Serializable; import org.springframework.aop.ClassFilter; +import org.springframework.util.Assert; /** * Simple ClassFilter implementation that passes classes (and optionally subclasses). * * @author Rod Johnson + * @author Sam Brannen */ @SuppressWarnings("serial") public class RootClassFilter implements ClassFilter, Serializable { - private Class clazz; + private final Class clazz; public RootClassFilter(Class clazz) { + Assert.notNull(clazz, "Class must not be null"); this.clazz = clazz; } @@ -41,4 +44,20 @@ public class RootClassFilter implements ClassFilter, Serializable { return this.clazz.isAssignableFrom(candidate); } + @Override + public boolean equals(Object other) { + return (this == other || (other instanceof RootClassFilter && + this.clazz.equals(((RootClassFilter) other).clazz))); + } + + @Override + public int hashCode() { + return this.clazz.hashCode(); + } + + @Override + public String toString() { + return getClass().getName() + ": " + this.clazz.getName(); + } + } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java index ddd9f89a0a..720c7b889b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -32,6 +32,7 @@ import org.springframework.util.Assert; * interface, if any, and the corresponding method on the target class). * * @author Juergen Hoeller + * @author Sam Brannen * @since 2.0 * @see AnnotationMatchingPointcut */ @@ -95,7 +96,7 @@ public class AnnotationMethodMatcher extends StaticMethodMatcher { return false; } AnnotationMethodMatcher otherMm = (AnnotationMethodMatcher) other; - return this.annotationType.equals(otherMm.annotationType); + return (this.annotationType.equals(otherMm.annotationType) && this.checkInherited == otherMm.checkInherited); } @Override diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/TypePatternClassFilterTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/TypePatternClassFilterTests.java index a1a321f602..8bcb178650 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/TypePatternClassFilterTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/TypePatternClassFilterTests.java @@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Rod Johnson * @author Rick Evans * @author Chris Beams + * @author Sam Brannen */ public class TypePatternClassFilterTests { @@ -93,4 +94,34 @@ public class TypePatternClassFilterTests { new TypePatternClassFilter().matches(String.class)); } + @Test + public void testEquals() { + TypePatternClassFilter filter1 = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); + TypePatternClassFilter filter2 = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); + TypePatternClassFilter filter3 = new TypePatternClassFilter("org.springframework.tests.*"); + + assertThat(filter1).isEqualTo(filter2); + assertThat(filter1).isNotEqualTo(filter3); + } + + @Test + public void testHashCode() { + TypePatternClassFilter filter1 = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); + TypePatternClassFilter filter2 = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); + TypePatternClassFilter filter3 = new TypePatternClassFilter("org.springframework.tests.*"); + + assertThat(filter1.hashCode()).isEqualTo(filter2.hashCode()); + assertThat(filter1.hashCode()).isNotEqualTo(filter3.hashCode()); + } + + @Test + public void testToString() { + TypePatternClassFilter filter1 = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); + TypePatternClassFilter filter2 = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); + + assertThat(filter1.toString()) + .isEqualTo("org.springframework.aop.aspectj.TypePatternClassFilter: org.springframework.tests.sample.beans.*"); + assertThat(filter1.toString()).isEqualTo(filter2.toString()); + } + } diff --git a/spring-aop/src/test/java/org/springframework/aop/support/ClassFiltersTests.java b/spring-aop/src/test/java/org/springframework/aop/support/ClassFiltersTests.java index 616fac6baa..00ea9213e5 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/ClassFiltersTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/ClassFiltersTests.java @@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rod Johnson * @author Chris Beams + * @author Sam Brannen */ class ClassFiltersTests { @@ -49,6 +50,8 @@ class ClassFiltersTests { ClassFilter union = ClassFilters.union(exceptionFilter, interfaceFilter); assertThat(union.matches(RuntimeException.class)).isTrue(); assertThat(union.matches(TestBean.class)).isTrue(); + assertThat(union.toString()) + .matches("^.+UnionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+TestBean\\]$"); } @Test @@ -59,6 +62,8 @@ class ClassFiltersTests { assertThat(intersection.matches(RuntimeException.class)).isFalse(); assertThat(intersection.matches(TestBean.class)).isFalse(); assertThat(intersection.matches(NestedRuntimeException.class)).isTrue(); + assertThat(intersection.toString()) + .matches("^.+IntersectionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+NestedRuntimeException\\]$"); } } diff --git a/spring-aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java index 7654324d19..72623dbf65 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/ControlFlowPointcutTests.java @@ -100,6 +100,14 @@ public class ControlFlowPointcutTests { assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode() == new ControlFlowPointcut(One.class).hashCode()).isFalse(); } + @Test + public void testToString() { + assertThat(new ControlFlowPointcut(One.class).toString()) + .isEqualTo(ControlFlowPointcut.class.getName() + ": class = " + One.class.getName() + "; methodName = null"); + assertThat(new ControlFlowPointcut(One.class, "getAge").toString()) + .isEqualTo(ControlFlowPointcut.class.getName() + ": class = " + One.class.getName() + "; methodName = getAge"); + } + public class One { int getAge(ITestBean proxied) { return proxied.getAge(); diff --git a/spring-aop/src/test/java/org/springframework/aop/support/RootClassFilterTests.java b/spring-aop/src/test/java/org/springframework/aop/support/RootClassFilterTests.java new file mode 100644 index 0000000000..0c132f327e --- /dev/null +++ b/spring-aop/src/test/java/org/springframework/aop/support/RootClassFilterTests.java @@ -0,0 +1,64 @@ +/* + * Copyright 2002-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.aop.support; + +import org.junit.jupiter.api.Test; + +import org.springframework.aop.ClassFilter; +import org.springframework.tests.sample.beans.ITestBean; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Unit tests for {@link RootClassFilter}. + * + * @author Sam Brannen + * @since 5.1.10 + */ +class RootClassFilterTests { + + private final ClassFilter filter1 = new RootClassFilter(Exception.class); + private final ClassFilter filter2 = new RootClassFilter(Exception.class); + private final ClassFilter filter3 = new RootClassFilter(ITestBean.class); + + + @Test + void matches() { + assertThat(filter1.matches(Exception.class)).isTrue(); + assertThat(filter1.matches(RuntimeException.class)).isTrue(); + assertThat(filter1.matches(Error.class)).isFalse(); + } + + @Test + void testEquals() { + assertThat(filter1).isEqualTo(filter2); + assertThat(filter1).isNotEqualTo(filter3); + } + + @Test + void testHashCode() { + assertThat(filter1.hashCode()).isEqualTo(filter2.hashCode()); + assertThat(filter1.hashCode()).isNotEqualTo(filter3.hashCode()); + } + + @Test + void testToString() { + assertThat(filter1.toString()).isEqualTo("org.springframework.aop.support.RootClassFilter: java.lang.Exception"); + assertThat(filter1.toString()).isEqualTo(filter2.toString()); + } + +} diff --git a/spring-aop/src/test/java/org/springframework/aop/support/AnnotationMatchingPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcutTests.java similarity index 94% rename from spring-aop/src/test/java/org/springframework/aop/support/AnnotationMatchingPointcutTests.java rename to spring-aop/src/test/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcutTests.java index 5f59bf7190..b7b23771b4 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/AnnotationMatchingPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcutTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.aop.support; +package org.springframework.aop.support.annotation; import org.junit.jupiter.api.Test; @@ -31,12 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * Unit tests for {@link AnnotationMatchingPointcut}. * * @author Sam Brannen - * @since 5.2 + * @since 5.1.10 */ class AnnotationMatchingPointcutTests { @Test - void classLevelPointCuts() { + void classLevelPointcuts() { Pointcut pointcut1 = new AnnotationMatchingPointcut(Qualifier.class, true); Pointcut pointcut2 = new AnnotationMatchingPointcut(Qualifier.class, true); Pointcut pointcut3 = new AnnotationMatchingPointcut(Qualifier.class); @@ -59,7 +59,7 @@ class AnnotationMatchingPointcutTests { } @Test - void methodLevelPointCuts() { + void methodLevelPointcuts() { Pointcut pointcut1 = new AnnotationMatchingPointcut(null, Qualifier.class, true); Pointcut pointcut2 = new AnnotationMatchingPointcut(null, Qualifier.class, true); Pointcut pointcut3 = new AnnotationMatchingPointcut(null, Qualifier.class); @@ -74,8 +74,7 @@ class AnnotationMatchingPointcutTests { assertThat(pointcut3.getMethodMatcher().getClass()).isEqualTo(AnnotationMethodMatcher.class); assertThat(pointcut1).isEqualTo(pointcut2); - // TODO Uncomment the following once AnnotationMethodMatcher.equals(Object) has been fixed. - // assertThat(pointcut1).isNotEqualTo(pointcut3); + assertThat(pointcut1).isNotEqualTo(pointcut3); assertThat(pointcut1.hashCode()).isEqualTo(pointcut2.hashCode()); // #1 and #3 have equivalent hash codes even though equals() returns false. assertThat(pointcut1.hashCode()).isEqualTo(pointcut3.hashCode()); @@ -83,7 +82,7 @@ class AnnotationMatchingPointcutTests { } @Test - void classLevelAndMethodLevelPointCuts() { + void classLevelAndMethodLevelPointcuts() { Pointcut pointcut1 = new AnnotationMatchingPointcut(Qualifier.class, Qualifier.class, true); Pointcut pointcut2 = new AnnotationMatchingPointcut(Qualifier.class, Qualifier.class, true); Pointcut pointcut3 = new AnnotationMatchingPointcut(Qualifier.class, Qualifier.class);