mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 03e695ad5f |
+1
-1
@@ -1,4 +1,4 @@
|
||||
version=5.3.18
|
||||
version=5.3.17
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
org.gradle.caching=true
|
||||
org.gradle.parallel=true
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -34,7 +34,7 @@ import org.springframework.util.ClassUtils;
|
||||
/**
|
||||
* AspectJ-based proxy factory, allowing for programmatic building
|
||||
* of proxies which include AspectJ aspects (code style as well
|
||||
* annotation style).
|
||||
* Java 5 annotation style).
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -60,8 +60,8 @@ public class AspectMetadata implements Serializable {
|
||||
private final Class<?> aspectClass;
|
||||
|
||||
/**
|
||||
* AspectJ reflection information.
|
||||
* <p>Re-resolved on deserialization since it isn't serializable itself.
|
||||
* AspectJ reflection information (AspectJ 5 / Java 5 specific).
|
||||
* Re-resolved on deserialization since it isn't serializable itself.
|
||||
*/
|
||||
private transient AjType<?> ajType;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -183,8 +183,8 @@ public abstract class AopUtils {
|
||||
* may be {@code DefaultFoo}. In this case, the method may be
|
||||
* {@code DefaultFoo.bar()}. This enables attributes on that method to be found.
|
||||
* <p><b>NOTE:</b> In contrast to {@link org.springframework.util.ClassUtils#getMostSpecificMethod},
|
||||
* this method resolves bridge methods in order to retrieve attributes from
|
||||
* the <i>original</i> method definition.
|
||||
* this method resolves Java 5 bridge methods in order to retrieve attributes
|
||||
* from the <i>original</i> method definition.
|
||||
* @param method the method to be invoked, which may come from an interface
|
||||
* @param targetClass the target class for the current invocation.
|
||||
* May be {@code null} or may not even implement the method.
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -24,7 +24,8 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple ClassFilter that looks for a specific annotation being present on a class.
|
||||
* Simple ClassFilter that looks for a specific Java 5 annotation
|
||||
* being present on a class.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,9 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple {@link Pointcut} that looks for a specific annotation being present on a
|
||||
* {@linkplain #forClassAnnotation class} or {@linkplain #forMethodAnnotation method}.
|
||||
* Simple Pointcut that looks for a specific Java 5 annotation
|
||||
* being present on a {@link #forClassAnnotation class} or
|
||||
* {@link #forMethodAnnotation method}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
|
||||
+4
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -27,10 +27,9 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple {@link org.springframework.aop.MethodMatcher MethodMatcher} that looks
|
||||
* for a specific annotation being present on a method (checking both the method
|
||||
* on the invoked interface, if any, and the corresponding method on the target
|
||||
* class).
|
||||
* Simple MethodMatcher that looks for a specific Java 5 annotation
|
||||
* being present on a method (checking both the method on the invoked
|
||||
* interface, if any, and the corresponding method on the target class).
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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.aspectj;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Additional parameter name discover tests that need Java 5.
|
||||
* Yes this will re-run the tests from the superclass, but that
|
||||
* doesn't matter in the grand scheme of things...
|
||||
*
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectJAdviceParameterNameDiscoverAnnotationTests extends AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void testAnnotationBinding() {
|
||||
assertParameterNames(getMethod("pjpAndAnAnnotation"),
|
||||
"execution(* *(..)) && @annotation(ann)",
|
||||
new String[] {"thisJoinPoint","ann"});
|
||||
}
|
||||
|
||||
|
||||
public void pjpAndAnAnnotation(ProceedingJoinPoint pjp, MyAnnotation ann) {}
|
||||
|
||||
@interface MyAnnotation {}
|
||||
|
||||
}
|
||||
+195
-259
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,11 +17,8 @@
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException;
|
||||
@@ -30,265 +27,200 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AspectJAdviceParameterNameDiscoverer}.
|
||||
* Unit tests for the {@link AspectJAdviceParameterNameDiscoverer} class.
|
||||
*
|
||||
* <p>See also {@link TigerAspectJAdviceParameterNameDiscovererTests} for tests relating to annotations.
|
||||
*
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class AspectJAdviceParameterNameDiscovererTests {
|
||||
public class AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
@Nested
|
||||
class StandardTests {
|
||||
|
||||
@Test
|
||||
void noArgs() {
|
||||
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void joinPointOnly() {
|
||||
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[] {"thisJoinPoint"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void joinPointStaticPartOnly() {
|
||||
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[] {"thisJoinPointStaticPart"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoJoinPoints() {
|
||||
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneThrowable() {
|
||||
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[] {"ex"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneJPAndOneThrowable() {
|
||||
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[] {"thisJoinPoint", "ex"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneJPAndTwoThrowables() {
|
||||
assertException(getMethod("jpAndTwoThrowables"), "foo()", null, "ex", AmbiguousBindingException.class,
|
||||
"Binding of throwing parameter 'ex' is ambiguous: could be bound to argument 1 or argument 2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void throwableNoCandidates() {
|
||||
assertException(getMethod("noArgs"), "foo()", null, "ex", IllegalStateException.class,
|
||||
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
||||
}
|
||||
|
||||
@Test
|
||||
void returning() {
|
||||
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[] {"obj"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void ambiguousReturning() {
|
||||
assertException(getMethod("twoObjects"), "foo()", "obj", null, AmbiguousBindingException.class,
|
||||
"Binding of returning parameter 'obj' is ambiguous, there are 2 candidates.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningNoCandidates() {
|
||||
assertException(getMethod("noArgs"), "foo()", "obj", null, IllegalStateException.class,
|
||||
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisBindingOneCandidate() {
|
||||
assertParameterNames(getMethod("oneObject"), "this(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisBindingWithAlternateTokenizations() {
|
||||
assertParameterNames(getMethod("oneObject"), "this( x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "this( x)", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "this (x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "this(x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisBindingTwoCandidates() {
|
||||
assertException(getMethod("oneObject"), "this(x) || this(y)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisBindingWithBadPointcutExpressions() {
|
||||
assertException(getMethod("oneObject"), "this(", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
assertException(getMethod("oneObject"), "this(x && foo()", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetBindingOneCandidate() {
|
||||
assertParameterNames(getMethod("oneObject"), "target(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetBindingWithAlternateTokenizations() {
|
||||
assertParameterNames(getMethod("oneObject"), "target( x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "target( x)", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "target (x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "target(x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetBindingTwoCandidates() {
|
||||
assertException(getMethod("oneObject"), "target(x) || target(y)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetBindingWithBadPointcutExpressions() {
|
||||
assertException(getMethod("oneObject"), "target(", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
assertException(getMethod("oneObject"), "target(x && foo()", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
}
|
||||
|
||||
@Test
|
||||
void argsBindingOneObject() {
|
||||
assertParameterNames(getMethod("oneObject"), "args(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void argsBindingOneObjectTwoCandidates() {
|
||||
assertException(getMethod("oneObject"), "args(x,y)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ambiguousArgsBinding() {
|
||||
assertException(getMethod("twoObjects"), "args(x,y)", AmbiguousBindingException.class,
|
||||
"Still 2 unbound args at this(),target(),args() binding stage, with no way to determine between them");
|
||||
}
|
||||
|
||||
@Test
|
||||
void argsOnePrimitive() {
|
||||
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[] {"count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void argsOnePrimitiveOneObject() {
|
||||
assertException(getMethod("oneObjectOnePrimitive"), "args(count,obj)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate variable names but only one candidate binding slot when matching primitive args");
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)",
|
||||
new String[] {"obj", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)",
|
||||
new String[] {"obj", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void throwingAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex",
|
||||
new String[] {"ex", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void allTogetherNow() {
|
||||
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex",
|
||||
new String[] {"thisJoinPoint", "ex", "x", "foo"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void referenceBinding() {
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)", new String[] {"foo"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void referenceBindingWithAlternateTokenizations() {
|
||||
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)", new String[] {"foo"});
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )", new String[] {"foo"});
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)", new String[] {"foo"});
|
||||
}
|
||||
@Test
|
||||
public void testNoArgs() {
|
||||
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests just the annotation binding part of {@link AspectJAdviceParameterNameDiscoverer}.
|
||||
*/
|
||||
@Nested
|
||||
class AnnotationTests {
|
||||
@Test
|
||||
public void testJoinPointOnly() {
|
||||
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[] {"thisJoinPoint"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void atThis() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@this(a)", new String[] {"a"});
|
||||
}
|
||||
@Test
|
||||
public void testJoinPointStaticPartOnly() {
|
||||
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[] {"thisJoinPointStaticPart"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void atTarget() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@target(a)", new String[] {"a"});
|
||||
}
|
||||
@Test
|
||||
public void testTwoJoinPoints() {
|
||||
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
}
|
||||
|
||||
@Test
|
||||
void atArgs() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@args(a)", new String[] {"a"});
|
||||
}
|
||||
@Test
|
||||
public void testOneThrowable() {
|
||||
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[] {"ex"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void atWithin() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@within(a)", new String[] {"a"});
|
||||
}
|
||||
@Test
|
||||
public void testOneJPAndOneThrowable() {
|
||||
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[] {"thisJoinPoint", "ex"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void atWithincode() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@withincode(a)", new String[] {"a"});
|
||||
}
|
||||
@Test
|
||||
public void testOneJPAndTwoThrowables() {
|
||||
assertException(getMethod("jpAndTwoThrowables"), "foo()", null, "ex", AmbiguousBindingException.class,
|
||||
"Binding of throwing parameter 'ex' is ambiguous: could be bound to argument 1 or argument 2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void atAnnotation() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@annotation(a)", new String[] {"a"});
|
||||
}
|
||||
@Test
|
||||
public void testThrowableNoCandidates() {
|
||||
assertException(getMethod("noArgs"), "foo()", null, "ex", IllegalStateException.class,
|
||||
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ambiguousAnnotationTwoVars() {
|
||||
assertException(getMethod("twoAnnotations"),"@annotation(a) && @this(x)", AmbiguousBindingException.class,
|
||||
"Found 2 potential annotation variable(s), and 2 potential argument slots");
|
||||
}
|
||||
@Test
|
||||
public void testReturning() {
|
||||
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[] {"obj"});
|
||||
}
|
||||
|
||||
@Test
|
||||
void ambiguousAnnotationOneVar() {
|
||||
assertException(getMethod("oneAnnotation"),"@annotation(a) && @this(x)",IllegalArgumentException.class,
|
||||
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
|
||||
}
|
||||
@Test
|
||||
public void testAmbiguousReturning() {
|
||||
assertException(getMethod("twoObjects"), "foo()", "obj", null, AmbiguousBindingException.class,
|
||||
"Binding of returning parameter 'obj' is ambiguous, there are 2 candidates.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void annotationMedley() {
|
||||
assertParameterNames(getMethod("annotationMedley"),"@annotation(a) && args(count) && this(foo)",
|
||||
null, "ex", new String[] {"ex", "foo", "count", "a"});
|
||||
}
|
||||
@Test
|
||||
public void testReturningNoCandidates() {
|
||||
assertException(getMethod("noArgs"), "foo()", "obj", null, IllegalStateException.class,
|
||||
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
||||
}
|
||||
|
||||
@Test
|
||||
void annotationBinding() {
|
||||
assertParameterNames(getMethod("pjpAndAnAnnotation"),
|
||||
"execution(* *(..)) && @annotation(ann)",
|
||||
new String[] {"thisJoinPoint","ann"});
|
||||
}
|
||||
@Test
|
||||
public void testThisBindingOneCandidate() {
|
||||
assertParameterNames(getMethod("oneObject"), "this(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisBindingWithAlternateTokenizations() {
|
||||
assertParameterNames(getMethod("oneObject"), "this( x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "this( x)", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "this (x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "this(x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisBindingTwoCandidates() {
|
||||
assertException(getMethod("oneObject"), "this(x) || this(y)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisBindingWithBadPointcutExpressions() {
|
||||
assertException(getMethod("oneObject"), "this(", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
assertException(getMethod("oneObject"), "this(x && foo()", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetBindingOneCandidate() {
|
||||
assertParameterNames(getMethod("oneObject"), "target(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetBindingWithAlternateTokenizations() {
|
||||
assertParameterNames(getMethod("oneObject"), "target( x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "target( x)", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "target (x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "target(x )", new String[] {"x"});
|
||||
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetBindingTwoCandidates() {
|
||||
assertException(getMethod("oneObject"), "target(x) || target(y)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetBindingWithBadPointcutExpressions() {
|
||||
assertException(getMethod("oneObject"), "target(", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
assertException(getMethod("oneObject"), "target(x && foo()", IllegalStateException.class,
|
||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgsBindingOneObject() {
|
||||
assertParameterNames(getMethod("oneObject"), "args(x)", new String[] {"x"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgsBindingOneObjectTwoCandidates() {
|
||||
assertException(getMethod("oneObject"), "args(x,y)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmbiguousArgsBinding() {
|
||||
assertException(getMethod("twoObjects"), "args(x,y)", AmbiguousBindingException.class,
|
||||
"Still 2 unbound args at this(),target(),args() binding stage, with no way to determine between them");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgsOnePrimitive() {
|
||||
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[] {"count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgsOnePrimitiveOneObject() {
|
||||
assertException(getMethod("oneObjectOnePrimitive"), "args(count,obj)", AmbiguousBindingException.class,
|
||||
"Found 2 candidate variable names but only one candidate binding slot when matching primitive args");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThisAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)",
|
||||
new String[] {"obj", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)",
|
||||
new String[] {"obj", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThrowingAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex",
|
||||
new String[] {"ex", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllTogetherNow() {
|
||||
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex",
|
||||
new String[] {"thisJoinPoint", "ex", "x", "foo"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceBinding() {
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)", new String[] {"foo"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceBindingWithAlternateTokenizations() {
|
||||
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)", new String[] {"foo"});
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )", new String[] {"foo"});
|
||||
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)", new String[] {"foo"});
|
||||
}
|
||||
|
||||
|
||||
private Method getMethod(String name) {
|
||||
protected Method getMethod(String name) {
|
||||
// Assumes no overloading of test methods...
|
||||
for (Method candidate : getClass().getMethods()) {
|
||||
Method[] candidates = getClass().getMethods();
|
||||
for (Method candidate : candidates) {
|
||||
if (candidate.getName().equals(name)) {
|
||||
return candidate;
|
||||
}
|
||||
@@ -296,11 +228,11 @@ class AspectJAdviceParameterNameDiscovererTests {
|
||||
throw new AssertionError("Bad test specification, no method '" + name + "' found in test class");
|
||||
}
|
||||
|
||||
private void assertParameterNames(Method method, String pointcut, String[] parameterNames) {
|
||||
protected void assertParameterNames(Method method, String pointcut, String[] parameterNames) {
|
||||
assertParameterNames(method, pointcut, null, null, parameterNames);
|
||||
}
|
||||
|
||||
private void assertParameterNames(
|
||||
protected void assertParameterNames(
|
||||
Method method, String pointcut, String returning, String throwing, String[] parameterNames) {
|
||||
|
||||
assertThat(parameterNames.length).as("bad test specification, must have same number of parameter names as method arguments").isEqualTo(method.getParameterCount());
|
||||
@@ -311,8 +243,8 @@ class AspectJAdviceParameterNameDiscovererTests {
|
||||
discoverer.setThrowingName(throwing);
|
||||
String[] discoveredNames = discoverer.getParameterNames(method);
|
||||
|
||||
String formattedExpectedNames = Arrays.toString(parameterNames);
|
||||
String formattedActualNames = Arrays.toString(discoveredNames);
|
||||
String formattedExpectedNames = format(parameterNames);
|
||||
String formattedActualNames = format(discoveredNames);
|
||||
|
||||
assertThat(discoveredNames.length).as("Expecting " + parameterNames.length + " parameter names in return set '" +
|
||||
formattedExpectedNames + "', but found " + discoveredNames.length +
|
||||
@@ -325,23 +257,37 @@ class AspectJAdviceParameterNameDiscovererTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertException(Method method, String pointcut, Class<? extends Throwable> exceptionType, String message) {
|
||||
protected void assertException(Method method, String pointcut, Class<? extends Throwable> exceptionType, String message) {
|
||||
assertException(method, pointcut, null, null, exceptionType, message);
|
||||
}
|
||||
|
||||
private void assertException(Method method, String pointcut, String returning,
|
||||
protected void assertException(Method method, String pointcut, String returning,
|
||||
String throwing, Class<? extends Throwable> exceptionType, String message) {
|
||||
|
||||
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
|
||||
discoverer.setRaiseExceptions(true);
|
||||
discoverer.setReturningName(returning);
|
||||
discoverer.setThrowingName(throwing);
|
||||
assertThatExceptionOfType(exceptionType)
|
||||
.isThrownBy(() -> discoverer.getParameterNames(method))
|
||||
assertThatExceptionOfType(exceptionType).isThrownBy(() ->
|
||||
discoverer.getParameterNames(method))
|
||||
.withMessageContaining(message);
|
||||
}
|
||||
|
||||
|
||||
private static String format(String[] names) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('(');
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
sb.append(names[i]);
|
||||
if ((i + 1) < names.length) {
|
||||
sb.append(',');
|
||||
}
|
||||
}
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
// Methods to discover parameter names for
|
||||
|
||||
public void noArgs() {
|
||||
@@ -383,14 +329,4 @@ class AspectJAdviceParameterNameDiscovererTests {
|
||||
public void theBigOne(JoinPoint jp, Throwable x, int y, Object foo) {
|
||||
}
|
||||
|
||||
public void oneAnnotation(MyAnnotation ann) {}
|
||||
|
||||
public void twoAnnotations(MyAnnotation ann, MyAnnotation anotherAnn) {}
|
||||
|
||||
public void annotationMedley(Throwable t, Object foo, int x, MyAnnotation ma) {}
|
||||
|
||||
public void pjpAndAnAnnotation(ProceedingJoinPoint pjp, MyAnnotation ann) {}
|
||||
|
||||
@interface MyAnnotation {}
|
||||
|
||||
}
|
||||
|
||||
+1
-286
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2020 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,9 +17,6 @@
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
@@ -28,8 +25,6 @@ import org.aspectj.weaver.tools.PointcutPrimitive;
|
||||
import org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.annotation.EmptySpringAnnotation;
|
||||
import test.annotation.transaction.Tx;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
@@ -61,19 +56,12 @@ public class AspectJExpressionPointcutTests {
|
||||
|
||||
private Method setSomeNumber;
|
||||
|
||||
private final Map<String, Method> methodsOnHasGeneric = new HashMap<>();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws NoSuchMethodException {
|
||||
getAge = TestBean.class.getMethod("getAge");
|
||||
setAge = TestBean.class.getMethod("setAge", int.class);
|
||||
setSomeNumber = TestBean.class.getMethod("setSomeNumber", Number.class);
|
||||
|
||||
// Assumes no overloading
|
||||
for (Method method : HasGeneric.class.getMethods()) {
|
||||
methodsOnHasGeneric.put(method.getName(), method);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -311,279 +299,6 @@ public class AspectJExpressionPointcutTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchGenericArgument() {
|
||||
String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
// TODO this will currently map, would be nice for optimization
|
||||
//assertTrue(ajexp.matches(HasGeneric.class));
|
||||
//assertFalse(ajexp.matches(TestBean.class));
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertThat(ajexp.matches(takesGenericList, HasGeneric.class)).isTrue();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isTrue();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchVarargs() throws Exception {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
class MyTemplate {
|
||||
public int queryForInt(String sql, Object... params) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
String expression = "execution(int *.*(String, Object...))";
|
||||
AspectJExpressionPointcut jdbcVarArgs = new AspectJExpressionPointcut();
|
||||
jdbcVarArgs.setExpression(expression);
|
||||
|
||||
assertThat(jdbcVarArgs.matches(
|
||||
MyTemplate.class.getMethod("queryForInt", String.class, Object[].class),
|
||||
MyTemplate.class)).isTrue();
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertThat(jdbcVarArgs.matches(takesGenericList, HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(getAge, TestBean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithAtWithin() throws Exception {
|
||||
String expression = "@within(test.annotation.transaction.Tx)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithoutBinding() throws Exception {
|
||||
String expression = "within(@test.annotation.transaction.Tx *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception {
|
||||
String expression = "within(@(test.annotation..*) *)";
|
||||
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse();
|
||||
assertThat(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isTrue();
|
||||
|
||||
expression = "within(@(test.annotation.transaction..*) *)";
|
||||
AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertThat(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception {
|
||||
String expression = "within(@(test.annotation.transaction.*) *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression) throws Exception {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isTrue();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
return ajexp;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithFQN() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnCglibProxyMethod() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(true);
|
||||
BeanA proxy = (BeanA) factory.getProxy();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnDynamicProxyMethod() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(false);
|
||||
IBeanA proxy = (IBeanA) factory.getProxy();
|
||||
assertThat(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithWildcard() throws Exception {
|
||||
String expression = "execution(@(test.annotation..*) * *(..))";
|
||||
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut();
|
||||
anySpringMethodAnnotation.setExpression(expression);
|
||||
|
||||
assertThat(anySpringMethodAnnotation.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception {
|
||||
String expression = "@args(*, test.annotation.EmptySpringAnnotation))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
|
||||
// True because it maybeMatches with potential argument subtypes
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception {
|
||||
String expression = "execution(* *(*, @(test..*) *))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isFalse();
|
||||
}
|
||||
|
||||
|
||||
public static class HasGeneric {
|
||||
|
||||
public void setFriends(List<TestBean> friends) {
|
||||
}
|
||||
public void setEnemies(List<TestBean> enemies) {
|
||||
}
|
||||
public void setPartners(List<?> partners) {
|
||||
}
|
||||
public void setPhoneNumbers(List<String> numbers) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ProcessesSpringAnnotatedParameters {
|
||||
|
||||
public void takesAnnotatedParameters(TestBean tb, SpringAnnotated sa) {
|
||||
}
|
||||
|
||||
public void takesNoAnnotatedParameters(TestBean tb, BeanA tb3) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Tx
|
||||
public static class HasTransactionalAnnotation {
|
||||
|
||||
public void foo() {
|
||||
}
|
||||
public Object bar(String foo) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EmptySpringAnnotation
|
||||
public static class SpringAnnotated {
|
||||
|
||||
public void foo() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface IBeanA {
|
||||
|
||||
@Tx
|
||||
int getAge();
|
||||
}
|
||||
|
||||
|
||||
static class BeanA implements IBeanA {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Tx
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Tx
|
||||
static class BeanB {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException;
|
||||
|
||||
/**
|
||||
* Tests just the annotation binding part of {@link AspectJAdviceParameterNameDiscoverer};
|
||||
* see supertype for remaining tests.
|
||||
*
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class TigerAspectJAdviceParameterNameDiscovererTests extends AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void testAtThis() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@this(a)", new String[] {"a"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtTarget() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@target(a)", new String[] {"a"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtArgs() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@args(a)", new String[] {"a"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtWithin() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@within(a)", new String[] {"a"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtWithincode() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@withincode(a)", new String[] {"a"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtAnnotation() {
|
||||
assertParameterNames(getMethod("oneAnnotation"),"@annotation(a)", new String[] {"a"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmbiguousAnnotationTwoVars() {
|
||||
assertException(getMethod("twoAnnotations"),"@annotation(a) && @this(x)", AmbiguousBindingException.class,
|
||||
"Found 2 potential annotation variable(s), and 2 potential argument slots");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmbiguousAnnotationOneVar() {
|
||||
assertException(getMethod("oneAnnotation"),"@annotation(a) && @this(x)",IllegalArgumentException.class,
|
||||
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationMedley() {
|
||||
assertParameterNames(getMethod("annotationMedley"),"@annotation(a) && args(count) && this(foo)",
|
||||
null, "ex", new String[] {"ex", "foo", "count", "a"});
|
||||
}
|
||||
|
||||
|
||||
public void oneAnnotation(MyAnnotation ann) {}
|
||||
|
||||
public void twoAnnotations(MyAnnotation ann, MyAnnotation anotherAnn) {}
|
||||
|
||||
public void annotationMedley(Throwable t, Object foo, int x, MyAnnotation ma) {}
|
||||
|
||||
@interface MyAnnotation {}
|
||||
|
||||
}
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* 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.aspectj;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.annotation.EmptySpringAnnotation;
|
||||
import test.annotation.transaction.Tx;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Java 5 specific {@link AspectJExpressionPointcutTests}.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class TigerAspectJExpressionPointcutTests {
|
||||
|
||||
private Method getAge;
|
||||
|
||||
private final Map<String, Method> methodsOnHasGeneric = new HashMap<>();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws NoSuchMethodException {
|
||||
getAge = TestBean.class.getMethod("getAge");
|
||||
// Assumes no overloading
|
||||
for (Method method : HasGeneric.class.getMethods()) {
|
||||
methodsOnHasGeneric.put(method.getName(), method);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchGenericArgument() {
|
||||
String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
// TODO this will currently map, would be nice for optimization
|
||||
//assertTrue(ajexp.matches(HasGeneric.class));
|
||||
//assertFalse(ajexp.matches(TestBean.class));
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertThat(ajexp.matches(takesGenericList, HasGeneric.class)).isTrue();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isTrue();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchVarargs() throws Exception {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
class MyTemplate {
|
||||
public int queryForInt(String sql, Object... params) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
String expression = "execution(int *.*(String, Object...))";
|
||||
AspectJExpressionPointcut jdbcVarArgs = new AspectJExpressionPointcut();
|
||||
jdbcVarArgs.setExpression(expression);
|
||||
|
||||
assertThat(jdbcVarArgs.matches(
|
||||
MyTemplate.class.getMethod("queryForInt", String.class, Object[].class),
|
||||
MyTemplate.class)).isTrue();
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertThat(jdbcVarArgs.matches(takesGenericList, HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(getAge, TestBean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithAtWithin() throws Exception {
|
||||
String expression = "@within(test.annotation.transaction.Tx)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithoutBinding() throws Exception {
|
||||
String expression = "within(@test.annotation.transaction.Tx *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception {
|
||||
String expression = "within(@(test.annotation..*) *)";
|
||||
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse();
|
||||
assertThat(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isTrue();
|
||||
|
||||
expression = "within(@(test.annotation.transaction..*) *)";
|
||||
AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertThat(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception {
|
||||
String expression = "within(@(test.annotation.transaction.*) *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression) throws Exception {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isTrue();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
return ajexp;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithFQN() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnCglibProxyMethod() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(true);
|
||||
BeanA proxy = (BeanA) factory.getProxy();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnDynamicProxyMethod() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(false);
|
||||
IBeanA proxy = (IBeanA) factory.getProxy();
|
||||
assertThat(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithWildcard() throws Exception {
|
||||
String expression = "execution(@(test.annotation..*) * *(..))";
|
||||
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut();
|
||||
anySpringMethodAnnotation.setExpression(expression);
|
||||
|
||||
assertThat(anySpringMethodAnnotation.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception {
|
||||
String expression = "@args(*, test.annotation.EmptySpringAnnotation))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
|
||||
// True because it maybeMatches with potential argument subtypes
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception {
|
||||
String expression = "execution(* *(*, @(test..*) *))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isFalse();
|
||||
}
|
||||
|
||||
|
||||
public static class HasGeneric {
|
||||
|
||||
public void setFriends(List<TestBean> friends) {
|
||||
}
|
||||
public void setEnemies(List<TestBean> enemies) {
|
||||
}
|
||||
public void setPartners(List<?> partners) {
|
||||
}
|
||||
public void setPhoneNumbers(List<String> numbers) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ProcessesSpringAnnotatedParameters {
|
||||
|
||||
public void takesAnnotatedParameters(TestBean tb, SpringAnnotated sa) {
|
||||
}
|
||||
|
||||
public void takesNoAnnotatedParameters(TestBean tb, BeanA tb3) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Tx
|
||||
public static class HasTransactionalAnnotation {
|
||||
|
||||
public void foo() {
|
||||
}
|
||||
public Object bar(String foo) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EmptySpringAnnotation
|
||||
public static class SpringAnnotated {
|
||||
|
||||
public void foo() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface IBeanA {
|
||||
|
||||
@Tx
|
||||
int getAge();
|
||||
}
|
||||
|
||||
|
||||
static class BeanA implements IBeanA {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Tx
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Tx
|
||||
static class BeanB {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+4
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2020 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,7 +22,6 @@ import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -287,13 +286,9 @@ public final class CachedIntrospectionResults {
|
||||
// This call is slow so we do it once.
|
||||
PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
if (Class.class == beanClass && (!"name".equals(pd.getName()) && !pd.getName().endsWith("Name"))) {
|
||||
// Only allow all name variants of Class properties
|
||||
continue;
|
||||
}
|
||||
if (pd.getPropertyType() != null && (ClassLoader.class.isAssignableFrom(pd.getPropertyType())
|
||||
|| ProtectionDomain.class.isAssignableFrom(pd.getPropertyType()))) {
|
||||
// Ignore ClassLoader and ProtectionDomain types - nobody needs to bind to those
|
||||
if (Class.class == beanClass &&
|
||||
("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) {
|
||||
// Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
|
||||
continue;
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
@@ -342,11 +337,6 @@ public final class CachedIntrospectionResults {
|
||||
// GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
|
||||
// against a declared read method, so we prefer read method descriptors here.
|
||||
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
|
||||
if (pd.getPropertyType() != null && (ClassLoader.class.isAssignableFrom(pd.getPropertyType())
|
||||
|| ProtectionDomain.class.isAssignableFrom(pd.getPropertyType()))) {
|
||||
// Ignore ClassLoader and ProtectionDomain types - nobody needs to bind to those
|
||||
continue;
|
||||
}
|
||||
this.propertyDescriptors.put(pd.getName(), pd);
|
||||
Method readMethod = pd.getReadMethod();
|
||||
if (readMethod != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Support package for beans-style handling of annotations.
|
||||
* Support package for beans-style handling of Java 5 annotations.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -44,7 +44,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation
|
||||
* that enforces required JavaBean properties to have been configured.
|
||||
* Required bean properties are detected through an annotation:
|
||||
* Required bean properties are detected through a Java 5 annotation:
|
||||
* by default, Spring's {@link Required} annotation.
|
||||
*
|
||||
* <p>The motivation for the existence of this BeanPostProcessor is to allow
|
||||
|
||||
+6
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -20,8 +20,8 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy interface for resolving a value by evaluating it as an expression,
|
||||
* if applicable.
|
||||
* Strategy interface for resolving a value through evaluating it
|
||||
* as an expression, if applicable.
|
||||
*
|
||||
* <p>A raw {@link org.springframework.beans.factory.BeanFactory} does not
|
||||
* contain a default implementation of this strategy. However,
|
||||
@@ -36,13 +36,12 @@ public interface BeanExpressionResolver {
|
||||
/**
|
||||
* Evaluate the given value as an expression, if applicable;
|
||||
* return the value as-is otherwise.
|
||||
* @param value the value to evaluate as an expression
|
||||
* @param beanExpressionContext the bean expression context to use when
|
||||
* evaluating the expression
|
||||
* @param value the value to check
|
||||
* @param evalContext the evaluation context
|
||||
* @return the resolved value (potentially the given value as-is)
|
||||
* @throws BeansException if evaluation failed
|
||||
*/
|
||||
@Nullable
|
||||
Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException;
|
||||
Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException;
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ import org.springframework.util.StringValueResolver;
|
||||
*
|
||||
* <p>The common annotations supported by this post-processor are available in
|
||||
* Java 6 (JDK 1.6) as well as in Java EE 5/6 (which provides a standalone jar for
|
||||
* its common annotations as well, allowing for use in any based application).
|
||||
* its common annotations as well, allowing for use in any Java 5 based application).
|
||||
*
|
||||
* <p>For default usage, resolving resource names as Spring bean names,
|
||||
* simply define the following in your application context:
|
||||
|
||||
+7
-7
@@ -138,7 +138,7 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException {
|
||||
public Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException {
|
||||
if (!StringUtils.hasLength(value)) {
|
||||
return value;
|
||||
}
|
||||
@@ -148,21 +148,21 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver {
|
||||
expr = this.expressionParser.parseExpression(value, this.beanExpressionParserContext);
|
||||
this.expressionCache.put(value, expr);
|
||||
}
|
||||
StandardEvaluationContext sec = this.evaluationCache.get(beanExpressionContext);
|
||||
StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
|
||||
if (sec == null) {
|
||||
sec = new StandardEvaluationContext(beanExpressionContext);
|
||||
sec = new StandardEvaluationContext(evalContext);
|
||||
sec.addPropertyAccessor(new BeanExpressionContextAccessor());
|
||||
sec.addPropertyAccessor(new BeanFactoryAccessor());
|
||||
sec.addPropertyAccessor(new MapAccessor());
|
||||
sec.addPropertyAccessor(new EnvironmentAccessor());
|
||||
sec.setBeanResolver(new BeanFactoryResolver(beanExpressionContext.getBeanFactory()));
|
||||
sec.setTypeLocator(new StandardTypeLocator(beanExpressionContext.getBeanFactory().getBeanClassLoader()));
|
||||
sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory()));
|
||||
sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
|
||||
sec.setTypeConverter(new StandardTypeConverter(() -> {
|
||||
ConversionService cs = beanExpressionContext.getBeanFactory().getConversionService();
|
||||
ConversionService cs = evalContext.getBeanFactory().getConversionService();
|
||||
return (cs != null ? cs : DefaultConversionService.getSharedInstance());
|
||||
}));
|
||||
customizeEvaluationContext(sec);
|
||||
this.evaluationCache.put(beanExpressionContext, sec);
|
||||
this.evaluationCache.put(evalContext, sec);
|
||||
}
|
||||
return expr.getValue(sec);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -46,7 +46,7 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link JmxAttributeSource} interface that
|
||||
* Implementation of the {@code JmxAttributeSource} interface that
|
||||
* reads annotations and exposes the corresponding attributes.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2012 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,7 +23,7 @@ import org.springframework.jmx.export.naming.MetadataNamingStrategy;
|
||||
|
||||
/**
|
||||
* Convenient subclass of Spring's standard {@link MBeanExporter},
|
||||
* activating annotation usage for JMX exposure of Spring beans:
|
||||
* activating Java 5 annotation usage for JMX exposure of Spring beans:
|
||||
* {@link ManagedResource}, {@link ManagedAttribute}, {@link ManagedOperation}, etc.
|
||||
*
|
||||
* <p>Sets a {@link MetadataNamingStrategy} and a {@link MetadataMBeanInfoAssembler}
|
||||
|
||||
+1
-2
@@ -27,8 +27,7 @@ import org.springframework.jmx.support.MetricType;
|
||||
/**
|
||||
* Method-level annotation that indicates to expose a given bean property as a
|
||||
* JMX attribute, with added descriptor properties to indicate that it is a metric.
|
||||
*
|
||||
* <p>Only valid when used on a JavaBean getter.
|
||||
* Only valid when used on a JavaBean getter.
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @since 3.0
|
||||
|
||||
+2
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -27,12 +27,10 @@ import java.lang.annotation.Target;
|
||||
/**
|
||||
* Type-level annotation that indicates a JMX notification emitted by a bean.
|
||||
*
|
||||
* <p>This annotation is a {@linkplain java.lang.annotation.Repeatable repeatable}
|
||||
* annotation.
|
||||
* <p>As of Spring Framework 4.2.4, this annotation is declared as repeatable.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @since 2.0
|
||||
* @see ManagedNotifications
|
||||
* @see org.springframework.jmx.export.metadata.ManagedNotification
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
|
||||
+3
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -24,12 +24,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Type-level annotation used as a container for one or more
|
||||
* {@code @ManagedNotification} declarations.
|
||||
*
|
||||
* <p>Note, however, that use of the {@code @ManagedNotifications} container
|
||||
* is completely optional since {@code @ManagedNotification} is a
|
||||
* {@linkplain java.lang.annotation.Repeatable repeatable} annotation.
|
||||
* Type-level annotation that indicates JMX notifications emitted by a bean,
|
||||
* containing multiple {@link ManagedNotification ManagedNotifications}.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @since 2.0
|
||||
|
||||
+4
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2015 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,11 +23,9 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Method-level annotation that indicates to expose a given method as a JMX operation,
|
||||
* corresponding to the {@link org.springframework.jmx.export.metadata.ManagedOperation}
|
||||
* attribute.
|
||||
*
|
||||
* <p>Only valid when used on a method that is not a JavaBean getter or setter.
|
||||
* Method-level annotation that indicates to expose a given method as a
|
||||
* JMX operation, corresponding to the {@code ManagedOperation} attribute.
|
||||
* Only valid when used on a method that is not a JavaBean getter or setter.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @since 1.2
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -24,15 +24,15 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Method-level annotation used to provide metadata about operation parameters, corresponding
|
||||
* to a {@link org.springframework.jmx.export.metadata.ManagedOperationParameter} attribute.
|
||||
* Method-level annotation used to provide metadata about operation parameters,
|
||||
* corresponding to a {@code ManagedOperationParameter} attribute.
|
||||
* Used as part of a {@link ManagedOperationParameters} annotation.
|
||||
*
|
||||
* <p>This annotation is a {@linkplain java.lang.annotation.Repeatable repeatable}
|
||||
* annotation.
|
||||
* <p>As of Spring Framework 4.2.4, this annotation is declared as repeatable.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @since 1.2
|
||||
* @see ManagedOperationParameters
|
||||
* @see ManagedOperationParameters#value
|
||||
* @see org.springframework.jmx.export.metadata.ManagedOperationParameter
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
|
||||
+3
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2015 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,12 +23,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Method-level annotation used as a container for one or more
|
||||
* {@code @ManagedOperationParameter} declarations.
|
||||
*
|
||||
* <p>Note, however, that use of the {@code @ManagedOperationParameters} container
|
||||
* is completely optional since {@code @ManagedOperationParameter} is a
|
||||
* {@linkplain java.lang.annotation.Repeatable repeatable} annotation.
|
||||
* Method-level annotation used to provide metadata about operation parameters,
|
||||
* corresponding to an array of {@code ManagedOperationParameter} attributes.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @since 1.2
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2015 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 java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Class-level annotation that indicates to register instances of a class with a JMX server,
|
||||
* corresponding to the {@link org.springframework.jmx.export.metadata.ManagedResource} attribute.
|
||||
* Class-level annotation that indicates to register instances of a class
|
||||
* with a JMX server, corresponding to the {@code ManagedResource} attribute.
|
||||
*
|
||||
* <p><b>Note:</b> This annotation is marked as inherited, allowing for generic
|
||||
* management-aware base classes. In such a scenario, it is recommended to
|
||||
|
||||
+3
-4
@@ -1,8 +1,7 @@
|
||||
/**
|
||||
* Annotations for MBean exposure.
|
||||
*
|
||||
* <p>Hooked into Spring's JMX export infrastructure via a special
|
||||
* {@link org.springframework.jmx.export.metadata.JmxAttributeSource} implementation.
|
||||
* Java 5 annotations for MBean exposure.
|
||||
* Hooked into Spring's JMX export infrastructure
|
||||
* via a special JmxAttributeSource implementation.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2017 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,7 +40,7 @@ import org.springframework.util.StringUtils;
|
||||
* <p>Uses the {@link JmxAttributeSource} strategy interface, so that
|
||||
* metadata can be read using any supported implementation. Out of the box,
|
||||
* {@link org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource}
|
||||
* introspects a well-defined set of annotations that come with Spring.
|
||||
* introspects a well-defined set of Java 5 annotations that come with Spring.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Annotation support for asynchronous method execution.
|
||||
* Java 5 annotation for asynchronous method execution.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
|
||||
+2
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -29,7 +29,6 @@ import org.springframework.lang.Nullable;
|
||||
* @see ScheduledTaskRegistrar#scheduleCronTask(CronTask)
|
||||
* @see ScheduledTaskRegistrar#scheduleFixedRateTask(FixedRateTask)
|
||||
* @see ScheduledTaskRegistrar#scheduleFixedDelayTask(FixedDelayTask)
|
||||
* @see ScheduledFuture
|
||||
*/
|
||||
public final class ScheduledTask {
|
||||
|
||||
@@ -55,24 +54,11 @@ public final class ScheduledTask {
|
||||
|
||||
/**
|
||||
* Trigger cancellation of this scheduled task.
|
||||
* <p>This variant will force interruption of the task if still running.
|
||||
* @see #cancel(boolean)
|
||||
*/
|
||||
public void cancel() {
|
||||
cancel(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger cancellation of this scheduled task.
|
||||
* @param mayInterruptIfRunning whether to force interruption of the task
|
||||
* if still running (specify {@code false} to allow the task to complete)
|
||||
* @since 5.3.18
|
||||
* @see ScheduledFuture#cancel(boolean)
|
||||
*/
|
||||
public void cancel(boolean mayInterruptIfRunning) {
|
||||
ScheduledFuture<?> future = this.future;
|
||||
if (future != null) {
|
||||
future.cancel(mayInterruptIfRunning);
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2017 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,7 @@ import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Subclass of {@link ModelMap} that implements the {@link Model} interface.
|
||||
* Java 5 specific like the {@code Model} interface itself.
|
||||
*
|
||||
* <p>This is an implementation class exposed to handler methods by Spring MVC, typically via
|
||||
* a declaration of the {@link org.springframework.ui.Model} interface. There is no need to
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,11 +22,9 @@ import java.util.Map;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Interface that defines a holder for model attributes.
|
||||
*
|
||||
* <p>Primarily designed for adding attributes to the model.
|
||||
*
|
||||
* <p>Allows for accessing the overall model as a {@code java.util.Map}.
|
||||
* Java-5-specific interface that defines a holder for model attributes.
|
||||
* Primarily designed for adding attributes to the model.
|
||||
* Allows for accessing the overall model as a {@code java.util.Map}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5.1
|
||||
|
||||
+11
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -38,9 +37,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AfterAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class AfterAdviceBindingTests {
|
||||
|
||||
private AdviceBindingCollaborator mockCollaborator;
|
||||
|
||||
@@ -50,8 +47,9 @@ class AfterAdviceBindingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
AdviceBindingTestAspect afterAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||
@@ -64,44 +62,39 @@ class AfterAdviceBindingTests {
|
||||
afterAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void oneIntArg() {
|
||||
public void testOneIntArg() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntArg(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneObjectArgBindingProxyWithThis() {
|
||||
public void testOneObjectArgBindingProxyWithThis() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneObjectArgBindingTarget() {
|
||||
public void testOneObjectArgBindingTarget() {
|
||||
testBeanProxy.getDoctor();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneIntAndOneObjectArgs() {
|
||||
public void testOneIntAndOneObjectArgs() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void needsJoinPoint() {
|
||||
public void testNeedsJoinPoint() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPoint("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
void needsJoinPointStaticPart() {
|
||||
public void testNeedsJoinPointStaticPart() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
|
||||
}
|
||||
|
||||
+17
-24
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -40,9 +39,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AfterReturningAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class AfterReturningAdviceBindingTests {
|
||||
|
||||
private AfterReturningAdviceBindingTestAspect afterAdviceAspect;
|
||||
|
||||
@@ -54,8 +51,9 @@ class AfterReturningAdviceBindingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
|
||||
@@ -69,63 +67,58 @@ class AfterReturningAdviceBindingTests {
|
||||
this.testBeanTarget = (TestBean) ((Advised)testBeanProxy).getTargetSource().getTarget();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void oneIntArg() {
|
||||
public void testOneIntArg() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntArg(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneObjectArg() {
|
||||
public void testOneObjectArg() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneIntAndOneObjectArgs() {
|
||||
public void testOneIntAndOneObjectArgs() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void needsJoinPoint() {
|
||||
public void testNeedsJoinPoint() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPoint("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
void needsJoinPointStaticPart() {
|
||||
public void testNeedsJoinPointStaticPart() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningString() {
|
||||
public void testReturningString() {
|
||||
testBeanProxy.setName("adrian");
|
||||
testBeanProxy.getName();
|
||||
verify(mockCollaborator).oneString("adrian");
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningObject() {
|
||||
public void testReturningObject() {
|
||||
testBeanProxy.returnsThis();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningBean() {
|
||||
public void testReturningBean() {
|
||||
testBeanProxy.returnsThis();
|
||||
verify(mockCollaborator).oneTestBeanArg(this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningBeanArray() {
|
||||
public void testReturningBeanArray() {
|
||||
this.testBeanTarget.setSpouse(new TestBean());
|
||||
ITestBean[] spouses = this.testBeanTarget.getSpouses();
|
||||
testBeanProxy.getSpouses();
|
||||
@@ -133,20 +126,20 @@ class AfterReturningAdviceBindingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void noInvokeWhenReturningParameterTypeDoesNotMatch() {
|
||||
public void testNoInvokeWhenReturningParameterTypeDoesNotMatch() {
|
||||
testBeanProxy.setSpouse(this.testBeanProxy);
|
||||
testBeanProxy.getSpouse();
|
||||
verifyNoInteractions(mockCollaborator);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningByType() {
|
||||
public void testReturningByType() {
|
||||
testBeanProxy.returnsThis();
|
||||
verify(mockCollaborator).objectMatchNoArgs();
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningPrimitive() {
|
||||
public void testReturningPrimitive() {
|
||||
testBeanProxy.setAge(20);
|
||||
testBeanProxy.haveBirthday();
|
||||
verify(mockCollaborator).oneInt(20);
|
||||
|
||||
+11
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -34,9 +33,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AfterThrowingAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class AfterThrowingAdviceBindingTests {
|
||||
|
||||
private ITestBean testBean;
|
||||
|
||||
@@ -46,8 +43,9 @@ class AfterThrowingAdviceBindingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
testBean = (ITestBean) ctx.getBean("testBean");
|
||||
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
|
||||
@@ -56,21 +54,16 @@ class AfterThrowingAdviceBindingTests {
|
||||
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void simpleAfterThrowing() throws Throwable {
|
||||
public void testSimpleAfterThrowing() throws Throwable {
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(new Throwable()));
|
||||
verify(mockCollaborator).noArgs();
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterThrowingWithBinding() throws Throwable {
|
||||
public void testAfterThrowingWithBinding() throws Throwable {
|
||||
Throwable t = new Throwable();
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(t));
|
||||
@@ -78,7 +71,7 @@ class AfterThrowingAdviceBindingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterThrowingWithNamedTypeRestriction() throws Throwable {
|
||||
public void testAfterThrowingWithNamedTypeRestriction() throws Throwable {
|
||||
Throwable t = new Throwable();
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(t));
|
||||
@@ -88,7 +81,7 @@ class AfterThrowingAdviceBindingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterThrowingWithRuntimeExceptionBinding() throws Throwable {
|
||||
public void testAfterThrowingWithRuntimeExceptionBinding() throws Throwable {
|
||||
RuntimeException ex = new RuntimeException();
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(ex));
|
||||
@@ -96,14 +89,14 @@ class AfterThrowingAdviceBindingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterThrowingWithTypeSpecified() throws Throwable {
|
||||
public void testAfterThrowingWithTypeSpecified() throws Throwable {
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(new Throwable()));
|
||||
verify(mockCollaborator).noArgsOnThrowableMatch();
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterThrowingWithRuntimeTypeSpecified() throws Throwable {
|
||||
public void testAfterThrowingWithRuntimeTypeSpecified() throws Throwable {
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
this.testBean.exceptional(new RuntimeException()));
|
||||
verify(mockCollaborator).noArgsOnRuntimeExceptionMatch();
|
||||
|
||||
+6
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,7 +19,6 @@ package org.springframework.aop.aspectj;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -34,9 +33,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AspectAndAdvicePrecedenceTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class AspectAndAdvicePrecedenceTests {
|
||||
|
||||
private PrecedenceTestAspect highPrecedenceAspect;
|
||||
|
||||
@@ -50,8 +47,9 @@ class AspectAndAdvicePrecedenceTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect");
|
||||
lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect");
|
||||
highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice");
|
||||
@@ -59,14 +57,9 @@ class AspectAndAdvicePrecedenceTests {
|
||||
testBean = (ITestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testAdviceOrder() {
|
||||
public void testAdviceOrder() {
|
||||
PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator();
|
||||
this.highPrecedenceAspect.setCollaborator(collaborator);
|
||||
this.lowPrecedenceAspect.setCollaborator(collaborator);
|
||||
|
||||
+19
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
@@ -30,22 +31,29 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AspectJExpressionPointcutAdvisorTests {
|
||||
public class AspectJExpressionPointcutAdvisorTests {
|
||||
|
||||
@Test
|
||||
void pointcutting() {
|
||||
private ITestBean testBean;
|
||||
|
||||
private CallCountingInterceptor interceptor;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (ITestBean) ctx.getBean("testBean");
|
||||
interceptor = (CallCountingInterceptor) ctx.getBean("interceptor");
|
||||
}
|
||||
|
||||
ITestBean testBean = ctx.getBean("testBean", ITestBean.class);
|
||||
CallCountingInterceptor interceptor = ctx.getBean("interceptor", CallCountingInterceptor.class);
|
||||
assertThat(interceptor.getCount()).as("Count").isEqualTo(0);
|
||||
|
||||
@Test
|
||||
public void testPointcutting() {
|
||||
assertThat(interceptor.getCount()).as("Count should be 0").isEqualTo(0);
|
||||
testBean.getSpouses();
|
||||
assertThat(interceptor.getCount()).as("Count").isEqualTo(1);
|
||||
assertThat(interceptor.getCount()).as("Count should be 1").isEqualTo(1);
|
||||
testBean.getSpouse();
|
||||
assertThat(interceptor.getCount()).as("Count").isEqualTo(1);
|
||||
|
||||
ctx.close();
|
||||
assertThat(interceptor.getCount()).as("Count should be 1").isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -18,8 +18,6 @@ package org.springframework.aop.aspectj;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
|
||||
@@ -37,9 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class BeanNamePointcutAtAspectTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class BeanNamePointcutAtAspectTests {
|
||||
|
||||
private ITestBean testBean1;
|
||||
|
||||
@@ -48,24 +44,19 @@ class BeanNamePointcutAtAspectTests {
|
||||
private CounterAspect counterAspect;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
testBean1 = (ITestBean) ctx.getBean("testBean1");
|
||||
testBean3 = (ITestBean) ctx.getBean("testBean3");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
void matchingBeanName() {
|
||||
public void testMatchingBeanName() {
|
||||
boolean condition = testBean1 instanceof Advised;
|
||||
assertThat(condition).as("Expected a proxy").isTrue();
|
||||
|
||||
@@ -76,7 +67,7 @@ class BeanNamePointcutAtAspectTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonMatchingBeanName() {
|
||||
public void testNonMatchingBeanName() {
|
||||
boolean condition = testBean3 instanceof Advised;
|
||||
assertThat(condition).as("Didn't expect a proxy").isFalse();
|
||||
|
||||
@@ -85,7 +76,7 @@ class BeanNamePointcutAtAspectTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void programmaticProxyCreation() {
|
||||
public void testProgrammaticProxyCreation() {
|
||||
ITestBean testBean = new TestBean();
|
||||
|
||||
AspectJProxyFactory factory = new AspectJProxyFactory();
|
||||
|
||||
+11
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -38,9 +37,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class BeforeAdviceBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class BeforeAdviceBindingTests {
|
||||
|
||||
private AdviceBindingCollaborator mockCollaborator;
|
||||
|
||||
@@ -50,8 +47,9 @@ class BeforeAdviceBindingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
|
||||
@@ -65,43 +63,38 @@ class BeforeAdviceBindingTests {
|
||||
beforeAdviceAspect.setCollaborator(mockCollaborator);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
void oneIntArg() {
|
||||
public void testOneIntArg() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntArg(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneObjectArgBoundToProxyUsingThis() {
|
||||
public void testOneObjectArgBoundToProxyUsingThis() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneIntAndOneObjectArgs() {
|
||||
public void testOneIntAndOneObjectArgs() {
|
||||
testBeanProxy.setAge(5);
|
||||
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanTarget);
|
||||
}
|
||||
|
||||
@Test
|
||||
void needsJoinPoint() {
|
||||
public void testNeedsJoinPoint() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPoint("getAge");
|
||||
}
|
||||
|
||||
@Test
|
||||
void needsJoinPointStaticPart() {
|
||||
public void testNeedsJoinPointStaticPart() {
|
||||
testBeanProxy.getAge();
|
||||
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+10
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,7 +19,6 @@ package org.springframework.aop.aspectj;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -32,9 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class DeclarationOrderIndependenceTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class DeclarationOrderIndependenceTests {
|
||||
|
||||
private TopsyTurvyAspect aspect;
|
||||
|
||||
@@ -42,32 +39,28 @@ class DeclarationOrderIndependenceTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
aspect = (TopsyTurvyAspect) ctx.getBean("topsyTurvyAspect");
|
||||
target = (TopsyTurvyTarget) ctx.getBean("topsyTurvyTarget");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testTargetIsSerializable() {
|
||||
public void testTargetIsSerializable() {
|
||||
boolean condition = this.target instanceof Serializable;
|
||||
assertThat(condition).as("target bean is serializable").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTargetIsBeanNameAware() {
|
||||
public void testTargetIsBeanNameAware() {
|
||||
boolean condition = this.target instanceof BeanNameAware;
|
||||
assertThat(condition).as("target bean is bean name aware").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeforeAdviceFiringOk() {
|
||||
public void testBeforeAdviceFiringOk() {
|
||||
AspectCollaborator collab = new AspectCollaborator();
|
||||
this.aspect.setCollaborator(collab);
|
||||
this.target.doSomething();
|
||||
@@ -75,7 +68,7 @@ class DeclarationOrderIndependenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAroundAdviceFiringOk() {
|
||||
public void testAroundAdviceFiringOk() {
|
||||
AspectCollaborator collab = new AspectCollaborator();
|
||||
this.aspect.setCollaborator(collab);
|
||||
this.target.getX();
|
||||
@@ -83,7 +76,7 @@ class DeclarationOrderIndependenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAfterReturningFiringOk() {
|
||||
public void testAfterReturningFiringOk() {
|
||||
AspectCollaborator collab = new AspectCollaborator();
|
||||
this.aspect.setCollaborator(collab);
|
||||
this.target.getX();
|
||||
|
||||
+12
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -28,35 +27,31 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class DeclareParentsDelegateRefTests {
|
||||
public class DeclareParentsDelegateRefTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
protected NoMethodsBean noMethodsBean;
|
||||
|
||||
private NoMethodsBean noMethodsBean;
|
||||
|
||||
private Counter counter;
|
||||
protected Counter counter;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
noMethodsBean = (NoMethodsBean) ctx.getBean("noMethodsBean");
|
||||
counter = (Counter) ctx.getBean("counter");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
counter.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void introductionWasMade() {
|
||||
assertThat(noMethodsBean).as("Introduction must have been made").isInstanceOf(ICounter.class);
|
||||
public void testIntroductionWasMade() {
|
||||
boolean condition = noMethodsBean instanceof ICounter;
|
||||
assertThat(condition).as("Introduction must have been made").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void introductionDelegation() {
|
||||
public void testIntroductionDelegation() {
|
||||
((ICounter)noMethodsBean).increment();
|
||||
assertThat(counter.getCount()).as("Delegate's counter should be updated").isEqualTo(1);
|
||||
}
|
||||
|
||||
+11
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import test.mixin.Lockable;
|
||||
@@ -32,9 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class DeclareParentsTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class DeclareParentsTests {
|
||||
|
||||
private ITestBean testBeanProxy;
|
||||
|
||||
@@ -42,23 +39,20 @@ class DeclareParentsTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBeanProxy = (ITestBean) ctx.getBean("testBean");
|
||||
introductionObject = ctx.getBean("introduction");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void introductionWasMade() {
|
||||
public void testIntroductionWasMade() {
|
||||
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
|
||||
assertThat(AopUtils.isAopProxy(introductionObject)).as("Introduction should not be proxied").isFalse();
|
||||
assertThat(testBeanProxy).as("Introduction must have been made").isInstanceOf(Lockable.class);
|
||||
boolean condition = testBeanProxy instanceof Lockable;
|
||||
assertThat(condition).as("Introduction must have been made").isTrue();
|
||||
}
|
||||
|
||||
// TODO if you change type pattern from org.springframework.beans..*
|
||||
@@ -66,7 +60,7 @@ class DeclareParentsTests {
|
||||
// Perhaps generated advisor bean definition could be made to depend
|
||||
// on the introduction, in which case this would not be a problem.
|
||||
@Test
|
||||
void lockingWorks() {
|
||||
public void testLockingWorks() {
|
||||
Lockable lockable = (Lockable) testBeanProxy;
|
||||
assertThat(lockable.locked()).isFalse();
|
||||
|
||||
@@ -75,7 +69,8 @@ class DeclareParentsTests {
|
||||
|
||||
testBeanProxy.setName("");
|
||||
lockable.lock();
|
||||
assertThatIllegalStateException().as("should be locked").isThrownBy(() -> testBeanProxy.setName(" "));
|
||||
assertThatIllegalStateException().as("should be locked").isThrownBy(() ->
|
||||
testBeanProxy.setName(" "));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -28,11 +28,10 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class ImplicitJPArgumentMatchingTests {
|
||||
public class ImplicitJPArgumentMatchingTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void testAspect() {
|
||||
public void testAspect() {
|
||||
// nothing to really test; it is enough if we don't get error while creating app context
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
}
|
||||
|
||||
+23
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for overloaded advice.
|
||||
@@ -29,26 +29,32 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class OverloadedAdviceTests {
|
||||
public class OverloadedAdviceTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void testExceptionOnConfigParsingWithMismatchedAdviceMethod() {
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()))
|
||||
.havingRootCause()
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.as("invalidAbsoluteTypeName should be detected by AJ").withMessageContaining("invalidAbsoluteTypeName");
|
||||
public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable cause = ex.getRootCause();
|
||||
boolean condition = cause instanceof IllegalArgumentException;
|
||||
assertThat(condition).as("Should be IllegalArgumentException").isTrue();
|
||||
assertThat(cause.getMessage().contains("invalidAbsoluteTypeName")).as("invalidAbsoluteTypeName should be detected by AJ").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() {
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ambiguous.xml", getClass()))
|
||||
.havingRootCause()
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.withMessageContaining("Cannot resolve method 'myBeforeAdvice' to a unique method");
|
||||
public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ambiguous.xml", getClass());
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable cause = ex.getRootCause();
|
||||
boolean condition = cause instanceof IllegalArgumentException;
|
||||
assertThat(condition).as("Should be IllegalArgumentException").isTrue();
|
||||
assertThat(cause.getMessage().contains("Cannot resolve method 'myBeforeAdvice' to a unique method")).as("Cannot resolve method 'myBeforeAdvice' to a unique method").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.aop.aspectj;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -34,9 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class ProceedTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class ProceedTests {
|
||||
|
||||
private SimpleBean testBean;
|
||||
|
||||
@@ -46,46 +43,43 @@ class ProceedTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (SimpleBean) ctx.getBean("testBean");
|
||||
firstTestAspect = (ProceedTestingAspect) ctx.getBean("firstTestAspect");
|
||||
secondTestAspect = (ProceedTestingAspect) ctx.getBean("secondTestAspect");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testSimpleProceedWithChangedArgs() {
|
||||
public void testSimpleProceedWithChangedArgs() {
|
||||
this.testBean.setName("abc");
|
||||
assertThat(this.testBean.getName()).as("Name changed in around advice").isEqualTo("ABC");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetArgsIsDefensive() {
|
||||
public void testGetArgsIsDefensive() {
|
||||
this.testBean.setAge(5);
|
||||
assertThat(this.testBean.getAge()).as("getArgs is defensive").isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProceedWithArgsInSameAspect() {
|
||||
public void testProceedWithArgsInSameAspect() {
|
||||
this.testBean.setMyFloat(1.0F);
|
||||
assertThat(this.testBean.getMyFloat() > 1.9F).as("value changed in around advice").isTrue();
|
||||
assertThat(this.firstTestAspect.getLastBeforeFloatValue() > 1.9F).as("changed value visible to next advice in chain").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProceedWithArgsAcrossAspects() {
|
||||
public void testProceedWithArgsAcrossAspects() {
|
||||
this.testBean.setSex("male");
|
||||
assertThat(this.testBean.getSex()).as("value changed in around advice").isEqualTo("MALE");
|
||||
assertThat(this.secondTestAspect.getLastBeforeStringValue()).as("changed value visible to next before advice in chain").isEqualTo("MALE");
|
||||
assertThat(this.secondTestAspect.getLastAroundStringValue()).as("changed value visible to next around advice in chain").isEqualTo("MALE");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -220,3 +214,4 @@ class ProceedTestingAspect implements Ordered {
|
||||
return this.lastBeforeFloatValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+34
-33
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -16,52 +16,53 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* See SPR-1682.
|
||||
*
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class SharedPointcutWithArgsMismatchTests {
|
||||
public class SharedPointcutWithArgsMismatchTests {
|
||||
|
||||
private static final List<String> messages = new ArrayList<>();
|
||||
private ToBeAdvised toBeAdvised;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
toBeAdvised = (ToBeAdvised) ctx.getBean("toBeAdvised");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void mismatchedArgBinding() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
ToBeAdvised toBeAdvised = ctx.getBean(ToBeAdvised.class);
|
||||
toBeAdvised.foo("test");
|
||||
assertThat(messages).containsExactly("doBefore(String): test", "foo(String): test");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
static class ToBeAdvised {
|
||||
|
||||
public void foo(String s) {
|
||||
messages.add("foo(String): " + s);
|
||||
}
|
||||
}
|
||||
|
||||
static class MyAspect {
|
||||
|
||||
public void doBefore(int x) {
|
||||
messages.add("doBefore(int): " + x);
|
||||
}
|
||||
|
||||
public void doBefore(String x) {
|
||||
messages.add("doBefore(String): " + x);
|
||||
}
|
||||
public void testMismatchedArgBinding() {
|
||||
this.toBeAdvised.foo("Hello");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ToBeAdvised {
|
||||
|
||||
public void foo(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MyAspect {
|
||||
|
||||
public void doBefore(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
|
||||
public void doBefore(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-24
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.aop.aspectj;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -31,9 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class SubtypeSensitiveMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class SubtypeSensitiveMatchingTests {
|
||||
|
||||
private NonSerializableFoo nonSerializableBean;
|
||||
|
||||
@@ -43,38 +40,31 @@ class SubtypeSensitiveMatchingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
nonSerializableBean = (NonSerializableFoo) ctx.getBean("testClassA");
|
||||
serializableBean = (SerializableFoo) ctx.getBean("testClassB");
|
||||
bar = (Bar) ctx.getBean("testClassC");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void beansAreProxiedOnStaticMatch() {
|
||||
assertThat(this.serializableBean)
|
||||
.as("bean with serializable type should be proxied")
|
||||
.isInstanceOf(Advised.class);
|
||||
public void testBeansAreProxiedOnStaticMatch() {
|
||||
boolean condition = this.serializableBean instanceof Advised;
|
||||
assertThat(condition).as("bean with serializable type should be proxied").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void beansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() {
|
||||
assertThat(this.nonSerializableBean)
|
||||
.as("bean with non-serializable type should not be proxied")
|
||||
.isNotInstanceOf(Advised.class);
|
||||
public void testBeansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() {
|
||||
boolean condition = this.nonSerializableBean instanceof Advised;
|
||||
assertThat(condition).as("bean with non-serializable type should not be proxied").isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void beansThatDoNotMatchBasedOnOtherTestAreProxied() {
|
||||
assertThat(this.bar)
|
||||
.as("bean with args check should be proxied")
|
||||
.isInstanceOf(Advised.class);
|
||||
public void testBeansThatDoNotMatchBasedOnOtherTestAreProxied() {
|
||||
boolean condition = this.bar instanceof Advised;
|
||||
assertThat(condition).as("bean with args check should be proxied").isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+32
-29
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.aop.aspectj;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -33,39 +32,37 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class TargetPointcutSelectionTests {
|
||||
public class TargetPointcutSelectionTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public TestInterface testImpl1;
|
||||
|
||||
private TestInterface testImpl1;
|
||||
public TestInterface testImpl2;
|
||||
|
||||
private TestInterface testImpl2;
|
||||
public TestAspect testAspectForTestImpl1;
|
||||
|
||||
private TestAspect testAspectForTestImpl1;
|
||||
public TestAspect testAspectForAbstractTestImpl;
|
||||
|
||||
private TestAspect testAspectForAbstractTestImpl;
|
||||
|
||||
private TestInterceptor testInterceptor;
|
||||
public TestInterceptor testInterceptor;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testImpl1 = (TestInterface) ctx.getBean("testImpl1");
|
||||
testImpl2 = (TestInterface) ctx.getBean("testImpl2");
|
||||
testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1");
|
||||
testAspectForAbstractTestImpl = (TestAspect) ctx.getBean("testAspectForAbstractTestImpl");
|
||||
testInterceptor = (TestInterceptor) ctx.getBean("testInterceptor");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
testAspectForTestImpl1.count = 0;
|
||||
testAspectForAbstractTestImpl.count = 0;
|
||||
testInterceptor.count = 0;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void targetSelectionForMatchedType() {
|
||||
public void targetSelectionForMatchedType() {
|
||||
testImpl1.interfaceMethod();
|
||||
assertThat(testAspectForTestImpl1.count).as("Should have been advised by POJO advice for impl").isEqualTo(1);
|
||||
assertThat(testAspectForAbstractTestImpl.count).as("Should have been advised by POJO advice for base type").isEqualTo(1);
|
||||
@@ -73,43 +70,49 @@ class TargetPointcutSelectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetNonSelectionForMismatchedType() {
|
||||
public void targetNonSelectionForMismatchedType() {
|
||||
testImpl2.interfaceMethod();
|
||||
assertThat(testAspectForTestImpl1.count).as("Shouldn't have been advised by POJO advice for impl").isZero();
|
||||
assertThat(testAspectForTestImpl1.count).as("Shouldn't have been advised by POJO advice for impl").isEqualTo(0);
|
||||
assertThat(testAspectForAbstractTestImpl.count).as("Should have been advised by POJO advice for base type").isEqualTo(1);
|
||||
assertThat(testInterceptor.count).as("Shouldn't have been advised by advisor").isZero();
|
||||
assertThat(testInterceptor.count).as("Shouldn't have been advised by advisor").isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
interface TestInterface {
|
||||
void interfaceMethod();
|
||||
public static interface TestInterface {
|
||||
|
||||
public void interfaceMethod();
|
||||
}
|
||||
|
||||
|
||||
// Reproducing bug requires that the class specified in target() pointcut doesn't
|
||||
// include the advised method's implementation (instead a base class should include it)
|
||||
static abstract class AbstractTestImpl implements TestInterface {
|
||||
public static abstract class AbstractTestImpl implements TestInterface {
|
||||
|
||||
@Override
|
||||
public void interfaceMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
static class TestImpl1 extends AbstractTestImpl {
|
||||
|
||||
public static class TestImpl1 extends AbstractTestImpl {
|
||||
}
|
||||
|
||||
static class TestImpl2 extends AbstractTestImpl {
|
||||
|
||||
public static class TestImpl2 extends AbstractTestImpl {
|
||||
}
|
||||
|
||||
static class TestAspect {
|
||||
|
||||
int count;
|
||||
public static class TestAspect {
|
||||
|
||||
void increment() {
|
||||
public int count;
|
||||
|
||||
public void increment() {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
static class TestInterceptor extends TestAspect implements MethodInterceptor {
|
||||
|
||||
public static class TestInterceptor extends TestAspect implements MethodInterceptor {
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
|
||||
+16
-25
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -21,8 +21,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -32,11 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
|
||||
private TestInterface testBean;
|
||||
|
||||
@@ -47,9 +42,10 @@ class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
private Counter counter;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (TestInterface) ctx.getBean("testBean");
|
||||
testAnnotatedClassBean = (TestInterface) ctx.getBean("testAnnotatedClassBean");
|
||||
testAnnotatedMethodBean = (TestInterface) ctx.getBean("testAnnotatedMethodBean");
|
||||
@@ -57,63 +53,58 @@ class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
counter.reset();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void thisAsClassDoesNotMatch() {
|
||||
public void thisAsClassDoesNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsClassCounter).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsInterfaceMatch() {
|
||||
public void thisAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetAsClassDoesMatch() {
|
||||
public void targetAsClassDoesMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.targetAsClassCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetAsInterfaceMatch() {
|
||||
public void targetAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.targetAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
public void thisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsClassAndTargetAsClassCounter).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
public void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsInterfaceAndTargetAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
public void thisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(counter.thisAsInterfaceAndTargetAsInterfaceCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void atTargetClassAnnotationMatch() {
|
||||
public void atTargetClassAnnotationMatch() {
|
||||
testAnnotatedClassBean.doIt();
|
||||
assertThat(counter.atTargetClassAnnotationCounter).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void atAnnotationMethodAnnotationMatch() {
|
||||
public void atAnnotationMethodAnnotationMatch() {
|
||||
testAnnotatedMethodBean.doIt();
|
||||
assertThat(counter.atAnnotationMethodAnnotationCounter).isEqualTo(1);
|
||||
}
|
||||
@@ -130,6 +121,7 @@ class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public static @interface TestAnnotation {
|
||||
|
||||
}
|
||||
|
||||
@TestAnnotation
|
||||
@@ -219,5 +211,4 @@ class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+27
-25
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -27,11 +26,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class ThisAndTargetSelectionOnlyPointcutsTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class ThisAndTargetSelectionOnlyPointcutsTests {
|
||||
|
||||
private TestInterface testBean;
|
||||
|
||||
@@ -41,64 +37,70 @@ class ThisAndTargetSelectionOnlyPointcutsTests {
|
||||
private Counter targetAsInterfaceCounter;
|
||||
private Counter thisAsClassAndTargetAsClassCounter;
|
||||
private Counter thisAsInterfaceAndTargetAsInterfaceCounter;
|
||||
private Counter thisAsInterfaceAndTargetAsClassCounter;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
testBean = (TestInterface) ctx.getBean("testBean");
|
||||
thisAsClassCounter = ctx.getBean("thisAsClassCounter", Counter.class);
|
||||
thisAsInterfaceCounter = ctx.getBean("thisAsInterfaceCounter", Counter.class);
|
||||
targetAsClassCounter = ctx.getBean("targetAsClassCounter", Counter.class);
|
||||
targetAsInterfaceCounter = ctx.getBean("targetAsInterfaceCounter", Counter.class);
|
||||
thisAsClassAndTargetAsClassCounter = ctx.getBean("thisAsClassAndTargetAsClassCounter", Counter.class);
|
||||
thisAsInterfaceAndTargetAsInterfaceCounter = ctx.getBean("thisAsInterfaceAndTargetAsInterfaceCounter", Counter.class);
|
||||
}
|
||||
thisAsClassCounter = (Counter) ctx.getBean("thisAsClassCounter");
|
||||
thisAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceCounter");
|
||||
targetAsClassCounter = (Counter) ctx.getBean("targetAsClassCounter");
|
||||
targetAsInterfaceCounter = (Counter) ctx.getBean("targetAsInterfaceCounter");
|
||||
thisAsClassAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsClassAndTargetAsClassCounter");
|
||||
thisAsInterfaceAndTargetAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsInterfaceCounter");
|
||||
thisAsInterfaceAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsClassCounter");
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
thisAsClassCounter.reset();
|
||||
thisAsInterfaceCounter.reset();
|
||||
targetAsClassCounter.reset();
|
||||
targetAsInterfaceCounter.reset();
|
||||
thisAsClassAndTargetAsClassCounter.reset();
|
||||
thisAsInterfaceAndTargetAsInterfaceCounter.reset();
|
||||
thisAsInterfaceAndTargetAsClassCounter.reset();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void thisAsClassDoesNotMatch() {
|
||||
public void testThisAsClassDoesNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsClassCounter.getCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsInterfaceMatch() {
|
||||
public void testThisAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetAsClassDoesMatch() {
|
||||
public void testTargetAsClassDoesMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(targetAsClassCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetAsInterfaceMatch() {
|
||||
public void testTargetAsInterfaceMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(targetAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsClassAndTargetAsClassCounter.getCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsInterfaceAndTargetAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void thisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
|
||||
testBean.doIt();
|
||||
assertThat(thisAsInterfaceAndTargetAsInterfaceCounter.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
+7
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -28,33 +27,27 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AnnotationBindingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class AnnotationBindingTests {
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void annotationBindingInAroundAdvice() {
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
assertThat(testBean.doThis()).isEqualTo("this value");
|
||||
assertThat(testBean.doThat()).isEqualTo("that value");
|
||||
}
|
||||
|
||||
@Test
|
||||
void noMatchingWithoutAnnotationPresent() {
|
||||
public void testNoMatchingWithoutAnnotationPresent() {
|
||||
assertThat(testBean.doTheOther()).isEqualTo("doTheOther");
|
||||
}
|
||||
|
||||
|
||||
+8
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -30,32 +29,27 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AnnotationPointcutTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class AnnotationPointcutTests {
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
this.testBean = ctx.getBean("testBean", AnnotatedTestBean.class);
|
||||
}
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void annotationBindingInAroundAdvice() {
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
assertThat(testBean.doThis()).isEqualTo("this value");
|
||||
}
|
||||
|
||||
@Test
|
||||
void noMatchingWithoutAnnotationPresent() {
|
||||
public void testNoMatchingWithoutAnnotationPresent() {
|
||||
assertThat(testBean.doTheOther()).isEqualTo("doTheOther");
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -30,21 +30,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class AspectImplementingInterfaceTests {
|
||||
public class AspectImplementingInterfaceTests {
|
||||
|
||||
@Test
|
||||
void proxyCreation() {
|
||||
public void testProxyCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
ITestBean testBean = ctx.getBean("testBean", ITestBean.class);
|
||||
AnInterface interfaceExtendingAspect = ctx.getBean("interfaceExtendingAspect", AnInterface.class);
|
||||
ITestBean testBean = (ITestBean) ctx.getBean("testBean");
|
||||
AnInterface interfaceExtendingAspect = (AnInterface) ctx.getBean("interfaceExtendingAspect");
|
||||
|
||||
assertThat(testBean).isInstanceOf(Advised.class);
|
||||
assertThat(interfaceExtendingAspect).isNotInstanceOf(Advised.class);
|
||||
ctx.close();
|
||||
boolean condition = testBean instanceof Advised;
|
||||
assertThat(condition).isTrue();
|
||||
boolean condition1 = interfaceExtendingAspect instanceof Advised;
|
||||
assertThat(condition1).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
|
||||
public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
|
||||
|
||||
@Test
|
||||
void testAdrian() {
|
||||
public void testAdrian() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
@@ -42,7 +42,6 @@ class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
|
||||
adrian.getAge();
|
||||
assertThat(adrian.getAge()).isEqualTo(68);
|
||||
assertThat(LazyTestBean.instantiations).isEqualTo(1);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @since 2.0
|
||||
*/
|
||||
class AtAspectJAfterThrowingTests {
|
||||
public class AtAspectJAfterThrowingTests {
|
||||
|
||||
@Test
|
||||
void accessThrowable() {
|
||||
public void testAccessThrowable() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
@@ -54,8 +54,6 @@ class AtAspectJAfterThrowingTests {
|
||||
|
||||
assertThat(aspect.handled).isEqualTo(1);
|
||||
assertThat(aspect.lastException).isSameAs(exceptionThrown);
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-25
@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class BenchmarkTests {
|
||||
public class BenchmarkTests {
|
||||
|
||||
private static final Class<?> CLASS = BenchmarkTests.class;
|
||||
|
||||
@@ -54,42 +54,42 @@ class BenchmarkTests {
|
||||
private static final String SPRING_AOP_CONTEXT = CLASS.getSimpleName() + "-springAop.xml";
|
||||
|
||||
@Test
|
||||
void repeatedAroundAdviceInvocationsWithAspectJ() {
|
||||
public void testRepeatedAroundAdviceInvocationsWithAspectJ() {
|
||||
testRepeatedAroundAdviceInvocations(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedAroundAdviceInvocationsWithSpringAop() {
|
||||
public void testRepeatedAroundAdviceInvocationsWithSpringAop() {
|
||||
testRepeatedAroundAdviceInvocations(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedBeforeAdviceInvocationsWithAspectJ() {
|
||||
public void testRepeatedBeforeAdviceInvocationsWithAspectJ() {
|
||||
testBeforeAdviceWithoutJoinPoint(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedBeforeAdviceInvocationsWithSpringAop() {
|
||||
public void testRepeatedBeforeAdviceInvocationsWithSpringAop() {
|
||||
testBeforeAdviceWithoutJoinPoint(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedAfterReturningAdviceInvocationsWithAspectJ() {
|
||||
public void testRepeatedAfterReturningAdviceInvocationsWithAspectJ() {
|
||||
testAfterReturningAdviceWithoutJoinPoint(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedAfterReturningAdviceInvocationsWithSpringAop() {
|
||||
public void testRepeatedAfterReturningAdviceInvocationsWithSpringAop() {
|
||||
testAfterReturningAdviceWithoutJoinPoint(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedMixWithAspectJ() {
|
||||
public void testRepeatedMixWithAspectJ() {
|
||||
testMix(ASPECTJ_CONTEXT, getCount(), "AspectJ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedMixWithSpringAop() {
|
||||
public void testRepeatedMixWithSpringAop() {
|
||||
testMix(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
@@ -101,11 +101,11 @@ class BenchmarkTests {
|
||||
}
|
||||
|
||||
private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated around advice invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
assertThat(adrian.getAge()).isEqualTo(68);
|
||||
@@ -115,17 +115,16 @@ class BenchmarkTests {
|
||||
}
|
||||
|
||||
sw.stop();
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
System.out.println(sw.prettyPrint());
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated before advice invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
Advised a = (Advised) adrian;
|
||||
@@ -137,17 +136,16 @@ class BenchmarkTests {
|
||||
}
|
||||
|
||||
sw.stop();
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
System.out.println(sw.prettyPrint());
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated after returning advice invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
Advised a = (Advised) adrian;
|
||||
@@ -160,17 +158,16 @@ class BenchmarkTests {
|
||||
}
|
||||
|
||||
sw.stop();
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
System.out.println(sw.prettyPrint());
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
private long testMix(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated mixed invocations with " + technology);
|
||||
ITestBean adrian = (ITestBean) ac.getBean("adrian");
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
|
||||
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
|
||||
Advised a = (Advised) adrian;
|
||||
@@ -189,8 +186,7 @@ class BenchmarkTests {
|
||||
}
|
||||
|
||||
sw.stop();
|
||||
// System.out.println(sw.prettyPrint());
|
||||
ac.close();
|
||||
System.out.println(sw.prettyPrint());
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,19 +32,20 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class SPR3064Tests {
|
||||
public class SPR3064Tests {
|
||||
|
||||
private Service service;
|
||||
|
||||
|
||||
@Test
|
||||
void testServiceIsAdvised() {
|
||||
public void testServiceIsAdvised() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
Service service = ctx.getBean(Service.class);
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(service::serveMe)
|
||||
.withMessage("advice invoked");
|
||||
|
||||
ctx.close();
|
||||
service = (Service) ctx.getBean("service");
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(
|
||||
this.service::serveMe)
|
||||
.withMessageContaining("advice invoked");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,7 +22,6 @@ import java.util.Collection;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -41,9 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AfterReturningGenericTypeMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class AfterReturningGenericTypeMatchingTests {
|
||||
|
||||
private GenericReturnTypeVariationClass testBean;
|
||||
|
||||
@@ -51,8 +48,9 @@ class AfterReturningGenericTypeMatchingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect.reset();
|
||||
@@ -60,14 +58,9 @@ class AfterReturningGenericTypeMatchingTests {
|
||||
testBean = (GenericReturnTypeVariationClass) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void returnTypeExactMatching() {
|
||||
public void testReturnTypeExactMatching() {
|
||||
testBean.getStrings();
|
||||
assertThat(counterAspect.getStringsInvocationsCount).isEqualTo(1);
|
||||
assertThat(counterAspect.getIntegersInvocationsCount).isEqualTo(0);
|
||||
@@ -80,7 +73,7 @@ class AfterReturningGenericTypeMatchingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnTypeRawMatching() {
|
||||
public void testReturnTypeRawMatching() {
|
||||
testBean.getStrings();
|
||||
assertThat(counterAspect.getRawsInvocationsCount).isEqualTo(1);
|
||||
|
||||
@@ -91,13 +84,13 @@ class AfterReturningGenericTypeMatchingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnTypeUpperBoundMatching() {
|
||||
public void testReturnTypeUpperBoundMatching() {
|
||||
testBean.getIntegers();
|
||||
assertThat(counterAspect.getNumbersInvocationsCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnTypeLowerBoundMatching() {
|
||||
public void testReturnTypeLowerBoundMatching() {
|
||||
testBean.getTestBeans();
|
||||
assertThat(counterAspect.getTestBeanInvocationsCount).isEqualTo(1);
|
||||
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,21 +25,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* <p>This class focuses on class proxying.
|
||||
*
|
||||
* <p>See {@link GenericBridgeMethodMatchingTests} for more details.
|
||||
* <p>See GenericBridgeMethodMatchingTests for more details.
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests {
|
||||
public class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests {
|
||||
|
||||
@Test
|
||||
void testGenericDerivedInterfaceMethodThroughClass() {
|
||||
public void testGenericDerivedInterfaceMethodThroughClass() {
|
||||
((DerivedStringParameterizedClass) testBean).genericDerivedInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericBaseInterfaceMethodThroughClass() {
|
||||
public void testGenericBaseInterfaceMethodThroughClass() {
|
||||
((DerivedStringParameterizedClass) testBean).genericBaseInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
|
||||
+10
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -18,8 +18,6 @@ package org.springframework.aop.aspectj.generic;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -41,40 +39,34 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class GenericBridgeMethodMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class GenericBridgeMethodMatchingTests {
|
||||
|
||||
protected DerivedInterface<String> testBean;
|
||||
|
||||
protected GenericCounterAspect counterAspect;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
counterAspect = ctx.getBean("counterAspect", GenericCounterAspect.class);
|
||||
counterAspect = (GenericCounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect.count = 0;
|
||||
|
||||
testBean = (DerivedInterface<String>) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenericDerivedInterfaceMethodThroughInterface() {
|
||||
public void testGenericDerivedInterfaceMethodThroughInterface() {
|
||||
testBean.genericDerivedInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericBaseInterfaceMethodThroughInterface() {
|
||||
public void testGenericBaseInterfaceMethodThroughInterface() {
|
||||
testBean.genericBaseInterfaceMethod("");
|
||||
assertThat(counterAspect.count).isEqualTo(1);
|
||||
}
|
||||
@@ -90,7 +82,7 @@ interface BaseInterface<T> {
|
||||
|
||||
interface DerivedInterface<T> extends BaseInterface<T> {
|
||||
|
||||
void genericDerivedInterfaceMethod(T t);
|
||||
public void genericDerivedInterfaceMethod(T t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-19
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -21,8 +21,6 @@ import java.util.Collection;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -36,44 +34,40 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class GenericParameterMatchingTests {
|
||||
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
public class GenericParameterMatchingTests {
|
||||
|
||||
private CounterAspect counterAspect;
|
||||
|
||||
private GenericInterface<String> testBean;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
void setup() {
|
||||
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
public void setup() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
testBean = (GenericInterface<String>) ctx.getBean("testBean");
|
||||
}
|
||||
counterAspect.reset();
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.ctx.close();
|
||||
testBean = (GenericInterface<String>) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenericInterfaceGenericArgExecution() {
|
||||
public void testGenericInterfaceGenericArgExecution() {
|
||||
testBean.save("");
|
||||
assertThat(counterAspect.genericInterfaceGenericArgExecutionCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericInterfaceGenericCollectionArgExecution() {
|
||||
public void testGenericInterfaceGenericCollectionArgExecution() {
|
||||
testBean.saveAll(null);
|
||||
assertThat(counterAspect.genericInterfaceGenericCollectionArgExecutionCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericInterfaceSubtypeGenericCollectionArgExecution() {
|
||||
public void testGenericInterfaceSubtypeGenericCollectionArgExecution() {
|
||||
testBean.saveAll(null);
|
||||
assertThat(counterAspect.genericInterfaceSubtypeGenericCollectionArgExecutionCount).isEqualTo(1);
|
||||
}
|
||||
@@ -81,9 +75,9 @@ class GenericParameterMatchingTests {
|
||||
|
||||
static interface GenericInterface<T> {
|
||||
|
||||
void save(T bean);
|
||||
public void save(T bean);
|
||||
|
||||
void saveAll(Collection<T> beans);
|
||||
public void saveAll(Collection<T> beans);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -31,7 +31,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
public class AopNamespaceHandlerAdviceTypeTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testParsingOfAdviceTypes() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -30,7 +30,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
public class AopNamespaceHandlerArgNamesTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testArgNamesOK() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -31,7 +31,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
public class AopNamespaceHandlerReturningTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testReturningOnReturningAdvice() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -31,7 +31,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
public class AopNamespaceHandlerThrowingTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void testThrowingOnThrowingAdvice() {
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
+7
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,34 +40,33 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Dmitriy Kopylenko
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class AdvisorAdapterRegistrationTests {
|
||||
public class AdvisorAdapterRegistrationTests {
|
||||
|
||||
@BeforeEach
|
||||
@AfterEach
|
||||
void resetGlobalAdvisorAdapterRegistry() {
|
||||
public void resetGlobalAdvisorAdapterRegistry() {
|
||||
GlobalAdvisorAdapterRegistry.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void advisorAdapterRegistrationManagerNotPresentInContext() {
|
||||
public void testAdvisorAdapterRegistrationManagerNotPresentInContext() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-without-bpp.xml", getClass());
|
||||
ITestBean tb = (ITestBean) ctx.getBean("testBean");
|
||||
// just invoke any method to see if advice fired
|
||||
assertThatExceptionOfType(UnknownAdviceTypeException.class).isThrownBy(tb::getName);
|
||||
assertThatExceptionOfType(UnknownAdviceTypeException.class).isThrownBy(
|
||||
tb::getName);
|
||||
assertThat(getAdviceImpl(tb).getInvocationCounter()).isZero();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void advisorAdapterRegistrationManagerPresentInContext() {
|
||||
public void testAdvisorAdapterRegistrationManagerPresentInContext() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-with-bpp.xml", getClass());
|
||||
ITestBean tb = (ITestBean) ctx.getBean("testBean");
|
||||
// just invoke any method to see if advice fired
|
||||
tb.getName();
|
||||
getAdviceImpl(tb).getInvocationCounter();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private SimpleBeforeAdviceImpl getAdviceImpl(ITestBean tb) {
|
||||
|
||||
+6
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,23 +32,18 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class BeanNameAutoProxyCreatorInitTests {
|
||||
public class BeanNameAutoProxyCreatorInitTests {
|
||||
|
||||
@Test
|
||||
void ignoreAdvisorThatIsCurrentlyInCreation() {
|
||||
public void testIgnoreAdvisorThatIsCurrentlyInCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
TestBean bean = ctx.getBean(TestBean.class);
|
||||
TestBean bean = (TestBean) ctx.getBean("bean");
|
||||
bean.setName("foo");
|
||||
assertThat(bean.getName()).isEqualTo("foo");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> bean.setName(null))
|
||||
.withMessage("Null argument at position 0");
|
||||
|
||||
ctx.close();
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
bean.setName(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,13 +26,14 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class BridgeMethodAutowiringTests {
|
||||
public class BridgeMethodAutowiringTests {
|
||||
|
||||
@Test
|
||||
void SPR8434() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(UserServiceImpl.class, Foo.class);
|
||||
public void SPR8434() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(UserServiceImpl.class, Foo.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(UserServiceImpl.class).object).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,31 +19,28 @@ package org.springframework.beans.factory.xml;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for combining the expression language and the p namespace.
|
||||
*
|
||||
* <p>Due to the required EL dependency, this test is in context module rather
|
||||
* than the beans module.
|
||||
* Tests for combining the expression language and the p namespace. Due to the required EL dependency, this test is in
|
||||
* context module rather than the beans module.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
class SimplePropertyNamespaceHandlerWithExpressionLanguageTests {
|
||||
public class SimplePropertyNamespaceHandlerWithExpressionLanguageTests {
|
||||
|
||||
@Test
|
||||
void combineWithExpressionLanguage() {
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
public void combineWithExpressionLanguage() {
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("simplePropertyNamespaceHandlerWithExpressionLanguageTests.xml",
|
||||
getClass());
|
||||
ITestBean foo = applicationContext.getBean("foo", ITestBean.class);
|
||||
ITestBean bar = applicationContext.getBean("bar", ITestBean.class);
|
||||
assertThat(foo.getName()).as("Invalid name").isEqualTo("Baz");
|
||||
assertThat(bar.getName()).as("Invalid name").isEqualTo("Baz");
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-19
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -53,10 +53,10 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class CacheReproTests {
|
||||
public class CacheReproTests {
|
||||
|
||||
@Test
|
||||
void spr11124MultipleAnnotations() {
|
||||
public void spr11124MultipleAnnotations() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11124Config.class);
|
||||
Spr11124Service bean = context.getBean(Spr11124Service.class);
|
||||
bean.single(2);
|
||||
@@ -67,7 +67,7 @@ class CacheReproTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr11249PrimitiveVarargs() {
|
||||
public void spr11249PrimitiveVarargs() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11249Config.class);
|
||||
Spr11249Service bean = context.getBean(Spr11249Service.class);
|
||||
Object result = bean.doSomething("op", 2, 3);
|
||||
@@ -76,7 +76,7 @@ class CacheReproTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr11592GetSimple() {
|
||||
public void spr11592GetSimple() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
|
||||
Spr11592Service bean = context.getBean(Spr11592Service.class);
|
||||
Cache cache = context.getBean("cache", Cache.class);
|
||||
@@ -93,7 +93,7 @@ class CacheReproTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr11592GetNeverCache() {
|
||||
public void spr11592GetNeverCache() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
|
||||
Spr11592Service bean = context.getBean(Spr11592Service.class);
|
||||
Cache cache = context.getBean("cache", Cache.class);
|
||||
@@ -110,7 +110,7 @@ class CacheReproTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr13081ConfigNoCacheNameIsRequired() {
|
||||
public void spr13081ConfigNoCacheNameIsRequired() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
|
||||
MyCacheResolver cacheResolver = context.getBean(MyCacheResolver.class);
|
||||
Spr13081Service bean = context.getBean(Spr13081Service.class);
|
||||
@@ -118,21 +118,20 @@ class CacheReproTests {
|
||||
assertThat(cacheResolver.getCache("foo").get("foo")).isNull();
|
||||
Object result = bean.getSimple("foo"); // cache name = id
|
||||
assertThat(cacheResolver.getCache("foo").get("foo").get()).isEqualTo(result);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr13081ConfigFailIfCacheResolverReturnsNullCacheName() {
|
||||
public void spr13081ConfigFailIfCacheResolverReturnsNullCacheName() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
|
||||
Spr13081Service bean = context.getBean(Spr13081Service.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> bean.getSimple(null))
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
bean.getSimple(null))
|
||||
.withMessageContaining(MyCacheResolver.class.getName());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr14230AdaptsToOptional() {
|
||||
public void spr14230AdaptsToOptional() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr14230Config.class);
|
||||
Spr14230Service bean = context.getBean(Spr14230Service.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
@@ -146,11 +145,10 @@ class CacheReproTests {
|
||||
TestBean tb2 = bean.findById("tb1").get();
|
||||
assertThat(tb2).isNotSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb2);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr14853AdaptsToOptionalWithSync() {
|
||||
public void spr14853AdaptsToOptionalWithSync() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr14853Config.class);
|
||||
Spr14853Service bean = context.getBean(Spr14853Service.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
@@ -164,11 +162,10 @@ class CacheReproTests {
|
||||
TestBean tb2 = bean.findById("tb1").get();
|
||||
assertThat(tb2).isNotSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb2);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr15271FindsOnInterfaceWithInterfaceProxy() {
|
||||
public void spr15271FindsOnInterfaceWithInterfaceProxy() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr15271ConfigA.class);
|
||||
Spr15271Interface bean = context.getBean(Spr15271Interface.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
@@ -177,11 +174,10 @@ class CacheReproTests {
|
||||
bean.insertItem(tb);
|
||||
assertThat(bean.findById("tb1").get()).isSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void spr15271FindsOnInterfaceWithCglibProxy() {
|
||||
public void spr15271FindsOnInterfaceWithCglibProxy() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr15271ConfigB.class);
|
||||
Spr15271Interface bean = context.getBean(Spr15271Interface.class);
|
||||
Cache cache = context.getBean(CacheManager.class).getCache("itemCache");
|
||||
@@ -190,7 +186,6 @@ class CacheReproTests {
|
||||
bean.insertItem(tb);
|
||||
assertThat(bean.findById("tb1").get()).isSameAs(tb);
|
||||
assertThat(cache.get("tb1").get()).isSameAs(tb);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+11
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
|
||||
/** hook into superclass suite of tests */
|
||||
@Override
|
||||
@@ -61,28 +61,26 @@ class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void keyStrategy() {
|
||||
public void testKeyStrategy() {
|
||||
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator", KeyGenerator.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cacheErrorHandler() {
|
||||
public void testCacheErrorHandler() {
|
||||
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void singleCacheManagerBean() {
|
||||
public void singleCacheManagerBean() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(SingleCacheManagerConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleCacheManagerBeans() {
|
||||
@SuppressWarnings("resource")
|
||||
public void multipleCacheManagerBeans() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(MultiCacheManagerConfig.class);
|
||||
try {
|
||||
@@ -95,16 +93,14 @@ class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleCacheManagerBeans_implementsCachingConfigurer() {
|
||||
public void multipleCacheManagerBeans_implementsCachingConfigurer() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(MultiCacheManagerConfigurer.class);
|
||||
ctx.refresh(); // does not throw an exception
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleCachingConfigurers() {
|
||||
@SuppressWarnings("resource")
|
||||
public void multipleCachingConfigurers() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(MultiCacheManagerConfigurer.class, EnableCachingConfig.class);
|
||||
try {
|
||||
@@ -116,8 +112,7 @@ class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void noCacheManagerBeans() {
|
||||
@SuppressWarnings("resource")
|
||||
public void noCacheManagerBeans() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EmptyConfig.class);
|
||||
try {
|
||||
@@ -130,7 +125,7 @@ class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyConfigSupport() {
|
||||
public void emptyConfigSupport() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
|
||||
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getCacheResolver()).isNotNull();
|
||||
@@ -140,7 +135,7 @@ class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bothSetOnlyResolverIsUsed() {
|
||||
public void bothSetOnlyResolverIsUsed() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class);
|
||||
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
|
||||
assertThat(ci.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
|
||||
|
||||
Vendored
+13
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2021 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,7 +19,6 @@ package org.springframework.cache.interceptor;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -48,9 +47,7 @@ import static org.mockito.Mockito.verify;
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class CacheErrorHandlerTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
public class CacheErrorHandlerTests {
|
||||
|
||||
private Cache cache;
|
||||
|
||||
@@ -61,21 +58,16 @@ class CacheErrorHandlerTests {
|
||||
private SimpleService simpleService;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.context = new AnnotationConfigApplicationContext(Config.class);
|
||||
public void setup() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
this.cache = context.getBean("mockCache", Cache.class);
|
||||
this.cacheInterceptor = context.getBean(CacheInterceptor.class);
|
||||
this.errorHandler = context.getBean(CacheErrorHandler.class);
|
||||
this.simpleService = context.getBean(SimpleService.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFail() {
|
||||
public void getFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||
willThrow(exception).given(this.cache).get(0L);
|
||||
|
||||
@@ -86,7 +78,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAndPutFail() {
|
||||
public void getAndPutFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||
willThrow(exception).given(this.cache).get(0L);
|
||||
willThrow(exception).given(this.cache).put(0L, 0L); // Update of the cache will fail as well
|
||||
@@ -101,7 +93,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFailProperException() {
|
||||
public void getFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||
willThrow(exception).given(this.cache).get(0L);
|
||||
|
||||
@@ -113,7 +105,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void putFail() {
|
||||
public void putFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||
willThrow(exception).given(this.cache).put(0L, 0L);
|
||||
|
||||
@@ -122,7 +114,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void putFailProperException() {
|
||||
public void putFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||
willThrow(exception).given(this.cache).put(0L, 0L);
|
||||
|
||||
@@ -134,7 +126,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void evictFail() {
|
||||
public void evictFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
willThrow(exception).given(this.cache).evict(0L);
|
||||
|
||||
@@ -143,7 +135,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void evictFailProperException() {
|
||||
public void evictFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
willThrow(exception).given(this.cache).evict(0L);
|
||||
|
||||
@@ -155,7 +147,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearFail() {
|
||||
public void clearFail() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||
willThrow(exception).given(this.cache).clear();
|
||||
|
||||
@@ -164,7 +156,7 @@ class CacheErrorHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearFailProperException() {
|
||||
public void clearFailProperException() {
|
||||
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on clear");
|
||||
willThrow(exception).given(this.cache).clear();
|
||||
|
||||
|
||||
+12
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -21,7 +21,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -32,7 +31,7 @@ import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -52,9 +51,7 @@ import static org.springframework.context.testfixture.cache.CacheTestUtils.asser
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
*/
|
||||
class CacheResolverCustomizationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
public class CacheResolverCustomizationTests {
|
||||
|
||||
private CacheManager cacheManager;
|
||||
|
||||
@@ -64,21 +61,16 @@ class CacheResolverCustomizationTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.context = new AnnotationConfigApplicationContext(Config.class);
|
||||
public void setup() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
this.cacheManager = context.getBean("cacheManager", CacheManager.class);
|
||||
this.anotherCacheManager = context.getBean("anotherCacheManager", CacheManager.class);
|
||||
this.simpleService = context.getBean(SimpleService.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void noCustomization() {
|
||||
public void noCustomization() {
|
||||
Cache cache = this.cacheManager.getCache("default");
|
||||
|
||||
Object key = new Object();
|
||||
@@ -89,7 +81,7 @@ class CacheResolverCustomizationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customCacheResolver() {
|
||||
public void customCacheResolver() {
|
||||
Cache cache = this.cacheManager.getCache("primary");
|
||||
|
||||
Object key = new Object();
|
||||
@@ -100,7 +92,7 @@ class CacheResolverCustomizationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customCacheManager() {
|
||||
public void customCacheManager() {
|
||||
Cache cache = this.anotherCacheManager.getCache("default");
|
||||
|
||||
Object key = new Object();
|
||||
@@ -111,7 +103,7 @@ class CacheResolverCustomizationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeResolution() {
|
||||
public void runtimeResolution() {
|
||||
Cache defaultCache = this.cacheManager.getCache("default");
|
||||
Cache primaryCache = this.cacheManager.getCache("primary");
|
||||
|
||||
@@ -129,7 +121,7 @@ class CacheResolverCustomizationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void namedResolution() {
|
||||
public void namedResolution() {
|
||||
Cache cache = this.cacheManager.getCache("secondary");
|
||||
|
||||
Object key = new Object();
|
||||
@@ -140,7 +132,7 @@ class CacheResolverCustomizationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void noCacheResolved() {
|
||||
public void noCacheResolved() {
|
||||
Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpleService.noCacheResolved(new Object()))
|
||||
@@ -148,7 +140,7 @@ class CacheResolverCustomizationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownCacheResolver() {
|
||||
public void unknownCacheResolver() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
|
||||
this.simpleService.unknownCacheResolver(new Object()))
|
||||
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("unknownCacheResolver"));
|
||||
|
||||
+40
-52
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -63,7 +63,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class ClassPathScanningCandidateComponentProviderTests {
|
||||
public class ClassPathScanningCandidateComponentProviderTests {
|
||||
|
||||
private static final String TEST_BASE_PACKAGE = "example.scannable";
|
||||
private static final String TEST_PROFILE_PACKAGE = "example.profilescan";
|
||||
@@ -75,7 +75,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
|
||||
|
||||
@Test
|
||||
void defaultsWithScan() {
|
||||
public void defaultsWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
@@ -83,7 +83,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultsWithIndex() {
|
||||
public void defaultsWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testDefault(provider);
|
||||
@@ -103,7 +103,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void antStylePackageWithScan() {
|
||||
public void antStylePackageWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
@@ -111,7 +111,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void antStylePackageWithIndex() {
|
||||
public void antStylePackageWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testAntStyle(provider);
|
||||
@@ -125,7 +125,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bogusPackageWithScan() {
|
||||
public void bogusPackageWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
@@ -134,7 +134,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bogusPackageWithIndex() {
|
||||
public void bogusPackageWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
|
||||
@@ -142,7 +142,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customFiltersFollowedByResetUseIndex() {
|
||||
public void customFiltersFollowedByResetUseIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
@@ -152,7 +152,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customAnnotationTypeIncludeFilterWithScan() {
|
||||
public void customAnnotationTypeIncludeFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
@@ -160,7 +160,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customAnnotationTypeIncludeFilterWithIndex() {
|
||||
public void customAnnotationTypeIncludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testCustomAnnotationTypeIncludeFilter(provider);
|
||||
@@ -172,7 +172,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customAssignableTypeIncludeFilterWithScan() {
|
||||
public void customAssignableTypeIncludeFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
@@ -180,7 +180,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customAssignableTypeIncludeFilterWithIndex() {
|
||||
public void customAssignableTypeIncludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testCustomAssignableTypeIncludeFilter(provider);
|
||||
@@ -198,7 +198,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customSupportedIncludeAndExcludedFilterWithScan() {
|
||||
public void customSupportedIncludeAndExcludedFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
@@ -206,7 +206,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customSupportedIncludeAndExcludeFilterWithIndex() {
|
||||
public void customSupportedIncludeAndExcludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
testCustomSupportedIncludeAndExcludeFilter(provider);
|
||||
@@ -225,7 +225,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customSupportIncludeFilterWithNonIndexedTypeUseScan() {
|
||||
public void customSupportIncludeFilterWithNonIndexedTypeUseScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
// This annotation type is not directly annotated with Indexed so we can use
|
||||
@@ -238,7 +238,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customNotSupportedIncludeFilterUseScan() {
|
||||
public void customNotSupportedIncludeFilterUseScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
|
||||
@@ -249,7 +249,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void excludeFilterWithScan() {
|
||||
public void excludeFilterWithScan() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(
|
||||
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
|
||||
@@ -258,7 +258,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void excludeFilterWithIndex() {
|
||||
public void excludeFilterWithIndex() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
|
||||
provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*Named.*")));
|
||||
@@ -276,14 +276,14 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withNoFilters() {
|
||||
public void testWithNoFilters() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
assertThat(candidates.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void withComponentAnnotationOnly() {
|
||||
public void testWithComponentAnnotationOnly() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
|
||||
@@ -300,7 +300,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withAspectAnnotationOnly() {
|
||||
public void testWithAspectAnnotationOnly() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
@@ -309,7 +309,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withInterfaceType() {
|
||||
public void testWithInterfaceType() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
@@ -318,7 +318,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withClassType() {
|
||||
public void testWithClassType() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
@@ -327,7 +327,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withMultipleMatchingFilters() {
|
||||
public void testWithMultipleMatchingFilters() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
|
||||
@@ -340,7 +340,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void excludeTakesPrecedence() {
|
||||
public void testExcludeTakesPrecedence() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
|
||||
@@ -354,14 +354,14 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withNullEnvironment() {
|
||||
public void testWithNullEnvironment() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
|
||||
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withInactiveProfile() {
|
||||
public void testWithInactiveProfile() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
ConfigurableEnvironment env = new StandardEnvironment();
|
||||
env.setActiveProfiles("other");
|
||||
@@ -371,7 +371,7 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withActiveProfile() {
|
||||
public void testWithActiveProfile() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
ConfigurableEnvironment env = new StandardEnvironment();
|
||||
env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
|
||||
@@ -381,67 +381,61 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_noProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_noProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_validProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_validProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
|
||||
ctx.register(ProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_validMetaAnnotatedProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_validMetaAnnotatedProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles(DevComponent.PROFILE_NAME);
|
||||
ctx.register(ProfileMetaAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_invalidProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_invalidProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles("other");
|
||||
ctx.register(ProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_invalidMetaAnnotatedProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_invalidMetaAnnotatedProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setActiveProfiles("other");
|
||||
ctx.register(ProfileMetaAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_defaultProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_defaultProfile() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.getEnvironment().setDefaultProfiles(TEST_DEFAULT_PROFILE_NAME);
|
||||
// no active profiles are set
|
||||
ctx.register(DefaultProfileAnnotatedComponent.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(DefaultProfileAnnotatedComponent.BEAN_NAME)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_defaultAndDevProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_defaultAndDevProfile() {
|
||||
Class<?> beanClass = DefaultAndDevProfileAnnotatedComponent.class;
|
||||
String beanName = DefaultAndDevProfileAnnotatedComponent.BEAN_NAME;
|
||||
{
|
||||
@@ -451,7 +445,6 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
@@ -460,7 +453,6 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
@@ -469,12 +461,11 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void integrationWithAnnotationConfigApplicationContext_metaProfile() {
|
||||
public void testIntegrationWithAnnotationConfigApplicationContext_metaProfile() {
|
||||
Class<?> beanClass = MetaProfileAnnotatedComponent.class;
|
||||
String beanName = MetaProfileAnnotatedComponent.BEAN_NAME;
|
||||
{
|
||||
@@ -484,7 +475,6 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
@@ -493,7 +483,6 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
{
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
@@ -502,12 +491,11 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
ctx.register(beanClass);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(beanName)).isFalse();
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void componentScanningFindsComponentsAnnotatedWithAnnotationsContainingNestedAnnotations() {
|
||||
public void componentScanningFindsComponentsAnnotatedWithAnnotationsContainingNestedAnnotations() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
Set<BeanDefinition> components = provider.findCandidateComponents(AnnotatedComponent.class.getPackage().getName());
|
||||
assertThat(components).hasSize(1);
|
||||
@@ -551,12 +539,12 @@ class ClassPathScanningCandidateComponentProviderTests {
|
||||
|
||||
@Profile(TEST_DEFAULT_PROFILE_NAME)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface DefaultProfile {
|
||||
public @interface DefaultProfile {
|
||||
}
|
||||
|
||||
@Profile("dev")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface DevProfile {
|
||||
public @interface DevProfile {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -31,59 +31,53 @@ import org.springframework.context.annotation.componentscan.simple.SimpleCompone
|
||||
public class ComponentScanAndImportAnnotationInteractionTests {
|
||||
|
||||
@Test
|
||||
void componentScanOverlapsWithImport() {
|
||||
public void componentScanOverlapsWithImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config1.class);
|
||||
ctx.register(Config2.class);
|
||||
ctx.refresh(); // no conflicts found trying to register SimpleComponent
|
||||
ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void componentScanOverlapsWithImportUsingAsm() {
|
||||
public void componentScanOverlapsWithImportUsingAsm() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config1", new RootBeanDefinition(Config1.class.getName()));
|
||||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(Config2.class.getName()));
|
||||
ctx.refresh(); // no conflicts found trying to register SimpleComponent
|
||||
ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void componentScanViaImport() {
|
||||
public void componentScanViaImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config3.class);
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void componentScanViaImportUsingAsm() {
|
||||
public void componentScanViaImportUsingAsm() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config", new RootBeanDefinition(Config3.class.getName()));
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void componentScanViaImportUsingScan() {
|
||||
public void componentScanViaImportUsingScan() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan("org.springframework.context.annotation.componentscan.importing");
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void circularImportViaComponentScan() {
|
||||
public void circularImportViaComponentScan() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("config", new RootBeanDefinition(ImportingConfig.class.getName()));
|
||||
ctx.refresh();
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,6 +25,7 @@ import org.springframework.context.annotation.componentscan.level3.Level3Compone
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests ensuring that configuration classes marked with @ComponentScan
|
||||
* may be processed recursively
|
||||
@@ -32,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
class ComponentScanAnnotationRecursionTests {
|
||||
public class ComponentScanAnnotationRecursionTests {
|
||||
|
||||
@Test
|
||||
void recursion() {
|
||||
public void recursion() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Level1Config.class);
|
||||
ctx.refresh();
|
||||
@@ -48,19 +49,14 @@ class ComponentScanAnnotationRecursionTests {
|
||||
// assert that enhancement is working
|
||||
assertThat(ctx.getBean("level1Bean")).isSameAs(ctx.getBean("level1Bean"));
|
||||
assertThat(ctx.getBean("level2Bean")).isSameAs(ctx.getBean("level2Bean"));
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void evenCircularScansAreSupported() {
|
||||
public void evenCircularScansAreSupported() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(LeftConfig.class); // left scans right, and right scans left
|
||||
ctx.refresh();
|
||||
ctx.getBean("leftConfig"); // but this is handled gracefully
|
||||
ctx.getBean("rightConfig"); // and beans from both packages are available
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -28,35 +29,33 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
class ComponentScanParserWithUserDefinedStrategiesTests {
|
||||
public class ComponentScanParserWithUserDefinedStrategiesTests {
|
||||
|
||||
@Test
|
||||
void customBeanNameGenerator() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
public void testCustomBeanNameGenerator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/customNameGeneratorTests.xml");
|
||||
assertThat(context.containsBean("testing.fooServiceImpl")).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customScopeMetadataResolver() {
|
||||
public void testCustomScopeMetadataResolver() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/customScopeResolverTests.xml");
|
||||
BeanDefinition bd = context.getBeanFactory().getBeanDefinition("fooServiceImpl");
|
||||
assertThat(bd.getScope()).isEqualTo("myCustomScope");
|
||||
assertThat(bd.isSingleton()).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidConstructorBeanNameGenerator() {
|
||||
public void testInvalidConstructorBeanNameGenerator() {
|
||||
assertThatExceptionOfType(BeansException.class).isThrownBy(() ->
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/invalidConstructorNameGeneratorTests.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidClassNameScopeMetadataResolver() {
|
||||
public void testInvalidClassNameScopeMetadataResolver() {
|
||||
assertThatExceptionOfType(BeansException.class).isThrownBy(() ->
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/annotation/invalidClassNameScopeResolverTests.xml"));
|
||||
|
||||
+17
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.testfixture.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests semantics of declaring {@link BeanFactoryPostProcessor}-returning @Bean
|
||||
* methods, specifically as regards static @Bean methods and the avoidance of
|
||||
@@ -32,34 +33,25 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
class ConfigurationClassAndBFPPTests {
|
||||
public class ConfigurationClassAndBFPPTests {
|
||||
|
||||
@Test
|
||||
void autowiringFailsWithBFPPAsInstanceMethod() {
|
||||
public void autowiringFailsWithBFPPAsInstanceMethod() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(TestBeanConfig.class, AutowiredConfigWithBFPPAsInstanceMethod.class);
|
||||
ctx.refresh();
|
||||
// instance method BFPP interferes with lifecycle -> autowiring fails!
|
||||
// WARN-level logging should have been issued about returning BFPP from non-static @Bean method
|
||||
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsInstanceMethod.class).autowiredTestBean).isNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void autowiringSucceedsWithBFPPAsStaticMethod() {
|
||||
public void autowiringSucceedsWithBFPPAsStaticMethod() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(TestBeanConfig.class, AutowiredConfigWithBFPPAsStaticMethod.class);
|
||||
ctx.refresh();
|
||||
// static method BFPP does not interfere with lifecycle -> autowiring succeeds
|
||||
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsStaticMethod.class).autowiredTestBean).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void staticBeanMethodsDoNotRespectScoping() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithStaticBeanMethod.class);
|
||||
assertThat(ConfigWithStaticBeanMethod.testBean()).isNotSameAs(ConfigWithStaticBeanMethod.testBean());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +63,7 @@ class ConfigurationClassAndBFPPTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class AutowiredConfigWithBFPPAsInstanceMethod {
|
||||
@Autowired TestBean autowiredTestBean;
|
||||
@@ -83,6 +76,7 @@ class ConfigurationClassAndBFPPTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class AutowiredConfigWithBFPPAsStaticMethod {
|
||||
@Autowired TestBean autowiredTestBean;
|
||||
@@ -95,6 +89,16 @@ class ConfigurationClassAndBFPPTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void staticBeanMethodsDoNotRespectScoping() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ConfigWithStaticBeanMethod.class);
|
||||
ctx.refresh();
|
||||
assertThat(ConfigWithStaticBeanMethod.testBean()).isNotSameAs(ConfigWithStaticBeanMethod.testBean());
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class ConfigWithStaticBeanMethod {
|
||||
@Bean
|
||||
|
||||
+22
-34
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -54,7 +54,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -389,7 +389,6 @@ class ConfigurationClassPostProcessorTests {
|
||||
.withMessageContaining("alias 'taskExecutor'")
|
||||
.withMessageContaining("name 'applicationTaskExecutor'")
|
||||
.withMessageContaining("bean definition 'taskExecutor'");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -999,129 +998,118 @@ class ConfigurationClassPostProcessorTests {
|
||||
|
||||
@Test
|
||||
void testPrototypeArgumentThroughBeanMethodCall() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithPrototype.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithPrototype.class);
|
||||
ctx.getBean(FooFactory.class).createFoo(new BarArgument());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSingletonArgumentThroughBeanMethodCall() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithSingleton.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithSingleton.class);
|
||||
ctx.getBean(FooFactory.class).createFoo(new BarArgument());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullArgumentThroughBeanMethodCall() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithNull.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithNull.class);
|
||||
ctx.getBean("aFoo");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInjectionPointMatchForNarrowTargetReturnType() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class);
|
||||
assertThat(ctx.getBean(FooImpl.class).bar).isSameAs(ctx.getBean(BarImpl.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVarargOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class);
|
||||
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.length).isEqualTo(1);
|
||||
assertThat(bean.testBeans[0]).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyVarargOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class);
|
||||
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.length).isEqualTo(0);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCollectionArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyCollectionArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.isEmpty()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMapArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.values().iterator().next()).isSameAs(ctx.getBean(Runnable.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyMapArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.isEmpty()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCollectionInjectionFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
|
||||
CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMapInjectionFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
|
||||
MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.size()).isEqualTo(1);
|
||||
assertThat(bean.testBeans.get("testBean")).isSameAs(ctx.getBean(Runnable.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeanLookupFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class);
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class);
|
||||
BeanLookupConfiguration bean = ctx.getBean(BeanLookupConfiguration.class);
|
||||
assertThat(bean.getTestBean()).isNotNull();
|
||||
assertThat(bean.getTestBean()).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNameClashBetweenConfigurationClassAndBean() {
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class)
|
||||
.isThrownBy(() -> new AnnotationConfigApplicationContext(MyTestBean.class).getBean("myTestBean", TestBean.class));
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MyTestBean.class);
|
||||
ctx.getBean("myTestBean", TestBean.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeanDefinitionRegistryPostProcessorConfig() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class);
|
||||
assertThat(ctx.getBean("myTestBean")).isInstanceOf(TestBean.class);
|
||||
ctx.close();
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class);
|
||||
boolean condition = ctx.getBean("myTestBean") instanceof TestBean;
|
||||
assertThat(condition).isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+9
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,70 +32,63 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
class ConfigurationWithFactoryBeanAndAutowiringTests {
|
||||
public class ConfigurationWithFactoryBeanAndAutowiringTests {
|
||||
|
||||
@Test
|
||||
void withConcreteFactoryBeanImplementationAsReturnType() {
|
||||
public void withConcreteFactoryBeanImplementationAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(ConcreteFactoryBeanImplementationConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withParameterizedFactoryBeanImplementationAsReturnType() {
|
||||
public void withParameterizedFactoryBeanImplementationAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(ParameterizedFactoryBeanImplementationConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
public void withParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(ParameterizedFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withNonPublicParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
public void withNonPublicParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(NonPublicParameterizedFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withRawFactoryBeanInterfaceAsReturnType() {
|
||||
public void withRawFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(RawFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withWildcardParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
public void withWildcardParameterizedFactoryBeanInterfaceAsReturnType() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(WildcardParameterizedFactoryBeanInterfaceConfig.class);
|
||||
ctx.refresh();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withFactoryBeanCallingBean() {
|
||||
public void withFactoryBeanCallingBean() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(FactoryBeanCallingConfig.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean("myString")).isEqualTo("true");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+8
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -33,13 +33,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
public class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, Bar.class);
|
||||
public void test() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, Bar.class);
|
||||
assertThat(ctx.getBean(Bar.class).foo).isNotNull();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +51,11 @@ class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
|
||||
static class Bar {
|
||||
|
||||
Foo foo;
|
||||
@@ -65,6 +66,7 @@ class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class FooFactoryBean implements FactoryBean<Foo> {
|
||||
|
||||
@Override
|
||||
|
||||
+15
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -38,33 +38,30 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class EnableAspectJAutoProxyTests {
|
||||
public class EnableAspectJAutoProxyTests {
|
||||
|
||||
@Test
|
||||
void withJdkProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithJdkProxy.class);
|
||||
public void withJdkProxy() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithJdkProxy.class);
|
||||
|
||||
aspectIsApplied(ctx);
|
||||
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class))).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withCglibProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithCglibProxy.class);
|
||||
public void withCglibProxy() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithCglibProxy.class);
|
||||
|
||||
aspectIsApplied(ctx);
|
||||
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooService.class))).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withExposedProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithExposedProxy.class);
|
||||
public void withExposedProxy() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithExposedProxy.class);
|
||||
|
||||
aspectIsApplied(ctx);
|
||||
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class))).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private void aspectIsApplied(ApplicationContext ctx) {
|
||||
@@ -85,7 +82,7 @@ class EnableAspectJAutoProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withAnnotationOnArgumentAndJdkProxy() {
|
||||
public void withAnnotationOnArgumentAndJdkProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||
ConfigWithJdkProxy.class, SampleService.class, LoggingAspect.class);
|
||||
|
||||
@@ -94,11 +91,10 @@ class EnableAspectJAutoProxyTests {
|
||||
sampleService.execute(new SampleInputBean());
|
||||
sampleService.execute((SampleDto) null);
|
||||
sampleService.execute((SampleInputBean) null);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withAnnotationOnArgumentAndCglibProxy() {
|
||||
public void withAnnotationOnArgumentAndCglibProxy() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
|
||||
ConfigWithCglibProxy.class, SampleService.class, LoggingAspect.class);
|
||||
|
||||
@@ -107,7 +103,6 @@ class EnableAspectJAutoProxyTests {
|
||||
sampleService.execute(new SampleInputBean());
|
||||
sampleService.execute((SampleDto) null);
|
||||
sampleService.execute((SampleInputBean) null);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +123,7 @@ class EnableAspectJAutoProxyTests {
|
||||
static class ConfigWithExposedProxy {
|
||||
|
||||
@Bean
|
||||
FooService fooServiceImpl(final ApplicationContext context) {
|
||||
public FooService fooServiceImpl(final ApplicationContext context) {
|
||||
return new FooServiceImpl() {
|
||||
@Override
|
||||
public String foo(int id) {
|
||||
@@ -145,20 +140,20 @@ class EnableAspectJAutoProxyTests {
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Loggable {
|
||||
public @interface Loggable {
|
||||
}
|
||||
|
||||
|
||||
@Loggable
|
||||
static class SampleDto {
|
||||
public static class SampleDto {
|
||||
}
|
||||
|
||||
|
||||
static class SampleInputBean {
|
||||
public static class SampleInputBean {
|
||||
}
|
||||
|
||||
|
||||
static class SampleService {
|
||||
public static class SampleService {
|
||||
|
||||
// Not matched method on {@link LoggingAspect}.
|
||||
public void execute(SampleInputBean inputBean) {
|
||||
|
||||
+6
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2021 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,28 +35,26 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
class EnableLoadTimeWeavingTests {
|
||||
public class EnableLoadTimeWeavingTests {
|
||||
|
||||
@Test
|
||||
void control() {
|
||||
public void control() {
|
||||
GenericXmlApplicationContext ctx =
|
||||
new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml");
|
||||
ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableLTW_withAjWeavingDisabled() {
|
||||
public void enableLTW_withAjWeavingDisabled() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EnableLTWConfig_withAjWeavingDisabled.class);
|
||||
ctx.refresh();
|
||||
LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
|
||||
verifyNoInteractions(loadTimeWeaver);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableLTW_withAjWeavingAutodetect() {
|
||||
public void enableLTW_withAjWeavingAutodetect() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EnableLTWConfig_withAjWeavingAutodetect.class);
|
||||
ctx.refresh();
|
||||
@@ -64,17 +62,15 @@ class EnableLoadTimeWeavingTests {
|
||||
// no expectations -> a class file transformer should NOT be added
|
||||
// because no META-INF/aop.xml is present on the classpath
|
||||
verifyNoInteractions(loadTimeWeaver);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableLTW_withAjWeavingEnabled() {
|
||||
public void enableLTW_withAjWeavingEnabled() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(EnableLTWConfig_withAjWeavingEnabled.class);
|
||||
ctx.refresh();
|
||||
LoadTimeWeaver loadTimeWeaver = ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
|
||||
verify(loadTimeWeaver).addTransformer(isA(ClassFileTransformer.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -39,18 +39,17 @@ import org.springframework.util.Assert;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests that an ImportAware @Configuration class gets injected with the
|
||||
* Tests that an ImportAware @Configuration classes gets injected with the
|
||||
* annotation metadata of the @Configuration class that imported it.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
class ImportAwareTests {
|
||||
public class ImportAwareTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void directlyAnnotatedWithImport() {
|
||||
public void directlyAnnotatedWithImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingConfig.class);
|
||||
ctx.refresh();
|
||||
@@ -66,8 +65,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void indirectlyAnnotatedWithImport() {
|
||||
public void indirectlyAnnotatedWithImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(IndirectlyImportingConfig.class);
|
||||
ctx.refresh();
|
||||
@@ -83,8 +81,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void directlyAnnotatedWithImportLite() {
|
||||
public void directlyAnnotatedWithImportLite() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingConfigLite.class);
|
||||
ctx.refresh();
|
||||
@@ -100,8 +97,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void importRegistrar() {
|
||||
public void importRegistrar() {
|
||||
ImportedRegistrar.called = false;
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingRegistrarConfig.class);
|
||||
@@ -111,8 +107,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void importRegistrarWithImport() {
|
||||
public void importRegistrarWithImport() {
|
||||
ImportedRegistrar.called = false;
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ImportingRegistrarConfigWithImport.class);
|
||||
@@ -124,8 +119,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void metadataFromImportsOneThenTwo() {
|
||||
public void metadataFromImportsOneThenTwo() {
|
||||
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
|
||||
ConfigurationOne.class, ConfigurationTwo.class)
|
||||
.getBean(MetadataHolder.class).importMetadata;
|
||||
@@ -133,8 +127,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void metadataFromImportsTwoThenOne() {
|
||||
public void metadataFromImportsTwoThenOne() {
|
||||
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
|
||||
ConfigurationTwo.class, ConfigurationOne.class)
|
||||
.getBean(MetadataHolder.class).importMetadata;
|
||||
@@ -142,8 +135,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void metadataFromImportsOneThenThree() {
|
||||
public void metadataFromImportsOneThenThree() {
|
||||
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
|
||||
ConfigurationOne.class, ConfigurationThree.class)
|
||||
.getBean(MetadataHolder.class).importMetadata;
|
||||
@@ -151,8 +143,7 @@ class ImportAwareTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void importAwareWithAnnotationAttributes() {
|
||||
public void importAwareWithAnnotationAttributes() {
|
||||
new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -37,16 +37,17 @@ import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ImportBeanDefinitionRegistrar}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Chris Beams
|
||||
*/
|
||||
class ImportBeanDefinitionRegistrarTests {
|
||||
public class ImportBeanDefinitionRegistrarTests {
|
||||
|
||||
@Test
|
||||
void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
|
||||
public void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
context.getBean(MessageSource.class);
|
||||
|
||||
@@ -54,7 +55,6 @@ class ImportBeanDefinitionRegistrarTests {
|
||||
assertThat(SampleRegistrar.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader());
|
||||
assertThat(SampleRegistrar.resourceLoader).isNotNull();
|
||||
assertThat(SampleRegistrar.environment).isEqualTo(context.getEnvironment());
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.0
|
||||
*/
|
||||
class LazyAutowiredAnnotationBeanPostProcessorTests {
|
||||
public class LazyAutowiredAnnotationBeanPostProcessorTests {
|
||||
|
||||
private void doTestLazyResourceInjection(Class<? extends TestBeanHolder> annotatedBeanClass) {
|
||||
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
|
||||
@@ -63,11 +63,10 @@ class LazyAutowiredAnnotationBeanPostProcessorTests {
|
||||
|
||||
assertThat(ObjectUtils.containsElement(bf.getDependenciesForBean("annotatedBean"), "testBean")).isTrue();
|
||||
assertThat(ObjectUtils.containsElement(bf.getDependentBeans("testBean"), "annotatedBean")).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithField() {
|
||||
public void testLazyResourceInjectionWithField() {
|
||||
doTestLazyResourceInjection(FieldResourceInjectionBean.class);
|
||||
|
||||
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
|
||||
@@ -87,46 +86,45 @@ class LazyAutowiredAnnotationBeanPostProcessorTests {
|
||||
TestBean tb = (TestBean) ac.getBean("testBean");
|
||||
tb.setName("tb");
|
||||
assertThat(bean.getTestBean().getName()).isSameAs("tb");
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithFieldAndCustomAnnotation() {
|
||||
public void testLazyResourceInjectionWithFieldAndCustomAnnotation() {
|
||||
doTestLazyResourceInjection(FieldResourceInjectionBeanWithCompositeAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithMethod() {
|
||||
public void testLazyResourceInjectionWithMethod() {
|
||||
doTestLazyResourceInjection(MethodResourceInjectionBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithMethodLevelLazy() {
|
||||
public void testLazyResourceInjectionWithMethodLevelLazy() {
|
||||
doTestLazyResourceInjection(MethodResourceInjectionBeanWithMethodLevelLazy.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithMethodAndCustomAnnotation() {
|
||||
public void testLazyResourceInjectionWithMethodAndCustomAnnotation() {
|
||||
doTestLazyResourceInjection(MethodResourceInjectionBeanWithCompositeAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithConstructor() {
|
||||
public void testLazyResourceInjectionWithConstructor() {
|
||||
doTestLazyResourceInjection(ConstructorResourceInjectionBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithConstructorLevelLazy() {
|
||||
public void testLazyResourceInjectionWithConstructorLevelLazy() {
|
||||
doTestLazyResourceInjection(ConstructorResourceInjectionBeanWithConstructorLevelLazy.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithConstructorAndCustomAnnotation() {
|
||||
public void testLazyResourceInjectionWithConstructorAndCustomAnnotation() {
|
||||
doTestLazyResourceInjection(ConstructorResourceInjectionBeanWithCompositeAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyResourceInjectionWithNonExistingTarget() {
|
||||
public void testLazyResourceInjectionWithNonExistingTarget() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
|
||||
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
|
||||
@@ -143,7 +141,7 @@ class LazyAutowiredAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyOptionalResourceInjectionWithNonExistingTarget() {
|
||||
public void testLazyOptionalResourceInjectionWithNonExistingTarget() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
|
||||
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
|
||||
|
||||
+10
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
class NestedConfigurationClassTests {
|
||||
public class NestedConfigurationClassTests {
|
||||
|
||||
@Test
|
||||
void oneLevelDeep() {
|
||||
public void oneLevelDeep() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0Config.L1Config.class);
|
||||
ctx.refresh();
|
||||
@@ -49,11 +49,10 @@ class NestedConfigurationClassTests {
|
||||
|
||||
// ensure that override order is correct
|
||||
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l1");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoLevelsDeep() {
|
||||
public void twoLevelsDeep() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0Config.class);
|
||||
ctx.refresh();
|
||||
@@ -72,11 +71,10 @@ class NestedConfigurationClassTests {
|
||||
|
||||
// ensure that override order is correct
|
||||
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l0");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoLevelsInLiteMode() {
|
||||
public void twoLevelsInLiteMode() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0ConfigLight.class);
|
||||
ctx.refresh();
|
||||
@@ -95,11 +93,10 @@ class NestedConfigurationClassTests {
|
||||
|
||||
// ensure that override order is correct
|
||||
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l0");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoLevelsDeepWithInheritance() {
|
||||
public void twoLevelsDeepWithInheritance() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(S1Config.class);
|
||||
ctx.refresh();
|
||||
@@ -124,11 +121,10 @@ class NestedConfigurationClassTests {
|
||||
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
|
||||
assertThat(pb1 != pb2).isTrue();
|
||||
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoLevelsDeepWithInheritanceThroughImport() {
|
||||
public void twoLevelsDeepWithInheritanceThroughImport() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(S1Importer.class);
|
||||
ctx.refresh();
|
||||
@@ -153,11 +149,10 @@ class NestedConfigurationClassTests {
|
||||
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
|
||||
assertThat(pb1 != pb2).isTrue();
|
||||
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoLevelsDeepWithInheritanceAndScopedProxy() {
|
||||
public void twoLevelsDeepWithInheritanceAndScopedProxy() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(S1ImporterWithProxy.class);
|
||||
ctx.refresh();
|
||||
@@ -182,11 +177,10 @@ class NestedConfigurationClassTests {
|
||||
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
|
||||
assertThat(pb1 != pb2).isTrue();
|
||||
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoLevelsWithNoBeanMethods() {
|
||||
public void twoLevelsWithNoBeanMethods() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0ConfigEmpty.class);
|
||||
ctx.refresh();
|
||||
@@ -204,11 +198,10 @@ class NestedConfigurationClassTests {
|
||||
Object l2i2 = ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.L2ConfigEmpty.class);
|
||||
assertThat(l2i1 == l2i2).isTrue();
|
||||
assertThat(l2i2.toString()).isNotEqualTo(l2i1.toString());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoLevelsOnNonAnnotatedBaseClass() {
|
||||
public void twoLevelsOnNonAnnotatedBaseClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(L0ConfigConcrete.class);
|
||||
ctx.refresh();
|
||||
@@ -226,7 +219,6 @@ class NestedConfigurationClassTests {
|
||||
Object l2i2 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.L2ConfigEmpty.class);
|
||||
assertThat(l2i1 == l2i2).isTrue();
|
||||
assertThat(l2i2.toString()).isNotEqualTo(l2i1.toString());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+22
-21
@@ -21,7 +21,7 @@ import javax.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -41,64 +41,65 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
class PrimitiveBeanLookupAndAutowiringTests {
|
||||
public class PrimitiveBeanLookupAndAutowiringTests {
|
||||
|
||||
@Test
|
||||
void primitiveLookupByName() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(ctx.getBean("b", boolean.class)).isTrue();
|
||||
assertThat(ctx.getBean("i", int.class)).isEqualTo(42);
|
||||
ctx.close();
|
||||
public void primitiveLookupByName() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
boolean b = ctx.getBean("b", boolean.class);
|
||||
assertThat(b).isTrue();
|
||||
int i = ctx.getBean("i", int.class);
|
||||
assertThat(i).isEqualTo(42);
|
||||
}
|
||||
|
||||
@Test
|
||||
void primitiveLookupByType() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(ctx.getBean(boolean.class)).isTrue();
|
||||
assertThat(ctx.getBean(int.class)).isEqualTo(42);
|
||||
ctx.close();
|
||||
public void primitiveLookupByType() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
boolean b = ctx.getBean(boolean.class);
|
||||
assertThat(b).isTrue();
|
||||
int i = ctx.getBean(int.class);
|
||||
assertThat(i).isEqualTo(42);
|
||||
}
|
||||
|
||||
@Test
|
||||
void primitiveAutowiredInjection() {
|
||||
ConfigurableApplicationContext ctx =
|
||||
public void primitiveAutowiredInjection() {
|
||||
ApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(Config.class, AutowiredComponent.class);
|
||||
assertThat(ctx.getBean(AutowiredComponent.class).b).isTrue();
|
||||
assertThat(ctx.getBean(AutowiredComponent.class).i).isEqualTo(42);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void primitiveResourceInjection() {
|
||||
ConfigurableApplicationContext ctx =
|
||||
public void primitiveResourceInjection() {
|
||||
ApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(Config.class, ResourceComponent.class);
|
||||
assertThat(ctx.getBean(ResourceComponent.class).b).isTrue();
|
||||
assertThat(ctx.getBean(ResourceComponent.class).i).isEqualTo(42);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
boolean b() {
|
||||
public boolean b() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Bean
|
||||
int i() {
|
||||
public int i() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class AutowiredComponent {
|
||||
@Autowired boolean b;
|
||||
@Autowired int i;
|
||||
}
|
||||
|
||||
|
||||
static class ResourceComponent {
|
||||
@Resource boolean b;
|
||||
@Autowired int i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-20
@@ -73,7 +73,6 @@ class PropertySourceAnnotationTests {
|
||||
while (iterator.hasNext());
|
||||
|
||||
assertThat(name).isEqualTo("p1");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +80,6 @@ class PropertySourceAnnotationTests {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithImplicitName.class);
|
||||
assertThat(ctx.getEnvironment().getPropertySources().contains("class path resource [org/springframework/context/annotation/p1.properties]")).as("property source p1 was not added").isTrue();
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +87,6 @@ class PropertySourceAnnotationTests {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithTestProfileBeans.class);
|
||||
assertThat(ctx.containsBean("testBean")).isTrue();
|
||||
assertThat(ctx.containsBean("testProfileBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +101,6 @@ class PropertySourceAnnotationTests {
|
||||
ctx.refresh();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
{
|
||||
@@ -113,7 +109,6 @@ class PropertySourceAnnotationTests {
|
||||
ctx.refresh();
|
||||
// p1 should 'win' as it was registered last
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +118,6 @@ class PropertySourceAnnotationTests {
|
||||
ctx.register(ConfigWithImplicitName.class, WithCustomFactory.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("P2TESTBEAN");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,7 +126,6 @@ class PropertySourceAnnotationTests {
|
||||
ctx.register(ConfigWithImplicitName.class, WithCustomFactoryAsMeta.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("P2TESTBEAN");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,7 +139,6 @@ class PropertySourceAnnotationTests {
|
||||
void withUnresolvablePlaceholderAndDefault() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithUnresolvablePlaceholderAndDefault.class);
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,7 +147,6 @@ class PropertySourceAnnotationTests {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithResolvablePlaceholder.class);
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
System.clearProperty("path.to.properties");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,7 +155,6 @@ class PropertySourceAnnotationTests {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithResolvablePlaceholderAndFactoryBean.class);
|
||||
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
|
||||
System.clearProperty("path.to.properties");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,7 +171,6 @@ class PropertySourceAnnotationTests {
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,7 +180,6 @@ class PropertySourceAnnotationTests {
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,7 +189,6 @@ class PropertySourceAnnotationTests {
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,7 +234,6 @@ class PropertySourceAnnotationTests {
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
// p2 should 'win' as it was registered last
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -262,7 +248,6 @@ class PropertySourceAnnotationTests {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithIgnoredPropertySource.class);
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -271,7 +256,6 @@ class PropertySourceAnnotationTests {
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
|
||||
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
|
||||
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,8 +265,6 @@ class PropertySourceAnnotationTests {
|
||||
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithMultipleResourceLocations.class);
|
||||
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
|
||||
ctxWithName.close();
|
||||
ctxWithoutName.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -290,7 +272,6 @@ class PropertySourceAnnotationTests {
|
||||
// SPR-12198: p4 should 'win' as it was registered last
|
||||
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithFourResourceLocations.class);
|
||||
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("p4TestBean");
|
||||
ctxWithoutName.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -302,7 +283,7 @@ class PropertySourceAnnotationTests {
|
||||
ctxWithoutName.register(ConfigWithFourResourceLocations.class);
|
||||
ctxWithoutName.refresh();
|
||||
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("myTestBean");
|
||||
ctxWithoutName.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+9
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.context.annotation.role.ComponentWithoutRole;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the use of the @Role and @Description annotation on @Bean methods and @Component classes.
|
||||
*
|
||||
@@ -31,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
class RoleAndDescriptionAnnotationTests {
|
||||
public class RoleAndDescriptionAnnotationTests {
|
||||
|
||||
@Test
|
||||
void onBeanMethod() {
|
||||
public void onBeanMethod() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(Config.class);
|
||||
ctx.refresh();
|
||||
@@ -42,11 +43,10 @@ class RoleAndDescriptionAnnotationTests {
|
||||
assertThat(ctx.getBeanDefinition("foo").getDescription()).isNull();
|
||||
assertThat(ctx.getBeanDefinition("bar").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
assertThat(ctx.getBeanDefinition("bar").getDescription()).isEqualTo("A Bean method with a role");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void onComponentClass() {
|
||||
public void onComponentClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ComponentWithoutRole.class, ComponentWithRole.class);
|
||||
ctx.refresh();
|
||||
@@ -54,11 +54,11 @@ class RoleAndDescriptionAnnotationTests {
|
||||
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription()).isNull();
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription()).isEqualTo("A Component with a role");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void viaComponentScanning() {
|
||||
public void viaComponentScanning() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.scan("org.springframework.context.annotation.role");
|
||||
ctx.refresh();
|
||||
@@ -66,21 +66,20 @@ class RoleAndDescriptionAnnotationTests {
|
||||
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription()).isNull();
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription()).isEqualTo("A Component with a role");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
String foo() {
|
||||
public String foo() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Description("A Bean method with a role")
|
||||
String bar() {
|
||||
public String bar() {
|
||||
return "bar";
|
||||
}
|
||||
}
|
||||
|
||||
+7
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -36,20 +36,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
class Spr11202Tests {
|
||||
public class Spr11202Tests {
|
||||
|
||||
@Test
|
||||
void withImporter() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
|
||||
public void testWithImporter() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
|
||||
assertThat(context.getBean("value")).isEqualTo("foo");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withoutImporter() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
public void testWithoutImporter() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(context.getBean("value")).isEqualTo("foo");
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -29,22 +29,24 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class Spr11310Tests {
|
||||
public class Spr11310Tests {
|
||||
|
||||
@Test
|
||||
void orderedList() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
public void orderedList() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
StringHolder holder = context.getBean(StringHolder.class);
|
||||
assertThat(holder.itemsList).containsExactly("second", "first", "unknownOrder");
|
||||
context.close();
|
||||
assertThat(holder.itemsList.get(0)).isEqualTo("second");
|
||||
assertThat(holder.itemsList.get(1)).isEqualTo("first");
|
||||
assertThat(holder.itemsList.get(2)).isEqualTo("unknownOrder");
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderedArray() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
public void orderedArray() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
StringHolder holder = context.getBean(StringHolder.class);
|
||||
assertThat(holder.itemsArray).containsExactly("second", "first", "unknownOrder");
|
||||
context.close();
|
||||
assertThat(holder.itemsArray[0]).isEqualTo("second");
|
||||
assertThat(holder.itemsArray[1]).isEqualTo("first");
|
||||
assertThat(holder.itemsArray[2]).isEqualTo("unknownOrder");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -24,12 +24,11 @@ import org.springframework.aop.target.CommonsPool2TargetSource;
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class Spr15042Tests {
|
||||
public class Spr15042Tests {
|
||||
|
||||
@Test
|
||||
void poolingTargetSource() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(PoolingTargetSourceConfig.class);
|
||||
context.close();
|
||||
public void poolingTargetSource() {
|
||||
new AnnotationConfigApplicationContext(PoolingTargetSourceConfig.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +36,7 @@ class Spr15042Tests {
|
||||
static class PoolingTargetSourceConfig {
|
||||
|
||||
@Bean
|
||||
@Scope(scopeName = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public ProxyFactoryBean myObject() {
|
||||
ProxyFactoryBean pfb = new ProxyFactoryBean();
|
||||
pfb.setTargetSource(poolTargetSource());
|
||||
|
||||
+15
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -20,62 +20,56 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class Spr15275Tests {
|
||||
public class Spr15275Tests {
|
||||
|
||||
@Test
|
||||
void withFactoryBean() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFactoryBean.class);
|
||||
public void testWithFactoryBean() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFactoryBean.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withAbstractFactoryBean() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBean.class);
|
||||
public void testWithAbstractFactoryBean() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBean.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withAbstractFactoryBeanForInterface() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanForInterface.class);
|
||||
public void testWithAbstractFactoryBeanForInterface() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanForInterface.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withAbstractFactoryBeanAsReturnType() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanAsReturnType.class);
|
||||
public void testWithAbstractFactoryBeanAsReturnType() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAbstractFactoryBeanAsReturnType.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withFinalFactoryBean() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBean.class);
|
||||
public void testWithFinalFactoryBean() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBean.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
assertThat(context.getBean(Bar.class).foo).isSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withFinalFactoryBeanAsReturnType() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBeanAsReturnType.class);
|
||||
public void testWithFinalFactoryBeanAsReturnType() {
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBeanAsReturnType.class);
|
||||
assertThat(context.getBean(Bar.class).foo.toString()).isEqualTo("x");
|
||||
// not same due to fallback to raw FinalFactoryBean instance with repeated getObject() invocations
|
||||
assertThat(context.getBean(Bar.class).foo).isNotSameAs(context.getBean(FooInterface.class));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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,19 +26,20 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class Spr16179Tests {
|
||||
public class Spr16179Tests {
|
||||
|
||||
@Test
|
||||
void repro() {
|
||||
try (AnnotationConfigApplicationContext bf = new AnnotationConfigApplicationContext(AssemblerConfig.class, AssemblerInjection.class)) {
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler0).isSameAs(bf.getBean("someAssembler"));
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler1); TODO: accidental match
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler2);
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler3).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler4).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler5).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler6).isSameAs(bf.getBean("pageAssembler"));
|
||||
}
|
||||
public void repro() {
|
||||
AnnotationConfigApplicationContext bf =
|
||||
new AnnotationConfigApplicationContext(AssemblerConfig.class, AssemblerInjection.class);
|
||||
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler0).isSameAs(bf.getBean("someAssembler"));
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler1); TODO: accidental match
|
||||
// assertNull(bf.getBean(AssemblerInjection.class).assembler2);
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler3).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler4).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler5).isSameAs(bf.getBean("pageAssembler"));
|
||||
assertThat(bf.getBean(AssemblerInjection.class).assembler6).isSameAs(bf.getBean("pageAssembler"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+17
-32
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -55,50 +55,46 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class AutowiredConfigurationTests {
|
||||
public class AutowiredConfigurationTests {
|
||||
|
||||
@Test
|
||||
void testAutowiredConfigurationDependencies() {
|
||||
public void testAutowiredConfigurationDependencies() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
AutowiredConfigurationTests.class.getSimpleName() + ".xml", AutowiredConfigurationTests.class);
|
||||
|
||||
assertThat(context.getBean("colour", Colour.class)).isEqualTo(Colour.RED);
|
||||
assertThat(context.getBean("testBean", TestBean.class).getName()).isEqualTo(Colour.RED.toString());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutowiredConfigurationMethodDependencies() {
|
||||
public void testAutowiredConfigurationMethodDependencies() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
AutowiredMethodConfig.class, ColorConfig.class);
|
||||
|
||||
assertThat(context.getBean(Colour.class)).isEqualTo(Colour.RED);
|
||||
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("RED-RED");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutowiredConfigurationMethodDependenciesWithOptionalAndAvailable() {
|
||||
public void testAutowiredConfigurationMethodDependenciesWithOptionalAndAvailable() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
OptionalAutowiredMethodConfig.class, ColorConfig.class);
|
||||
|
||||
assertThat(context.getBean(Colour.class)).isEqualTo(Colour.RED);
|
||||
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("RED-RED");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutowiredConfigurationMethodDependenciesWithOptionalAndNotAvailable() {
|
||||
public void testAutowiredConfigurationMethodDependenciesWithOptionalAndNotAvailable() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
OptionalAutowiredMethodConfig.class);
|
||||
|
||||
assertThat(context.getBeansOfType(Colour.class).isEmpty()).isTrue();
|
||||
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutowiredSingleConstructorSupported() {
|
||||
public void testAutowiredSingleConstructorSupported() {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
|
||||
new ClassPathResource("annotation-config.xml", AutowiredConstructorConfig.class));
|
||||
@@ -107,11 +103,10 @@ class AutowiredConfigurationTests {
|
||||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(Colour.class)).isSameAs(ctx.getBean(AutowiredConstructorConfig.class).colour);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testObjectFactoryConstructorWithTypeVariable() {
|
||||
public void testObjectFactoryConstructorWithTypeVariable() {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
|
||||
new ClassPathResource("annotation-config.xml", ObjectFactoryConstructorConfig.class));
|
||||
@@ -120,11 +115,10 @@ class AutowiredConfigurationTests {
|
||||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(Colour.class)).isSameAs(ctx.getBean(ObjectFactoryConstructorConfig.class).colour);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutowiredAnnotatedConstructorSupported() {
|
||||
public void testAutowiredAnnotatedConstructorSupported() {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
|
||||
new ClassPathResource("annotation-config.xml", MultipleConstructorConfig.class));
|
||||
@@ -133,55 +127,48 @@ class AutowiredConfigurationTests {
|
||||
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(Colour.class)).isSameAs(ctx.getBean(MultipleConstructorConfig.class).colour);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValueInjection() {
|
||||
public void testValueInjection() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"ValueInjectionTests.xml", AutowiredConfigurationTests.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValueInjectionWithMetaAnnotation() {
|
||||
public void testValueInjectionWithMetaAnnotation() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithMetaAnnotation.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValueInjectionWithAliasedMetaAnnotation() {
|
||||
public void testValueInjectionWithAliasedMetaAnnotation() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithAliasedMetaAnnotation.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValueInjectionWithProviderFields() {
|
||||
public void testValueInjectionWithProviderFields() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithProviderFields.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValueInjectionWithProviderConstructorArguments() {
|
||||
public void testValueInjectionWithProviderConstructorArguments() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithProviderConstructorArguments.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValueInjectionWithProviderMethodArguments() {
|
||||
public void testValueInjectionWithProviderMethodArguments() {
|
||||
AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext(ValueConfigWithProviderMethodArguments.class);
|
||||
doTestValueInjection(context);
|
||||
context.close();
|
||||
}
|
||||
|
||||
private void doTestValueInjection(BeanFactory context) {
|
||||
@@ -211,18 +198,17 @@ class AutowiredConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomPropertiesWithClassPathContext() throws IOException {
|
||||
public void testCustomPropertiesWithClassPathContext() throws IOException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class);
|
||||
|
||||
TestBean testBean = context.getBean("testBean", TestBean.class);
|
||||
assertThat(testBean.getName()).isEqualTo("localhost");
|
||||
assertThat(testBean.getAge()).isEqualTo(contentLength());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomPropertiesWithGenericContext() throws IOException {
|
||||
public void testCustomPropertiesWithGenericContext() throws IOException {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
new XmlBeanDefinitionReader(context).loadBeanDefinitions(
|
||||
new ClassPathResource("AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class));
|
||||
@@ -231,7 +217,6 @@ class AutowiredConfigurationTests {
|
||||
TestBean testBean = context.getBean("testBean", TestBean.class);
|
||||
assertThat(testBean.getName()).isEqualTo("localhost");
|
||||
assertThat(testBean.getAge()).isEqualTo(contentLength());
|
||||
context.close();
|
||||
}
|
||||
|
||||
private int contentLength() throws IOException {
|
||||
|
||||
+15
-23
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -44,43 +44,40 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class BeanMethodQualificationTests {
|
||||
public class BeanMethodQualificationTests {
|
||||
|
||||
@Test
|
||||
void standard() {
|
||||
public void testStandard() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(StandardConfig.class, StandardPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isFalse();
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void scoped() {
|
||||
public void testScoped() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ScopedConfig.class, StandardPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isFalse();
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void scopedProxy() {
|
||||
public void testScopedProxy() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ScopedProxyConfig.class, StandardPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isTrue(); // a shared scoped proxy
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customWithLazyResolution() {
|
||||
public void testCustomWithLazyResolution() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(CustomConfig.class, CustomPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean1")).isFalse();
|
||||
@@ -92,11 +89,10 @@ class BeanMethodQualificationTests {
|
||||
TestBean testBean2 = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
|
||||
ctx.getDefaultListableBeanFactory(), TestBean.class, "boring");
|
||||
assertThat(testBean2.getName()).isEqualTo("boring");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customWithEarlyResolution() {
|
||||
public void testCustomWithEarlyResolution() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(CustomConfig.class, CustomPojo.class);
|
||||
ctx.refresh();
|
||||
@@ -107,11 +103,10 @@ class BeanMethodQualificationTests {
|
||||
"testBean2", ctx.getDefaultListableBeanFactory())).isTrue();
|
||||
CustomPojo pojo = ctx.getBean(CustomPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customWithAsm() {
|
||||
public void testCustomWithAsm() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.registerBeanDefinition("customConfig", new RootBeanDefinition(CustomConfig.class.getName()));
|
||||
RootBeanDefinition customPojo = new RootBeanDefinition(CustomPojo.class.getName());
|
||||
@@ -122,27 +117,24 @@ class BeanMethodQualificationTests {
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBean2")).isFalse();
|
||||
CustomPojo pojo = ctx.getBean(CustomPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customWithAttributeOverride() {
|
||||
public void testCustomWithAttributeOverride() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(CustomConfigWithAttributeOverride.class, CustomPojo.class);
|
||||
assertThat(ctx.getBeanFactory().containsSingleton("testBeanX")).isFalse();
|
||||
CustomPojo pojo = ctx.getBean(CustomPojo.class);
|
||||
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void beanNamesForAnnotation() {
|
||||
public void testBeanNamesForAnnotation() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(StandardConfig.class);
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Configuration.class)).isEqualTo(new String[] {"beanMethodQualificationTests.StandardConfig"});
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Scope.class)).isEqualTo(new String[] {});
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Lazy.class)).isEqualTo(new String[] {"testBean1"});
|
||||
assertThat(ctx.getBeanNamesForAnnotation(Boring.class)).isEqualTo(new String[] {"testBean2"});
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -249,31 +241,31 @@ class BeanMethodQualificationTests {
|
||||
|
||||
@Bean @Lazy @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface InterestingBean {
|
||||
public @interface InterestingBean {
|
||||
}
|
||||
|
||||
@Bean @Lazy @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface InterestingBeanWithName {
|
||||
public @interface InterestingBeanWithName {
|
||||
|
||||
String name();
|
||||
}
|
||||
|
||||
@Autowired @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface InterestingNeed {
|
||||
public @interface InterestingNeed {
|
||||
}
|
||||
|
||||
@Autowired @Qualifier("interesting")
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface InterestingNeedWithRequiredOverride {
|
||||
public @interface InterestingNeedWithRequiredOverride {
|
||||
|
||||
boolean required();
|
||||
}
|
||||
|
||||
@Component @Lazy
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface InterestingPojo {
|
||||
public @interface InterestingPojo {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests ensuring that configuration class bean names as expressed via @Configuration
|
||||
* or @Component 'value' attributes are indeed respected, and that customization of bean
|
||||
@@ -37,30 +38,32 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @since 3.1.1
|
||||
*/
|
||||
class ConfigurationBeanNameTests {
|
||||
public class ConfigurationBeanNameTests {
|
||||
|
||||
@Test
|
||||
void registerOuterConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(A.class);
|
||||
public void registerOuterConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(A.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean("outer")).isTrue();
|
||||
assertThat(ctx.containsBean("imported")).isTrue();
|
||||
assertThat(ctx.containsBean("nested")).isTrue();
|
||||
assertThat(ctx.containsBean("nestedBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerNestedConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(A.B.class);
|
||||
public void registerNestedConfig() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(A.B.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean("outer")).isFalse();
|
||||
assertThat(ctx.containsBean("imported")).isFalse();
|
||||
assertThat(ctx.containsBean("nested")).isTrue();
|
||||
assertThat(ctx.containsBean("nestedBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerOuterConfig_withBeanNameGenerator() {
|
||||
public void registerOuterConfig_withBeanNameGenerator() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
|
||||
@Override
|
||||
@@ -75,7 +78,6 @@ class ConfigurationBeanNameTests {
|
||||
assertThat(ctx.containsBean("custom-imported")).isTrue();
|
||||
assertThat(ctx.containsBean("custom-nested")).isTrue();
|
||||
assertThat(ctx.containsBean("nestedBean")).isTrue();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Configuration("outer")
|
||||
@@ -91,5 +93,4 @@ class ConfigurationBeanNameTests {
|
||||
static class C {
|
||||
@Bean public String s() { return "s"; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -37,6 +37,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* System tests covering use of AspectJ {@link Aspect}s in conjunction with {@link Configuration} classes.
|
||||
* {@link Bean} methods may return aspects, or Configuration classes may themselves be annotated with Aspect.
|
||||
@@ -50,15 +51,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class ConfigurationClassAspectIntegrationTests {
|
||||
public class ConfigurationClassAspectIntegrationTests {
|
||||
|
||||
@Test
|
||||
void aspectAnnotatedConfiguration() {
|
||||
public void aspectAnnotatedConfiguration() {
|
||||
assertAdviceWasApplied(AspectConfig.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void configurationIncludesAspect() {
|
||||
public void configurationIncludesAspect() {
|
||||
assertAdviceWasApplied(ConfigurationWithAspect.class);
|
||||
}
|
||||
|
||||
@@ -75,17 +76,15 @@ class ConfigurationClassAspectIntegrationTests {
|
||||
assertThat(testBean.getName()).isEqualTo("name");
|
||||
testBean.absquatulate();
|
||||
assertThat(testBean.getName()).isEqualTo("advisedName");
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withInnerClassAndLambdaExpression() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Application.class, CountingAspect.class);
|
||||
public void withInnerClassAndLambdaExpression() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Application.class, CountingAspect.class);
|
||||
ctx.getBeansOfType(Runnable.class).forEach((k, v) -> v.run());
|
||||
|
||||
// TODO: returns just 1 as of AspectJ 1.9 beta 3, not detecting the applicable lambda expression anymore
|
||||
// assertEquals(2, ctx.getBean(CountingAspect.class).count);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user