This commit is contained in:
Stéphane Nicoll 2024-01-03 16:34:07 +01:00
parent f846d9484c
commit 05ebca8677
218 changed files with 1576 additions and 1591 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -64,7 +64,7 @@ class AfterAdviceBindingTests {
} }
@AfterEach @AfterEach
void tearDown() throws Exception { void tearDown() {
this.ctx.close(); this.ctx.close();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -62,14 +62,14 @@ class AfterThrowingAdviceBindingTests {
@Test @Test
void simpleAfterThrowing() throws Throwable { void simpleAfterThrowing() {
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
this.testBean.exceptional(new Throwable())); this.testBean.exceptional(new Throwable()));
verify(mockCollaborator).noArgs(); verify(mockCollaborator).noArgs();
} }
@Test @Test
void afterThrowingWithBinding() throws Throwable { void afterThrowingWithBinding() {
Throwable t = new Throwable(); Throwable t = new Throwable();
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
this.testBean.exceptional(t)); this.testBean.exceptional(t));
@ -77,7 +77,7 @@ class AfterThrowingAdviceBindingTests {
} }
@Test @Test
void afterThrowingWithNamedTypeRestriction() throws Throwable { void afterThrowingWithNamedTypeRestriction() {
Throwable t = new Throwable(); Throwable t = new Throwable();
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
this.testBean.exceptional(t)); this.testBean.exceptional(t));
@ -87,7 +87,7 @@ class AfterThrowingAdviceBindingTests {
} }
@Test @Test
void afterThrowingWithRuntimeExceptionBinding() throws Throwable { void afterThrowingWithRuntimeExceptionBinding() {
RuntimeException ex = new RuntimeException(); RuntimeException ex = new RuntimeException();
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
this.testBean.exceptional(ex)); this.testBean.exceptional(ex));
@ -95,14 +95,14 @@ class AfterThrowingAdviceBindingTests {
} }
@Test @Test
void afterThrowingWithTypeSpecified() throws Throwable { void afterThrowingWithTypeSpecified() {
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
this.testBean.exceptional(new Throwable())); this.testBean.exceptional(new Throwable()));
verify(mockCollaborator).noArgsOnThrowableMatch(); verify(mockCollaborator).noArgsOnThrowableMatch();
} }
@Test @Test
void afterThrowingWithRuntimeTypeSpecified() throws Throwable { void afterThrowingWithRuntimeTypeSpecified() {
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
this.testBean.exceptional(new RuntimeException())); this.testBean.exceptional(new RuntimeException()));
verify(mockCollaborator).noArgsOnRuntimeExceptionMatch(); verify(mockCollaborator).noArgsOnRuntimeExceptionMatch();
@ -123,7 +123,7 @@ final class AfterThrowingAdviceBindingTestAspect {
void noArgsOnRuntimeExceptionMatch(); void noArgsOnRuntimeExceptionMatch();
} }
protected AfterThrowingAdviceBindingCollaborator collaborator = null; AfterThrowingAdviceBindingCollaborator collaborator = null;
public void setCollaborator(AfterThrowingAdviceBindingCollaborator aCollaborator) { public void setCollaborator(AfterThrowingAdviceBindingCollaborator aCollaborator) {
this.collaborator = aCollaborator; this.collaborator = aCollaborator;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -242,8 +242,7 @@ class SimpleSpringBeforeAdvice implements MethodBeforeAdvice, BeanNameAware {
* @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object) * @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object)
*/ */
@Override @Override
public void before(Method method, Object[] args, @Nullable Object target) public void before(Method method, Object[] args, @Nullable Object target) {
throws Throwable {
this.collaborator.beforeAdviceOne(this.name); this.collaborator.beforeAdviceOne(this.name);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -139,7 +139,7 @@ class BeanNamePointcutTests {
private int interceptionCount; private int interceptionCount;
@Override @Override
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable { public void before(Method method, Object[] args, @Nullable Object target) {
interceptionCount++; interceptionCount++;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -119,7 +119,7 @@ class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
} }
interface TestInterface { interface TestInterface {
public void doIt(); void doIt();
} }
static class TestImpl implements TestInterface { static class TestImpl implements TestInterface {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -107,7 +107,7 @@ class ThisAndTargetSelectionOnlyPointcutsTests {
interface TestInterface { interface TestInterface {
public void doIt(); void doIt();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
*/ */
class AnnotationBindingTestAspect { class AnnotationBindingTestAspect {
public String doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnnotation) throws Throwable { public String doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnnotation) {
return testAnnotation.value(); return testAnnotation.value();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -65,7 +65,7 @@ class AnnotationPointcutTests {
class TestMethodInterceptor implements MethodInterceptor { class TestMethodInterceptor implements MethodInterceptor {
@Override @Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable { public Object invoke(MethodInvocation methodInvocation) {
return "this value"; return "this value";
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,7 +51,7 @@ class AspectImplementingInterfaceTests {
interface AnInterface { interface AnInterface {
public void interfaceMethod(); void interfaceMethod();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -226,7 +226,7 @@ class TraceAfterReturningAdvice implements AfterReturningAdvice {
public int afterTakesInt; public int afterTakesInt;
@Override @Override
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { public void afterReturning(Object returnValue, Method method, Object[] args, Object target) {
++afterTakesInt; ++afterTakesInt;
} }
@ -270,7 +270,7 @@ class TraceBeforeAdvice implements MethodBeforeAdvice {
public int beforeStringReturn; public int beforeStringReturn;
@Override @Override
public void before(Method method, Object[] args, Object target) throws Throwable { public void before(Method method, Object[] args, Object target) {
++beforeStringReturn; ++beforeStringReturn;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -59,7 +59,7 @@ class SPR3064Tests {
class TransactionInterceptor { class TransactionInterceptor {
@Around(value="execution(* *..Service.*(..)) && @annotation(transaction)") @Around(value="execution(* *..Service.*(..)) && @annotation(transaction)")
public Object around(ProceedingJoinPoint pjp, Transaction transaction) throws Throwable { public Object around(ProceedingJoinPoint pjp, Transaction transaction) {
throw new RuntimeException("advice invoked"); throw new RuntimeException("advice invoked");
//return pjp.proceed(); //return pjp.proceed();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -157,11 +157,11 @@ class CountingAspectJAdvice {
private int aroundCount; private int aroundCount;
public void myBeforeAdvice() throws Throwable { public void myBeforeAdvice() {
this.beforeCount++; this.beforeCount++;
} }
public void myAfterAdvice() throws Throwable { public void myAfterAdvice() {
this.afterCount++; this.afterCount++;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -96,12 +96,12 @@ public abstract class AbstractAopProxyTests {
* to ensure that it was used appropriately by code. * to ensure that it was used appropriately by code.
*/ */
@BeforeEach @BeforeEach
public void reset() { void reset() {
mockTargetSource.reset(); mockTargetSource.reset();
} }
@AfterEach @AfterEach
public void verify() { void verify() {
mockTargetSource.verify(); mockTargetSource.verify();
} }
@ -125,7 +125,7 @@ public abstract class AbstractAopProxyTests {
* Simple test that if we set values we can get them out again. * Simple test that if we set values we can get them out again.
*/ */
@Test @Test
public void testValuesStick() { void testValuesStick() {
int age1 = 33; int age1 = 33;
int age2 = 37; int age2 = 37;
String name = "tony"; String name = "tony";
@ -146,7 +146,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testSerializationAdviceAndTargetNotSerializable() throws Exception { void testSerializationAdviceAndTargetNotSerializable() throws Exception {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
assertThat(SerializationTestUtils.isSerializable(tb)).isFalse(); assertThat(SerializationTestUtils.isSerializable(tb)).isFalse();
@ -159,7 +159,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testSerializationAdviceNotSerializable() throws Exception { void testSerializationAdviceNotSerializable() throws Exception {
SerializablePerson sp = new SerializablePerson(); SerializablePerson sp = new SerializablePerson();
assertThat(SerializationTestUtils.isSerializable(sp)).isTrue(); assertThat(SerializationTestUtils.isSerializable(sp)).isTrue();
@ -175,7 +175,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testSerializableTargetAndAdvice() throws Throwable { void testSerializableTargetAndAdvice() throws Throwable {
SerializablePerson personTarget = new SerializablePerson(); SerializablePerson personTarget = new SerializablePerson();
personTarget.setName("jim"); personTarget.setName("jim");
personTarget.setAge(26); personTarget.setAge(26);
@ -245,7 +245,7 @@ public abstract class AbstractAopProxyTests {
* Check also proxy exposure. * Check also proxy exposure.
*/ */
@Test @Test
public void testOneAdvisedObjectCallsAnother() { void testOneAdvisedObjectCallsAnother() {
int age1 = 33; int age1 = 33;
int age2 = 37; int age2 = 37;
@ -290,7 +290,7 @@ public abstract class AbstractAopProxyTests {
@Test @Test
public void testReentrance() { void testReentrance() {
int age1 = 33; int age1 = 33;
TestBean target1 = new TestBean(); TestBean target1 = new TestBean();
@ -314,7 +314,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testTargetCanGetProxy() { void testTargetCanGetProxy() {
NopInterceptor di = new NopInterceptor(); NopInterceptor di = new NopInterceptor();
INeedsToSeeProxy target = new TargetChecker(); INeedsToSeeProxy target = new TargetChecker();
ProxyFactory proxyFactory = new ProxyFactory(target); ProxyFactory proxyFactory = new ProxyFactory(target);
@ -343,24 +343,23 @@ public abstract class AbstractAopProxyTests {
ProxyFactory pf1 = new ProxyFactory(et); ProxyFactory pf1 = new ProxyFactory(et);
assertThat(pf1.isExposeProxy()).isFalse(); assertThat(pf1.isExposeProxy()).isFalse();
INeedsToSeeProxy proxied = (INeedsToSeeProxy) createProxy(pf1); INeedsToSeeProxy proxied = (INeedsToSeeProxy) createProxy(pf1);
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(proxied::incrementViaProxy);
proxied.incrementViaProxy());
} }
@Test @Test
public void testContext() throws Throwable { void testContext() {
testContext(true); testContext(true);
} }
@Test @Test
public void testNoContext() throws Throwable { void testNoContext() {
testContext(false); testContext(false);
} }
/** /**
* @param context if true, want context * @param context if true, want context
*/ */
private void testContext(final boolean context) throws Throwable { private void testContext(final boolean context) {
final String s = "foo"; final String s = "foo";
// Test return value // Test return value
MethodInterceptor mi = invocation -> { MethodInterceptor mi = invocation -> {
@ -394,7 +393,7 @@ public abstract class AbstractAopProxyTests {
* target returns {@code this} * target returns {@code this}
*/ */
@Test @Test
public void testTargetReturnsThis() throws Throwable { void testTargetReturnsThis() {
// Test return value // Test return value
TestBean raw = new OwnSpouse(); TestBean raw = new OwnSpouse();
@ -407,7 +406,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testDeclaredException() throws Throwable { void testDeclaredException() {
final Exception expectedException = new Exception(); final Exception expectedException = new Exception();
// Test return value // Test return value
MethodInterceptor mi = invocation -> { MethodInterceptor mi = invocation -> {
@ -435,7 +434,7 @@ public abstract class AbstractAopProxyTests {
* org.springframework.cglib UndeclaredThrowableException * org.springframework.cglib UndeclaredThrowableException
*/ */
@Test @Test
public void testUndeclaredCheckedException() throws Throwable { void testUndeclaredCheckedException() {
final Exception unexpectedException = new Exception(); final Exception unexpectedException = new Exception();
// Test return value // Test return value
MethodInterceptor mi = invocation -> { MethodInterceptor mi = invocation -> {
@ -455,7 +454,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testUndeclaredUncheckedException() throws Throwable { void testUndeclaredUncheckedException() {
final RuntimeException unexpectedException = new RuntimeException(); final RuntimeException unexpectedException = new RuntimeException();
// Test return value // Test return value
MethodInterceptor mi = invocation -> { MethodInterceptor mi = invocation -> {
@ -481,7 +480,7 @@ public abstract class AbstractAopProxyTests {
* so as to guarantee a consistent programming model. * so as to guarantee a consistent programming model.
*/ */
@Test @Test
public void testTargetCanGetInvocationEvenIfNoAdviceChain() throws Throwable { void testTargetCanGetInvocationEvenIfNoAdviceChain() {
NeedsToSeeProxy target = new NeedsToSeeProxy(); NeedsToSeeProxy target = new NeedsToSeeProxy();
AdvisedSupport pc = new AdvisedSupport(INeedsToSeeProxy.class); AdvisedSupport pc = new AdvisedSupport(INeedsToSeeProxy.class);
pc.setTarget(target); pc.setTarget(target);
@ -495,7 +494,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testTargetCanGetInvocation() throws Throwable { void testTargetCanGetInvocation() {
final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean(); final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean();
AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class); AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class);
@ -528,7 +527,7 @@ public abstract class AbstractAopProxyTests {
* Test stateful interceptor * Test stateful interceptor
*/ */
@Test @Test
public void testMixinWithIntroductionAdvisor() throws Throwable { void testMixinWithIntroductionAdvisor() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(); ProxyFactory pc = new ProxyFactory();
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
@ -539,7 +538,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testMixinWithIntroductionInfo() throws Throwable { void testMixinWithIntroductionInfo() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(); ProxyFactory pc = new ProxyFactory();
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
@ -572,7 +571,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testReplaceArgument() throws Throwable { void testReplaceArgument() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(); ProxyFactory pc = new ProxyFactory();
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
@ -593,7 +592,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testCanCastProxyToProxyConfig() throws Throwable { void testCanCastProxyToProxyConfig() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(tb); ProxyFactory pc = new ProxyFactory(tb);
NopInterceptor di = new NopInterceptor(); NopInterceptor di = new NopInterceptor();
@ -629,7 +628,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testAdviceImplementsIntroductionInfo() throws Throwable { void testAdviceImplementsIntroductionInfo() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
String name = "tony"; String name = "tony";
tb.setName(name); tb.setName(name);
@ -646,7 +645,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testCannotAddDynamicIntroductionAdviceExceptInIntroductionAdvice() throws Throwable { void testCannotAddDynamicIntroductionAdviceExceptInIntroductionAdvice() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -659,7 +658,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() throws Throwable { void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -680,7 +679,7 @@ public abstract class AbstractAopProxyTests {
* that are unsupported by the IntroductionInterceptor. * that are unsupported by the IntroductionInterceptor.
*/ */
@Test @Test
public void testCannotAddIntroductionAdviceWithUnimplementedInterface() throws Throwable { void testCannotAddIntroductionAdviceWithUnimplementedInterface() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -696,7 +695,7 @@ public abstract class AbstractAopProxyTests {
* as it's constrained by the interface. * as it's constrained by the interface.
*/ */
@Test @Test
public void testIntroductionThrowsUncheckedException() throws Throwable { void testIntroductionThrowsUncheckedException() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -721,7 +720,7 @@ public abstract class AbstractAopProxyTests {
* Should only be able to introduce interfaces, not classes. * Should only be able to introduce interfaces, not classes.
*/ */
@Test @Test
public void testCannotAddIntroductionAdviceToIntroduceClass() throws Throwable { void testCannotAddIntroductionAdviceToIntroduceClass() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -734,7 +733,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testCannotAddInterceptorWhenFrozen() throws Throwable { void testCannotAddInterceptorWhenFrozen() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -754,7 +753,7 @@ public abstract class AbstractAopProxyTests {
* Check that casting to Advised can't get around advice freeze. * Check that casting to Advised can't get around advice freeze.
*/ */
@Test @Test
public void testCannotAddAdvisorWhenFrozenUsingCast() throws Throwable { void testCannotAddAdvisorWhenFrozenUsingCast() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -774,7 +773,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testCannotRemoveAdvisorWhenFrozen() throws Throwable { void testCannotRemoveAdvisorWhenFrozen() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -799,7 +798,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testUseAsHashKey() { void testUseAsHashKey() {
TestBean target1 = new TestBean(); TestBean target1 = new TestBean();
ProxyFactory pf1 = new ProxyFactory(target1); ProxyFactory pf1 = new ProxyFactory(target1);
pf1.addAdvice(new NopInterceptor()); pf1.addAdvice(new NopInterceptor());
@ -824,7 +823,7 @@ public abstract class AbstractAopProxyTests {
* Check that the string is informative. * Check that the string is informative.
*/ */
@Test @Test
public void testProxyConfigString() { void testProxyConfigString() {
TestBean target = new TestBean(); TestBean target = new TestBean();
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
pc.setInterfaces(ITestBean.class); pc.setInterfaces(ITestBean.class);
@ -840,7 +839,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testCanPreventCastToAdvisedUsingOpaque() { void testCanPreventCastToAdvisedUsingOpaque() {
TestBean target = new TestBean(); TestBean target = new TestBean();
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
pc.setInterfaces(ITestBean.class); pc.setInterfaces(ITestBean.class);
@ -861,7 +860,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testAdviceSupportListeners() throws Throwable { void testAdviceSupportListeners() {
TestBean target = new TestBean(); TestBean target = new TestBean();
target.setAge(21); target.setAge(21);
@ -900,7 +899,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testExistingProxyChangesTarget() throws Throwable { void testExistingProxyChangesTarget() {
TestBean tb1 = new TestBean(); TestBean tb1 = new TestBean();
tb1.setAge(33); tb1.setAge(33);
@ -943,7 +942,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testDynamicMethodPointcutThatAlwaysAppliesStatically() throws Throwable { void testDynamicMethodPointcutThatAlwaysAppliesStatically() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(); ProxyFactory pc = new ProxyFactory();
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
@ -960,7 +959,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() throws Throwable { void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(); ProxyFactory pc = new ProxyFactory();
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
@ -983,7 +982,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testStaticMethodPointcut() throws Throwable { void testStaticMethodPointcut() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(); ProxyFactory pc = new ProxyFactory();
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
@ -1005,7 +1004,7 @@ public abstract class AbstractAopProxyTests {
* We can do this if we clone the invocation. * We can do this if we clone the invocation.
*/ */
@Test @Test
public void testCloneInvocationToProceedThreeTimes() throws Throwable { void testCloneInvocationToProceedThreeTimes() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(tb); ProxyFactory pc = new ProxyFactory(tb);
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
@ -1042,14 +1041,11 @@ public abstract class AbstractAopProxyTests {
* We want to change the arguments on a clone: it shouldn't affect the original. * We want to change the arguments on a clone: it shouldn't affect the original.
*/ */
@Test @Test
public void testCanChangeArgumentsIndependentlyOnClonedInvocation() throws Throwable { void testCanChangeArgumentsIndependentlyOnClonedInvocation() {
TestBean tb = new TestBean(); TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory(tb); ProxyFactory pc = new ProxyFactory(tb);
pc.addInterface(ITestBean.class); pc.addInterface(ITestBean.class);
/**
* Changes the name, then changes it back.
*/
MethodInterceptor nameReverter = mi -> { MethodInterceptor nameReverter = mi -> {
MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone(); MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone();
String oldName = ((ITestBean) mi.getThis()).getName(); String oldName = ((ITestBean) mi.getThis()).getName();
@ -1084,14 +1080,12 @@ public abstract class AbstractAopProxyTests {
it.setName(name2); it.setName(name2);
// NameReverter saved it back // NameReverter saved it back
assertThat(it.getName()).isEqualTo(name1); assertThat(it.getName()).isEqualTo(name1);
assertThat(saver.names).hasSize(2); assertThat(saver.names).containsExactly(name2, name1);
assertThat(saver.names).element(0).isEqualTo(name2);
assertThat(saver.names).element(1).isEqualTo(name1);
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")
@Test @Test
public void testOverloadedMethodsWithDifferentAdvice() throws Throwable { void testOverloadedMethodsWithDifferentAdvice() {
Overloads target = new Overloads(); Overloads target = new Overloads();
ProxyFactory pc = new ProxyFactory(target); ProxyFactory pc = new ProxyFactory(target);
@ -1127,7 +1121,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testProxyIsBoundBeforeTargetSourceInvoked() { void testProxyIsBoundBeforeTargetSourceInvoked() {
final TestBean target = new TestBean(); final TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
pf.addAdvice(new DebugInterceptor()); pf.addAdvice(new DebugInterceptor());
@ -1142,7 +1136,7 @@ public abstract class AbstractAopProxyTests {
return TestBean.class; return TestBean.class;
} }
@Override @Override
public Object getTarget() throws Exception { public Object getTarget() {
assertThat(AopContext.currentProxy()).isEqualTo(proxy); assertThat(AopContext.currentProxy()).isEqualTo(proxy);
return target; return target;
} }
@ -1153,7 +1147,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testEquals() { void testEquals() {
IOther a = new AllInstancesAreEqual(); IOther a = new AllInstancesAreEqual();
IOther b = new AllInstancesAreEqual(); IOther b = new AllInstancesAreEqual();
NopInterceptor i1 = new NopInterceptor(); NopInterceptor i1 = new NopInterceptor();
@ -1183,7 +1177,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testBeforeAdvisorIsInvoked() { void testBeforeAdvisorIsInvoked() {
CountingBeforeAdvice cba = new CountingBeforeAdvice(); CountingBeforeAdvice cba = new CountingBeforeAdvice();
@SuppressWarnings("serial") @SuppressWarnings("serial")
Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cba) { Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cba) {
@ -1212,7 +1206,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testUserAttributes() throws Throwable { void testUserAttributes() {
class MapAwareMethodInterceptor implements MethodInterceptor { class MapAwareMethodInterceptor implements MethodInterceptor {
private final Map<String, String> expectedValues; private final Map<String, String> expectedValues;
private final Map<String, String> valuesToAdd; private final Map<String, String> valuesToAdd;
@ -1263,7 +1257,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testMultiAdvice() throws Throwable { void testMultiAdvice() {
CountingMultiAdvice cca = new CountingMultiAdvice(); CountingMultiAdvice cca = new CountingMultiAdvice();
@SuppressWarnings("serial") @SuppressWarnings("serial")
Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cca) { Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cca) {
@ -1297,7 +1291,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testBeforeAdviceThrowsException() { void testBeforeAdviceThrowsException() {
final RuntimeException rex = new RuntimeException(); final RuntimeException rex = new RuntimeException();
@SuppressWarnings("serial") @SuppressWarnings("serial")
CountingBeforeAdvice ba = new CountingBeforeAdvice() { CountingBeforeAdvice ba = new CountingBeforeAdvice() {
@ -1339,11 +1333,11 @@ public abstract class AbstractAopProxyTests {
@Test @Test
public void testAfterReturningAdvisorIsInvoked() { void testAfterReturningAdvisorIsInvoked() {
class SummingAfterAdvice implements AfterReturningAdvice { class SummingAfterAdvice implements AfterReturningAdvice {
public int sum; public int sum;
@Override @Override
public void afterReturning(@Nullable Object returnValue, Method m, Object[] args, @Nullable Object target) throws Throwable { public void afterReturning(@Nullable Object returnValue, Method m, Object[] args, @Nullable Object target) {
sum += (Integer) returnValue; sum += (Integer) returnValue;
} }
} }
@ -1376,7 +1370,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testAfterReturningAdvisorIsNotInvokedOnException() { void testAfterReturningAdvisorIsNotInvokedOnException() {
CountingAfterReturningAdvice car = new CountingAfterReturningAdvice(); CountingAfterReturningAdvice car = new CountingAfterReturningAdvice();
TestBean target = new TestBean(); TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target); ProxyFactory pf = new ProxyFactory(target);
@ -1398,7 +1392,7 @@ public abstract class AbstractAopProxyTests {
@Test @Test
public void testThrowsAdvisorIsInvoked() throws Throwable { void testThrowsAdvisorIsInvoked() {
// Reacts to ServletException and RemoteException // Reacts to ServletException and RemoteException
MyThrowsHandler th = new MyThrowsHandler(); MyThrowsHandler th = new MyThrowsHandler();
@SuppressWarnings("serial") @SuppressWarnings("serial")
@ -1431,7 +1425,7 @@ public abstract class AbstractAopProxyTests {
} }
@Test @Test
public void testAddThrowsAdviceWithoutAdvisor() throws Throwable { void testAddThrowsAdviceWithoutAdvisor() {
// Reacts to ServletException and RemoteException // Reacts to ServletException and RemoteException
MyThrowsHandler th = new MyThrowsHandler(); MyThrowsHandler th = new MyThrowsHandler();
@ -1790,21 +1784,20 @@ public abstract class AbstractAopProxyTests {
AfterReturningAdvice, ThrowsAdvice { AfterReturningAdvice, ThrowsAdvice {
@Override @Override
public void before(Method m, Object[] args, @Nullable Object target) throws Throwable { public void before(Method m, Object[] args, @Nullable Object target) {
count(m); count(m);
} }
@Override @Override
public void afterReturning(@Nullable Object o, Method m, Object[] args, @Nullable Object target) public void afterReturning(@Nullable Object o, Method m, Object[] args, @Nullable Object target) {
throws Throwable {
count(m); count(m);
} }
public void afterThrowing(IOException ex) throws Throwable { public void afterThrowing(IOException ex) {
count(IOException.class.getName()); count(IOException.class.getName());
} }
public void afterThrowing(UncheckedException ex) throws Throwable { public void afterThrowing(UncheckedException ex) {
count(UncheckedException.class.getName()); count(UncheckedException.class.getName());
} }
@ -1814,11 +1807,11 @@ public abstract class AbstractAopProxyTests {
@SuppressWarnings("serial") @SuppressWarnings("serial")
public static class CountingThrowsAdvice extends MethodCounter implements ThrowsAdvice { public static class CountingThrowsAdvice extends MethodCounter implements ThrowsAdvice {
public void afterThrowing(IOException ex) throws Throwable { public void afterThrowing(IOException ex) {
count(IOException.class.getName()); count(IOException.class.getName());
} }
public void afterThrowing(UncheckedException ex) throws Throwable { public void afterThrowing(UncheckedException ex) {
count(UncheckedException.class.getName()); count(UncheckedException.class.getName());
} }
@ -1869,7 +1862,7 @@ public abstract class AbstractAopProxyTests {
* @see org.springframework.aop.TargetSource#getTarget() * @see org.springframework.aop.TargetSource#getTarget()
*/ */
@Override @Override
public Object getTarget() throws Exception { public Object getTarget() {
++gets; ++gets;
return target; return target;
} }
@ -1878,7 +1871,7 @@ public abstract class AbstractAopProxyTests {
* @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object) * @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object)
*/ */
@Override @Override
public void releaseTarget(Object pTarget) throws Exception { public void releaseTarget(Object pTarget) {
if (pTarget != this.target) { if (pTarget != this.target) {
throw new RuntimeException("Released wrong target"); throw new RuntimeException("Released wrong target");
} }

View File

@ -458,13 +458,13 @@ class CglibProxyTests extends AbstractAopProxyTests {
public enum MyEnum implements MyInterface { public enum MyEnum implements MyInterface {
A, B; A, B
} }
public enum MyOtherEnum implements MyInterface { public enum MyOtherEnum implements MyInterface {
C, D; C, D
} }
@ -482,7 +482,7 @@ class CglibProxyTests extends AbstractAopProxyTests {
return finallyInvoked; return finallyInvoked;
} }
public void doTest() throws Exception { public void doTest() {
try { try {
throw new ApplicationContextException("foo"); throw new ApplicationContextException("foo");
} }
@ -586,7 +586,7 @@ class CglibTestBean {
class UnsupportedInterceptor implements MethodInterceptor { class UnsupportedInterceptor implements MethodInterceptor {
@Override @Override
public Object invoke(MethodInvocation mi) throws Throwable { public Object invoke(MethodInvocation mi) {
throw new UnsupportedOperationException(mi.getMethod().getName()); throw new UnsupportedOperationException(mi.getMethod().getName());
} }
} }

View File

@ -239,13 +239,13 @@ class JdkDynamicProxyTests extends AbstractAopProxyTests {
public enum MyEnum implements MyInterface { public enum MyEnum implements MyInterface {
A, B; A, B
} }
public enum MyOtherEnum implements MyInterface { public enum MyOtherEnum implements MyInterface {
C, D; C, D
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -92,7 +92,7 @@ class ProxyFactoryBeanTests {
@BeforeEach @BeforeEach
void setup() throws Exception { void setup() {
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
parent.registerBeanDefinition("target2", new RootBeanDefinition(TestApplicationListener.class)); parent.registerBeanDefinition("target2", new RootBeanDefinition(TestApplicationListener.class));
this.factory = new DefaultListableBeanFactory(parent); this.factory = new DefaultListableBeanFactory(parent);
@ -425,13 +425,12 @@ class ProxyFactoryBeanTests {
tb.getAge(); tb.getAge();
tb.setName("Tristan"); tb.setName("Tristan");
tb.toString(); tb.toString();
assertThat(PointcutForVoid.methodNames).as("Recorded wrong number of invocations").hasSize(2); assertThat(PointcutForVoid.methodNames).as("Recorded wrong number of invocations")
assertThat(PointcutForVoid.methodNames).element(0).isEqualTo("setAge"); .containsExactly("setAge", "setName");
assertThat(PointcutForVoid.methodNames).element(1).isEqualTo("setName");
} }
@Test @Test
void testCanAddThrowsAdviceWithoutAdvisor() throws Throwable { void testCanAddThrowsAdviceWithoutAdvisor() {
DefaultListableBeanFactory f = new DefaultListableBeanFactory(); DefaultListableBeanFactory f = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(f).loadBeanDefinitions(new ClassPathResource(THROWS_ADVICE_CONTEXT, CLASS)); new XmlBeanDefinitionReader(f).loadBeanDefinitions(new ClassPathResource(THROWS_ADVICE_CONTEXT, CLASS));
MyThrowsHandler th = (MyThrowsHandler) f.getBean("throwsAdvice"); MyThrowsHandler th = (MyThrowsHandler) f.getBean("throwsAdvice");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -81,7 +81,7 @@ class AdvisorAdapterRegistrationTests {
interface SimpleBeforeAdvice extends BeforeAdvice { interface SimpleBeforeAdvice extends BeforeAdvice {
void before() throws Throwable; void before();
} }
@ -108,7 +108,7 @@ class SimpleBeforeAdviceImpl implements SimpleBeforeAdvice {
private int invocationCounter; private int invocationCounter;
@Override @Override
public void before() throws Throwable { public void before() {
++invocationCounter; ++invocationCounter;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,6 @@
package org.springframework.aop.framework.autoproxy; package org.springframework.aop.framework.autoproxy;
import java.io.IOException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.aop.Advisor; import org.springframework.aop.Advisor;
@ -63,7 +61,7 @@ class AdvisorAutoProxyCreatorTests {
/** /**
* Return a bean factory with attributes and EnterpriseServices configured. * Return a bean factory with attributes and EnterpriseServices configured.
*/ */
protected BeanFactory getBeanFactory() throws IOException { protected BeanFactory getBeanFactory() {
return new ClassPathXmlApplicationContext(DEFAULT_CONTEXT, CLASS); return new ClassPathXmlApplicationContext(DEFAULT_CONTEXT, CLASS);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -57,7 +57,7 @@ class BeanNameAutoProxyCreatorInitTests {
class NullChecker implements MethodBeforeAdvice { class NullChecker implements MethodBeforeAdvice {
@Override @Override
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable { public void before(Method method, Object[] args, @Nullable Object target) {
check(args); check(args);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -198,7 +198,7 @@ class BeanNameAutoProxyCreatorTests {
class CreatesTestBean implements FactoryBean<Object> { class CreatesTestBean implements FactoryBean<Object> {
@Override @Override
public Object getObject() throws Exception { public Object getObject() {
return new TestBean(); return new TestBean();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -56,7 +56,7 @@ class CommonsPool2TargetSourceTests {
private DefaultListableBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
@BeforeEach @BeforeEach
void setUp() throws Exception { void setUp() {
this.beanFactory = new DefaultListableBeanFactory(); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 3.0 * @since 3.0
*/ */
public class InjectAnnotationAutowireContextTests { class InjectAnnotationAutowireContextTests {
private static final String JUERGEN = "juergen"; private static final String JUERGEN = "juergen";
@ -52,7 +52,7 @@ public class InjectAnnotationAutowireContextTests {
@Test @Test
public void testAutowiredFieldWithSingleNonQualifiedCandidate() { void testAutowiredFieldWithSingleNonQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -70,7 +70,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredMethodParameterWithSingleNonQualifiedCandidate() { void testAutowiredMethodParameterWithSingleNonQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -88,7 +88,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredConstructorArgumentWithSingleNonQualifiedCandidate() { void testAutowiredConstructorArgumentWithSingleNonQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -103,7 +103,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldWithSingleQualifiedCandidate() { void testAutowiredFieldWithSingleQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -118,7 +118,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredMethodParameterWithSingleQualifiedCandidate() { void testAutowiredMethodParameterWithSingleQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -135,7 +135,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredMethodParameterWithStaticallyQualifiedCandidate() { void testAutowiredMethodParameterWithStaticallyQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -152,7 +152,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredMethodParameterWithStaticallyQualifiedCandidateAmongOthers() { void testAutowiredMethodParameterWithStaticallyQualifiedCandidateAmongOthers() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -172,7 +172,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredConstructorArgumentWithSingleQualifiedCandidate() { void testAutowiredConstructorArgumentWithSingleQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -189,7 +189,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldWithMultipleNonQualifiedCandidates() { void testAutowiredFieldWithMultipleNonQualifiedCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -211,7 +211,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredMethodParameterWithMultipleNonQualifiedCandidates() { void testAutowiredMethodParameterWithMultipleNonQualifiedCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -233,7 +233,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredConstructorArgumentWithMultipleNonQualifiedCandidates() { void testAutowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -252,7 +252,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldResolvesQualifiedCandidate() { void testAutowiredFieldResolvesQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -272,7 +272,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredMethodParameterResolvesQualifiedCandidate() { void testAutowiredMethodParameterResolvesQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -293,7 +293,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredConstructorArgumentResolvesQualifiedCandidate() { void testAutowiredConstructorArgumentResolvesQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -314,7 +314,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() { void testAutowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -336,7 +336,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() { void testAutowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -360,7 +360,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() { void testAutowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -382,7 +382,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldResolvesWithMultipleQualifierValues() { void testAutowiredFieldResolvesWithMultipleQualifierValues() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -408,7 +408,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() { void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -437,7 +437,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() { void testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -464,7 +464,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() { void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -493,7 +493,7 @@ public class InjectAnnotationAutowireContextTests {
} }
@Test @Test
public void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() { void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue("the real juergen"); cavs1.addGenericArgumentValue("the real juergen");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Chris Beams * @author Chris Beams
* @author Sam Brannen * @author Sam Brannen
*/ */
public class QualifierAnnotationAutowireContextTests { class QualifierAnnotationAutowireContextTests {
private static final String JUERGEN = "juergen"; private static final String JUERGEN = "juergen";
@ -53,7 +53,7 @@ public class QualifierAnnotationAutowireContextTests {
@Test @Test
public void autowiredFieldWithSingleNonQualifiedCandidate() { void autowiredFieldWithSingleNonQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -72,7 +72,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredMethodParameterWithSingleNonQualifiedCandidate() { void autowiredMethodParameterWithSingleNonQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -91,7 +91,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredConstructorArgumentWithSingleNonQualifiedCandidate() { void autowiredConstructorArgumentWithSingleNonQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -106,7 +106,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldWithSingleQualifiedCandidate() { void autowiredFieldWithSingleQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -121,7 +121,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredMethodParameterWithSingleQualifiedCandidate() { void autowiredMethodParameterWithSingleQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -138,7 +138,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredMethodParameterWithStaticallyQualifiedCandidate() { void autowiredMethodParameterWithStaticallyQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -155,7 +155,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredMethodParameterWithStaticallyQualifiedCandidateAmongOthers() { void autowiredMethodParameterWithStaticallyQualifiedCandidateAmongOthers() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -175,7 +175,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredConstructorArgumentWithSingleQualifiedCandidate() { void autowiredConstructorArgumentWithSingleQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs = new ConstructorArgumentValues(); ConstructorArgumentValues cavs = new ConstructorArgumentValues();
cavs.addGenericArgumentValue(JUERGEN); cavs.addGenericArgumentValue(JUERGEN);
@ -192,7 +192,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldWithMultipleNonQualifiedCandidates() { void autowiredFieldWithMultipleNonQualifiedCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -214,7 +214,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredMethodParameterWithMultipleNonQualifiedCandidates() { void autowiredMethodParameterWithMultipleNonQualifiedCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -236,7 +236,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredConstructorArgumentWithMultipleNonQualifiedCandidates() { void autowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -255,7 +255,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesQualifiedCandidate() { void autowiredFieldResolvesQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -275,7 +275,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesMetaQualifiedCandidate() { void autowiredFieldResolvesMetaQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -295,7 +295,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredMethodParameterResolvesQualifiedCandidate() { void autowiredMethodParameterResolvesQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -316,7 +316,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredConstructorArgumentResolvesQualifiedCandidate() { void autowiredConstructorArgumentResolvesQualifiedCandidate() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -337,7 +337,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() { void autowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -359,7 +359,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() { void autowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -383,7 +383,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() { void autowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -405,7 +405,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesWithMultipleQualifierValues() { void autowiredFieldResolvesWithMultipleQualifierValues() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -431,7 +431,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() { void autowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -460,7 +460,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() { void autowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -487,7 +487,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() { void autowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -516,7 +516,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesWithBaseQualifierAndDefaultValue() { void autowiredFieldResolvesWithBaseQualifierAndDefaultValue() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue(JUERGEN); cavs1.addGenericArgumentValue(JUERGEN);
@ -537,7 +537,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldResolvesWithBaseQualifierAndNonDefaultValue() { void autowiredFieldResolvesWithBaseQualifierAndNonDefaultValue() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue("the real juergen"); cavs1.addGenericArgumentValue("the real juergen");
@ -559,7 +559,7 @@ public class QualifierAnnotationAutowireContextTests {
} }
@Test @Test
public void autowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() { void autowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
cavs1.addGenericArgumentValue("the real juergen"); cavs1.addGenericArgumentValue("the real juergen");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class LookupMethodWrappedByCglibProxyTests { class LookupMethodWrappedByCglibProxyTests {
private static final Class<?> CLASS = LookupMethodWrappedByCglibProxyTests.class; private static final Class<?> CLASS = LookupMethodWrappedByCglibProxyTests.class;
private static final String CLASSNAME = CLASS.getSimpleName(); private static final String CLASSNAME = CLASS.getSimpleName();
@ -43,13 +43,13 @@ public class LookupMethodWrappedByCglibProxyTests {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
this.applicationContext = new ClassPathXmlApplicationContext(CONTEXT, CLASS); this.applicationContext = new ClassPathXmlApplicationContext(CONTEXT, CLASS);
resetInterceptor(); resetInterceptor();
} }
@Test @Test
public void testAutoProxiedLookup() { void testAutoProxiedLookup() {
OverloadLookup olup = (OverloadLookup) applicationContext.getBean("autoProxiedOverload"); OverloadLookup olup = (OverloadLookup) applicationContext.getBean("autoProxiedOverload");
ITestBean jenny = olup.newTestBean(); ITestBean jenny = olup.newTestBean();
assertThat(jenny.getName()).isEqualTo("Jenny"); assertThat(jenny.getName()).isEqualTo("Jenny");
@ -58,7 +58,7 @@ public class LookupMethodWrappedByCglibProxyTests {
} }
@Test @Test
public void testRegularlyProxiedLookup() { void testRegularlyProxiedLookup() {
OverloadLookup olup = (OverloadLookup) applicationContext.getBean("regularlyProxiedOverload"); OverloadLookup olup = (OverloadLookup) applicationContext.getBean("regularlyProxiedOverload");
ITestBean jenny = olup.newTestBean(); ITestBean jenny = olup.newTestBean();
assertThat(jenny.getName()).isEqualTo("Jenny"); assertThat(jenny.getName()).isEqualTo("Jenny");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ import static org.springframework.util.ClassUtils.convertClassNameToResourcePath
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class QualifierAnnotationTests { class QualifierAnnotationTests {
private static final String CLASSNAME = QualifierAnnotationTests.class.getName(); private static final String CLASSNAME = QualifierAnnotationTests.class.getName();
@ -53,7 +53,7 @@ public class QualifierAnnotationTests {
@Test @Test
public void testNonQualifiedFieldFails() { void testNonQualifiedFieldFails() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -64,7 +64,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByValue() { void testQualifiedByValue() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -76,7 +76,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByParentValue() { void testQualifiedByParentValue() {
StaticApplicationContext parent = new StaticApplicationContext(); StaticApplicationContext parent = new StaticApplicationContext();
GenericBeanDefinition parentLarry = new GenericBeanDefinition(); GenericBeanDefinition parentLarry = new GenericBeanDefinition();
parentLarry.setBeanClass(Person.class); parentLarry.setBeanClass(Person.class);
@ -101,7 +101,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByBeanName() { void testQualifiedByBeanName() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -115,7 +115,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByFieldName() { void testQualifiedByFieldName() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -127,7 +127,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByParameterName() { void testQualifiedByParameterName() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -139,7 +139,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByAlias() { void testQualifiedByAlias() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -151,7 +151,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByAnnotation() { void testQualifiedByAnnotation() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -163,7 +163,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByCustomValue() { void testQualifiedByCustomValue() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -175,7 +175,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByAnnotationValue() { void testQualifiedByAnnotationValue() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -187,7 +187,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByAttributesFailsWithoutCustomQualifierRegistered() { void testQualifiedByAttributesFailsWithoutCustomQualifierRegistered() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -198,7 +198,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() { void testQualifiedByAttributesWithCustomQualifierRegistered() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);
@ -215,7 +215,7 @@ public class QualifierAnnotationTests {
} }
@Test @Test
public void testInterfaceWithOneQualifiedFactoryAndOneQualifiedBean() { void testInterfaceWithOneQualifiedFactoryAndOneQualifiedBean() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION); reader.loadBeanDefinitions(CONFIG_LOCATION);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -313,7 +313,7 @@ class FixedMethodReplacer implements MethodReplacer {
public static final String VALUE = "fixedMethodReplacer"; public static final String VALUE = "fixedMethodReplacer";
@Override @Override
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable { public Object reimplement(Object obj, Method method, Object[] args) {
return VALUE; return VALUE;
} }
} }
@ -587,7 +587,7 @@ class ProtectedLifecycleBean implements BeanNameAware, BeanFactoryAware, Initial
class ReverseMethodReplacer implements MethodReplacer, Serializable { class ReverseMethodReplacer implements MethodReplacer, Serializable {
@Override @Override
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable { public Object reimplement(Object obj, Method method, Object[] args) {
String s = (String) args[0]; String s = (String) args[0];
return new StringBuilder(s).reverse().toString(); return new StringBuilder(s).reverse().toString();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -1611,7 +1611,7 @@ class XmlBeanFactoryTests {
public Object lastArg; public Object lastArg;
@Override @Override
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable { public Object reimplement(Object obj, Method method, Object[] args) {
assertThat(args).hasSize(1); assertThat(args).hasSize(1);
assertThat(method.getName()).isEqualTo("doSomething"); assertThat(method.getName()).isEqualTo("doSomething");
lastArg = args[0]; lastArg = args[0];
@ -1668,7 +1668,7 @@ class XmlBeanFactoryTests {
} }
/** Init method */ /** Init method */
public void customInit() throws IOException { public void customInit() {
assertThat(this.afterPropertiesSetInvoked).isTrue(); assertThat(this.afterPropertiesSetInvoked).isTrue();
if (this.initMethodInvoked) { if (this.initMethodInvoked) {
throw new IllegalStateException("Already customInitialized"); throw new IllegalStateException("Already customInitialized");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -71,7 +71,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Chris Beams * @author Chris Beams
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class CustomNamespaceHandlerTests { class CustomNamespaceHandlerTests {
private static final Class<?> CLASS = CustomNamespaceHandlerTests.class; private static final Class<?> CLASS = CustomNamespaceHandlerTests.class;
private static final String CLASSNAME = CLASS.getSimpleName(); private static final String CLASSNAME = CLASS.getSimpleName();
@ -85,7 +85,7 @@ public class CustomNamespaceHandlerTests {
@BeforeEach @BeforeEach
public void setUp() throws Exception { void setUp() {
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS); NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
this.beanFactory = new GenericApplicationContext(); this.beanFactory = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
@ -98,19 +98,19 @@ public class CustomNamespaceHandlerTests {
@Test @Test
public void testSimpleParser() throws Exception { void testSimpleParser() {
TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); TestBean bean = (TestBean) this.beanFactory.getBean("testBean");
assertTestBean(bean); assertTestBean(bean);
} }
@Test @Test
public void testSimpleDecorator() throws Exception { void testSimpleDecorator() {
TestBean bean = (TestBean) this.beanFactory.getBean("customisedTestBean"); TestBean bean = (TestBean) this.beanFactory.getBean("customisedTestBean");
assertTestBean(bean); assertTestBean(bean);
} }
@Test @Test
public void testProxyingDecorator() throws Exception { void testProxyingDecorator() {
ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean"); ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
assertTestBean(bean); assertTestBean(bean);
assertThat(AopUtils.isAopProxy(bean)).isTrue(); assertThat(AopUtils.isAopProxy(bean)).isTrue();
@ -120,7 +120,7 @@ public class CustomNamespaceHandlerTests {
} }
@Test @Test
public void testProxyingDecoratorNoInstance() throws Exception { void testProxyingDecoratorNoInstance() {
String[] beanNames = this.beanFactory.getBeanNamesForType(ApplicationListener.class); String[] beanNames = this.beanFactory.getBeanNamesForType(ApplicationListener.class);
assertThat(Arrays.asList(beanNames)).contains("debuggingTestBeanNoInstance"); assertThat(Arrays.asList(beanNames)).contains("debuggingTestBeanNoInstance");
assertThat(this.beanFactory.getType("debuggingTestBeanNoInstance")).isEqualTo(ApplicationListener.class); assertThat(this.beanFactory.getType("debuggingTestBeanNoInstance")).isEqualTo(ApplicationListener.class);
@ -131,7 +131,7 @@ public class CustomNamespaceHandlerTests {
} }
@Test @Test
public void testChainedDecorators() throws Exception { void testChainedDecorators() {
ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean"); ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
assertTestBean(bean); assertTestBean(bean);
assertThat(AopUtils.isAopProxy(bean)).isTrue(); assertThat(AopUtils.isAopProxy(bean)).isTrue();
@ -142,27 +142,27 @@ public class CustomNamespaceHandlerTests {
} }
@Test @Test
public void testDecorationViaAttribute() throws Exception { void testDecorationViaAttribute() {
BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition("decorateWithAttribute"); BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition("decorateWithAttribute");
assertThat(beanDefinition.getAttribute("objectName")).isEqualTo("foo"); assertThat(beanDefinition.getAttribute("objectName")).isEqualTo("foo");
} }
@Test // SPR-2728 @Test // SPR-2728
public void testCustomElementNestedWithinUtilList() throws Exception { public void testCustomElementNestedWithinUtilList() {
List<?> things = (List<?>) this.beanFactory.getBean("list.of.things"); List<?> things = (List<?>) this.beanFactory.getBean("list.of.things");
assertThat(things).isNotNull(); assertThat(things).isNotNull();
assertThat(things).hasSize(2); assertThat(things).hasSize(2);
} }
@Test // SPR-2728 @Test // SPR-2728
public void testCustomElementNestedWithinUtilSet() throws Exception { public void testCustomElementNestedWithinUtilSet() {
Set<?> things = (Set<?>) this.beanFactory.getBean("set.of.things"); Set<?> things = (Set<?>) this.beanFactory.getBean("set.of.things");
assertThat(things).isNotNull(); assertThat(things).isNotNull();
assertThat(things).hasSize(2); assertThat(things).hasSize(2);
} }
@Test // SPR-2728 @Test // SPR-2728
public void testCustomElementNestedWithinUtilMap() throws Exception { public void testCustomElementNestedWithinUtilMap() {
Map<?, ?> things = (Map<?, ?>) this.beanFactory.getBean("map.of.things"); Map<?, ?> things = (Map<?, ?>) this.beanFactory.getBean("map.of.things");
assertThat(things).isNotNull(); assertThat(things).isNotNull();
assertThat(things).hasSize(2); assertThat(things).hasSize(2);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,19 +30,19 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Costin Leau * @author Costin Leau
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class NoOpCacheManagerTests { class NoOpCacheManagerTests {
private final CacheManager manager = new NoOpCacheManager(); private final CacheManager manager = new NoOpCacheManager();
@Test @Test
public void testGetCache() throws Exception { void testGetCache() {
Cache cache = this.manager.getCache("bucket"); Cache cache = this.manager.getCache("bucket");
assertThat(cache).isNotNull(); assertThat(cache).isNotNull();
assertThat(this.manager.getCache("bucket")).isSameAs(cache); assertThat(this.manager.getCache("bucket")).isSameAs(cache);
} }
@Test @Test
public void testNoOpCache() throws Exception { void testNoOpCache() {
String name = createRandomKey(); String name = createRandomKey();
Cache cache = this.manager.getCache(name); Cache cache = this.manager.getCache(name);
assertThat(cache.getName()).isEqualTo(name); assertThat(cache.getName()).isEqualTo(name);
@ -54,7 +54,7 @@ public class NoOpCacheManagerTests {
} }
@Test @Test
public void testCacheName() throws Exception { void testCacheName() {
String name = "bucket"; String name = "bucket";
assertThat(this.manager.getCacheNames()).doesNotContain(name); assertThat(this.manager.getCacheNames()).doesNotContain(name);
this.manager.getCache(name); this.manager.getCache(name);
@ -62,7 +62,7 @@ public class NoOpCacheManagerTests {
} }
@Test @Test
public void testCacheCallable() throws Exception { void testCacheCallable() {
String name = createRandomKey(); String name = createRandomKey();
Cache cache = this.manager.getCache(name); Cache cache = this.manager.getCache(name);
Object returnValue = new Object(); Object returnValue = new Object();
@ -71,7 +71,7 @@ public class NoOpCacheManagerTests {
} }
@Test @Test
public void testCacheGetCallableFail() { void testCacheGetCallableFail() {
Cache cache = this.manager.getCache(createRandomKey()); Cache cache = this.manager.getCache(createRandomKey());
String key = createRandomKey(); String key = createRandomKey();
try { try {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,19 +41,19 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Sam Brannen * @author Sam Brannen
*/ */
public class AnnotationCacheOperationSourceTests { class AnnotationCacheOperationSourceTests {
private final AnnotationCacheOperationSource source = new AnnotationCacheOperationSource(); private final AnnotationCacheOperationSource source = new AnnotationCacheOperationSource();
@Test @Test
public void singularAnnotation() { void singularAnnotation() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
assertThat(ops).element(0).isInstanceOf(CacheableOperation.class); assertThat(ops).element(0).isInstanceOf(CacheableOperation.class);
} }
@Test @Test
public void multipleAnnotation() { void multipleAnnotation() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2);
Iterator<CacheOperation> it = ops.iterator(); Iterator<CacheOperation> it = ops.iterator();
assertThat(it.next()).isInstanceOf(CacheableOperation.class); assertThat(it.next()).isInstanceOf(CacheableOperation.class);
@ -61,7 +61,7 @@ public class AnnotationCacheOperationSourceTests {
} }
@Test @Test
public void caching() { void caching() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2);
Iterator<CacheOperation> it = ops.iterator(); Iterator<CacheOperation> it = ops.iterator();
assertThat(it.next()).isInstanceOf(CacheableOperation.class); assertThat(it.next()).isInstanceOf(CacheableOperation.class);
@ -69,18 +69,18 @@ public class AnnotationCacheOperationSourceTests {
} }
@Test @Test
public void emptyCaching() { void emptyCaching() {
getOps(AnnotatedClass.class, "emptyCaching", 0); getOps(AnnotatedClass.class, "emptyCaching", 0);
} }
@Test @Test
public void singularStereotype() { void singularStereotype() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleStereotype", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleStereotype", 1);
assertThat(ops).element(0).isInstanceOf(CacheEvictOperation.class); assertThat(ops).element(0).isInstanceOf(CacheEvictOperation.class);
} }
@Test @Test
public void multipleStereotypes() { void multipleStereotypes() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleStereotype", 3); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleStereotype", 3);
Iterator<CacheOperation> it = ops.iterator(); Iterator<CacheOperation> it = ops.iterator();
assertThat(it.next()).isInstanceOf(CacheableOperation.class); assertThat(it.next()).isInstanceOf(CacheableOperation.class);
@ -93,7 +93,7 @@ public class AnnotationCacheOperationSourceTests {
} }
@Test @Test
public void singleComposedAnnotation() { void singleComposedAnnotation() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2);
Iterator<CacheOperation> it = ops.iterator(); Iterator<CacheOperation> it = ops.iterator();
@ -109,7 +109,7 @@ public class AnnotationCacheOperationSourceTests {
} }
@Test @Test
public void multipleComposedAnnotations() { void multipleComposedAnnotations() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4);
Iterator<CacheOperation> it = ops.iterator(); Iterator<CacheOperation> it = ops.iterator();
@ -135,89 +135,89 @@ public class AnnotationCacheOperationSourceTests {
} }
@Test @Test
public void customKeyGenerator() { void customKeyGenerator() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom"); assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom");
} }
@Test @Test
public void customKeyGeneratorInherited() { void customKeyGeneratorInherited() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGeneratorInherited", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGeneratorInherited", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom"); assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom");
} }
@Test @Test
public void keyAndKeyGeneratorCannotBeSetTogether() { void keyAndKeyGeneratorCannotBeSetTogether() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
getOps(AnnotatedClass.class, "invalidKeyAndKeyGeneratorSet")); getOps(AnnotatedClass.class, "invalidKeyAndKeyGeneratorSet"));
} }
@Test @Test
public void customCacheManager() { void customCacheManager() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManager", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManager", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom"); assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom");
} }
@Test @Test
public void customCacheManagerInherited() { void customCacheManagerInherited() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManagerInherited", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManagerInherited", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom"); assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom");
} }
@Test @Test
public void customCacheResolver() { void customCacheResolver() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolver", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolver", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom"); assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom");
} }
@Test @Test
public void customCacheResolverInherited() { void customCacheResolverInherited() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolverInherited", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolverInherited", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom"); assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom");
} }
@Test @Test
public void cacheResolverAndCacheManagerCannotBeSetTogether() { void cacheResolverAndCacheManagerCannotBeSetTogether() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
getOps(AnnotatedClass.class, "invalidCacheResolverAndCacheManagerSet")); getOps(AnnotatedClass.class, "invalidCacheResolverAndCacheManagerSet"));
} }
@Test @Test
public void fullClassLevelWithCustomCacheName() { void fullClassLevelWithCustomCacheName() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheName", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheName", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "classCacheResolver", "custom"); assertSharedConfig(cacheOperation, "classKeyGenerator", "", "classCacheResolver", "custom");
} }
@Test @Test
public void fullClassLevelWithCustomKeyManager() { void fullClassLevelWithCustomKeyManager() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelKeyGenerator", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelKeyGenerator", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "custom", "", "classCacheResolver" , "classCacheName"); assertSharedConfig(cacheOperation, "custom", "", "classCacheResolver" , "classCacheName");
} }
@Test @Test
public void fullClassLevelWithCustomCacheManager() { void fullClassLevelWithCustomCacheManager() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheManager", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheManager", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "classKeyGenerator", "custom", "", "classCacheName"); assertSharedConfig(cacheOperation, "classKeyGenerator", "custom", "", "classCacheName");
} }
@Test @Test
public void fullClassLevelWithCustomCacheResolver() { void fullClassLevelWithCustomCacheResolver() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheResolver", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheResolver", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "custom" , "classCacheName"); assertSharedConfig(cacheOperation, "classKeyGenerator", "", "custom" , "classCacheName");
} }
@Test @Test
public void validateNoCacheIsValid() { void validateNoCacheIsValid() {
// Valid as a CacheResolver might return the cache names to use with other info // Valid as a CacheResolver might return the cache names to use with other info
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "noCacheNameSpecified"); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "noCacheNameSpecified");
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
@ -226,28 +226,28 @@ public class AnnotationCacheOperationSourceTests {
} }
@Test @Test
public void customClassLevelWithCustomCacheName() { void customClassLevelWithCustomCacheName() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithCustomDefault.class, "methodLevelCacheName", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithCustomDefault.class, "methodLevelCacheName", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "classCacheResolver", "custom"); assertSharedConfig(cacheOperation, "classKeyGenerator", "", "classCacheResolver", "custom");
} }
@Test @Test
public void severalCacheConfigUseClosest() { void severalCacheConfigUseClosest() {
Collection<CacheOperation> ops = getOps(MultipleCacheConfig.class, "multipleCacheConfig"); Collection<CacheOperation> ops = getOps(MultipleCacheConfig.class, "multipleCacheConfig");
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "", "", "", "myCache"); assertSharedConfig(cacheOperation, "", "", "", "myCache");
} }
@Test @Test
public void cacheConfigFromInterface() { void cacheConfigFromInterface() {
Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheConfig"); Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheConfig");
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "", "", "", "myCache"); assertSharedConfig(cacheOperation, "", "", "", "myCache");
} }
@Test @Test
public void cacheAnnotationOverride() { void cacheAnnotationOverride() {
Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheableOverride"); Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheableOverride");
assertThat(ops.size()).isSameAs(1); assertThat(ops.size()).isSameAs(1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
@ -255,21 +255,21 @@ public class AnnotationCacheOperationSourceTests {
} }
@Test @Test
public void partialClassLevelWithCustomCacheManager() { void partialClassLevelWithCustomCacheManager() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "methodLevelCacheManager", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "methodLevelCacheManager", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "classKeyGenerator", "custom", "", "classCacheName"); assertSharedConfig(cacheOperation, "classKeyGenerator", "custom", "", "classCacheName");
} }
@Test @Test
public void partialClassLevelWithCustomCacheResolver() { void partialClassLevelWithCustomCacheResolver() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "methodLevelCacheResolver", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "methodLevelCacheResolver", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "custom", "classCacheName"); assertSharedConfig(cacheOperation, "classKeyGenerator", "", "custom", "classCacheName");
} }
@Test @Test
public void partialClassLevelWithNoCustomization() { void partialClassLevelWithNoCustomization() {
Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "noCustomization", 1); Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "noCustomization", 1);
CacheOperation cacheOperation = ops.iterator().next(); CacheOperation cacheOperation = ops.iterator().next();
assertSharedConfig(cacheOperation, "classKeyGenerator", "classCacheManager", "", "classCacheName"); assertSharedConfig(cacheOperation, "classKeyGenerator", "classCacheManager", "", "classCacheName");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,10 +27,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class ConcurrentMapCacheManagerTests { class ConcurrentMapCacheManagerTests {
@Test @Test
public void testDynamicMode() { void testDynamicMode() {
CacheManager cm = new ConcurrentMapCacheManager(); CacheManager cm = new ConcurrentMapCacheManager();
Cache cache1 = cm.getCache("c1"); Cache cache1 = cm.getCache("c1");
assertThat(cache1).isInstanceOf(ConcurrentMapCache.class); assertThat(cache1).isInstanceOf(ConcurrentMapCache.class);
@ -68,7 +68,7 @@ public class ConcurrentMapCacheManagerTests {
} }
@Test @Test
public void testStaticMode() { void testStaticMode() {
ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2"); ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
Cache cache1 = cm.getCache("c1"); Cache cache1 = cm.getCache("c1");
assertThat(cache1).isInstanceOf(ConcurrentMapCache.class); assertThat(cache1).isInstanceOf(ConcurrentMapCache.class);
@ -115,7 +115,7 @@ public class ConcurrentMapCacheManagerTests {
} }
@Test @Test
public void testChangeStoreByValue() { void testChangeStoreByValue() {
ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2"); ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
assertThat(cm.isStoreByValue()).isFalse(); assertThat(cm.isStoreByValue()).isFalse();
Cache cache1 = cm.getCache("c1"); Cache cache1 = cm.getCache("c1");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests<ConcurrentMapCache> { class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests<ConcurrentMapCache> {
protected ConcurrentMap<Object, Object> nativeCache; protected ConcurrentMap<Object, Object> nativeCache;
@ -48,7 +48,7 @@ public class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests<Con
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.nativeCache = new ConcurrentHashMap<>(); this.nativeCache = new ConcurrentHashMap<>();
this.cache = new ConcurrentMapCache(CACHE_NAME, this.nativeCache, true); this.cache = new ConcurrentMapCache(CACHE_NAME, this.nativeCache, true);
this.nativeCacheNoNull = new ConcurrentHashMap<>(); this.nativeCacheNoNull = new ConcurrentHashMap<>();
@ -73,13 +73,13 @@ public class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests<Con
@Test @Test
public void testIsStoreByReferenceByDefault() { void testIsStoreByReferenceByDefault() {
assertThat(this.cache.isStoreByValue()).isFalse(); assertThat(this.cache.isStoreByValue()).isFalse();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testSerializer() { void testSerializer() {
ConcurrentMapCache serializeCache = createCacheWithStoreByValue(); ConcurrentMapCache serializeCache = createCacheWithStoreByValue();
assertThat(serializeCache.isStoreByValue()).isTrue(); assertThat(serializeCache.isStoreByValue()).isTrue();
@ -89,11 +89,11 @@ public class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests<Con
content.remove(0); content.remove(0);
List<String> entry = (List<String>) serializeCache.get(key).get(); List<String> entry = (List<String>) serializeCache.get(key).get();
assertThat(entry).hasSize(3); assertThat(entry).hasSize(3);
assertThat(entry).element(0).isEqualTo("one"); assertThat(entry.get(0)).isEqualTo("one");
} }
@Test @Test
public void testNonSerializableContent() { void testNonSerializableContent() {
ConcurrentMapCache serializeCache = createCacheWithStoreByValue(); ConcurrentMapCache serializeCache = createCacheWithStoreByValue();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
@ -104,7 +104,7 @@ public class ConcurrentMapCacheTests extends AbstractValueAdaptingCacheTests<Con
} }
@Test @Test
public void testInvalidSerializedContent() { void testInvalidSerializedContent() {
ConcurrentMapCache serializeCache = createCacheWithStoreByValue(); ConcurrentMapCache serializeCache = createCacheWithStoreByValue();
String key = createRandomKey(); String key = createRandomKey();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ import org.springframework.context.testfixture.cache.AbstractCacheAnnotationTest
* @author Costin Leau * @author Costin Leau
* @author Chris Beams * @author Chris Beams
*/ */
public class AnnotationDrivenCacheConfigTests extends AbstractCacheAnnotationTests { class AnnotationDrivenCacheConfigTests extends AbstractCacheAnnotationTests {
@Override @Override
protected ConfigurableApplicationContext getApplicationContext() { protected ConfigurableApplicationContext getApplicationContext() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests { class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests {
@Override @Override
protected ConfigurableApplicationContext getApplicationContext() { protected ConfigurableApplicationContext getApplicationContext() {
@ -40,14 +40,14 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
} }
@Test @Test
public void testKeyStrategy() { void testKeyStrategy() {
CacheInterceptor ci = this.ctx.getBean( CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertThat(ci.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator")); assertThat(ci.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator"));
} }
@Test @Test
public void cacheResolver() { void cacheResolver() {
ConfigurableApplicationContext context = new GenericXmlApplicationContext( ConfigurableApplicationContext context = new GenericXmlApplicationContext(
"/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml"); "/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml");
@ -57,7 +57,7 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
} }
@Test @Test
public void bothSetOnlyResolverIsUsed() { void bothSetOnlyResolverIsUsed() {
ConfigurableApplicationContext context = new GenericXmlApplicationContext( ConfigurableApplicationContext context = new GenericXmlApplicationContext(
"/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml"); "/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml");
@ -67,7 +67,7 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
} }
@Test @Test
public void testCacheErrorHandler() { void testCacheErrorHandler() {
CacheInterceptor ci = this.ctx.getBean( CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertThat(ci.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class)); assertThat(ci.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Costin Leau * @author Costin Leau
* @author Chris Beams * @author Chris Beams
*/ */
public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests { class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests {
@Override @Override
protected ConfigurableApplicationContext getApplicationContext() { protected ConfigurableApplicationContext getApplicationContext() {
@ -38,7 +38,7 @@ public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests {
} }
@Test @Test
public void testKeyStrategy() { void testKeyStrategy() {
CacheInterceptor bean = this.ctx.getBean("cacheAdviceClass", CacheInterceptor.class); CacheInterceptor bean = this.ctx.getBean("cacheAdviceClass", CacheInterceptor.class);
assertThat(bean.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator")); assertThat(bean.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator"));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,13 +49,13 @@ class CustomInterceptorTests {
protected CacheableService<?> cs; protected CacheableService<?> cs;
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.ctx = new AnnotationConfigApplicationContext(EnableCachingConfig.class); this.ctx = new AnnotationConfigApplicationContext(EnableCachingConfig.class);
this.cs = ctx.getBean("service", CacheableService.class); this.cs = ctx.getBean("service", CacheableService.class);
} }
@AfterEach @AfterEach
public void tearDown() { void tearDown() {
this.ctx.close(); this.ctx.close();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration;
/** /**
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class ExpressionCachingIntegrationTests { class ExpressionCachingIntegrationTests {
@Test // SPR-11692 @Test // SPR-11692
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author John Blum * @author John Blum
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class CacheProxyFactoryBeanTests { class CacheProxyFactoryBeanTests {
@Test @Test
public void configurationClassWithCacheProxyFactoryBean() { void configurationClassWithCacheProxyFactoryBean() {
try (AnnotationConfigApplicationContext applicationContext = try (AnnotationConfigApplicationContext applicationContext =
new AnnotationConfigApplicationContext(CacheProxyFactoryBeanConfiguration.class)) { new AnnotationConfigApplicationContext(CacheProxyFactoryBeanConfiguration.class)) {
Greeter greeter = applicationContext.getBean("greeter", Greeter.class); Greeter greeter = applicationContext.getBean("greeter", Greeter.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class CachePutEvaluationTests { class CachePutEvaluationTests {
private ConfigurableApplicationContext context; private ConfigurableApplicationContext context;
@ -53,20 +53,20 @@ public class CachePutEvaluationTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.context = new AnnotationConfigApplicationContext(Config.class); this.context = new AnnotationConfigApplicationContext(Config.class);
this.cache = this.context.getBean(CacheManager.class).getCache("test"); this.cache = this.context.getBean(CacheManager.class).getCache("test");
this.service = this.context.getBean(SimpleService.class); this.service = this.context.getBean(SimpleService.class);
} }
@AfterEach @AfterEach
public void closeContext() { void closeContext() {
this.context.close(); this.context.close();
} }
@Test @Test
public void mutualGetPutExclusion() { void mutualGetPutExclusion() {
String key = "1"; String key = "1";
Long first = this.service.getOrPut(key, true); Long first = this.service.getOrPut(key, true);
@ -83,7 +83,7 @@ public class CachePutEvaluationTests {
} }
@Test @Test
public void getAndPut() { void getAndPut() {
this.cache.clear(); this.cache.clear();
long key = 1; long key = 1;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 4.3 * @since 4.3
*/ */
public class CacheSyncFailureTests { class CacheSyncFailureTests {
private ConfigurableApplicationContext context; private ConfigurableApplicationContext context;
@ -50,13 +50,13 @@ public class CacheSyncFailureTests {
@BeforeEach @BeforeEach
public void setup() { void setup() {
this.context = new AnnotationConfigApplicationContext(Config.class); this.context = new AnnotationConfigApplicationContext(Config.class);
this.simpleService = this.context.getBean(SimpleService.class); this.simpleService = this.context.getBean(SimpleService.class);
} }
@AfterEach @AfterEach
public void closeContext() { void closeContext() {
if (this.context != null) { if (this.context != null) {
this.context.close(); this.context.close();
} }
@ -64,35 +64,35 @@ public class CacheSyncFailureTests {
@Test @Test
public void unlessSync() { void unlessSync() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> this.simpleService.unlessSync("key")) .isThrownBy(() -> this.simpleService.unlessSync("key"))
.withMessageContaining("A sync=true operation does not support the unless attribute"); .withMessageContaining("A sync=true operation does not support the unless attribute");
} }
@Test @Test
public void severalCachesSync() { void severalCachesSync() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> this.simpleService.severalCachesSync("key")) .isThrownBy(() -> this.simpleService.severalCachesSync("key"))
.withMessageContaining("A sync=true operation is restricted to a single cache"); .withMessageContaining("A sync=true operation is restricted to a single cache");
} }
@Test @Test
public void severalCachesWithResolvedSync() { void severalCachesWithResolvedSync() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> this.simpleService.severalCachesWithResolvedSync("key")) .isThrownBy(() -> this.simpleService.severalCachesWithResolvedSync("key"))
.withMessageContaining("A sync=true operation is restricted to a single cache"); .withMessageContaining("A sync=true operation is restricted to a single cache");
} }
@Test @Test
public void syncWithAnotherOperation() { void syncWithAnotherOperation() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> this.simpleService.syncWithAnotherOperation("key")) .isThrownBy(() -> this.simpleService.syncWithAnotherOperation("key"))
.withMessageContaining("A sync=true operation cannot be combined with other cache operations"); .withMessageContaining("A sync=true operation cannot be combined with other cache operations");
} }
@Test @Test
public void syncWithTwoGetOperations() { void syncWithTwoGetOperations() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> this.simpleService.syncWithTwoGetOperations("key")) .isThrownBy(() -> this.simpleService.syncWithTwoGetOperations("key"))
.withMessageContaining("Only one sync=true operation is allowed"); .withMessageContaining("Only one sync=true operation is allowed");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Sam Brannen * @author Sam Brannen
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class ExpressionEvaluatorTests { class ExpressionEvaluatorTests {
private final StandardEvaluationContext originalEvaluationContext = new StandardEvaluationContext(); private final StandardEvaluationContext originalEvaluationContext = new StandardEvaluationContext();
@ -65,7 +65,7 @@ public class ExpressionEvaluatorTests {
@Test @Test
public void testMultipleCachingSource() { void testMultipleCachingSource() {
Collection<CacheOperation> ops = getOps("multipleCaching"); Collection<CacheOperation> ops = getOps("multipleCaching");
assertThat(ops).hasSize(2); assertThat(ops).hasSize(2);
Iterator<CacheOperation> it = ops.iterator(); Iterator<CacheOperation> it = ops.iterator();
@ -80,7 +80,7 @@ public class ExpressionEvaluatorTests {
} }
@Test @Test
public void testMultipleCachingEval() { void testMultipleCachingEval() {
AnnotatedClass target = new AnnotatedClass(); AnnotatedClass target = new AnnotatedClass();
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
AnnotatedClass.class, "multipleCaching", Object.class, Object.class); AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
@ -102,28 +102,28 @@ public class ExpressionEvaluatorTests {
} }
@Test @Test
public void withReturnValue() { void withReturnValue() {
EvaluationContext context = createEvaluationContext("theResult"); EvaluationContext context = createEvaluationContext("theResult");
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context); Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value).isEqualTo("theResult"); assertThat(value).isEqualTo("theResult");
} }
@Test @Test
public void withNullReturn() { void withNullReturn() {
EvaluationContext context = createEvaluationContext(null); EvaluationContext context = createEvaluationContext(null);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context); Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value).isNull(); assertThat(value).isNull();
} }
@Test @Test
public void withoutReturnValue() { void withoutReturnValue() {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT); EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context); Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value).isNull(); assertThat(value).isNull();
} }
@Test @Test
public void unavailableReturnValue() { void unavailableReturnValue() {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.RESULT_UNAVAILABLE); EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.RESULT_UNAVAILABLE);
assertThatExceptionOfType(VariableNotAvailableException.class).isThrownBy(() -> assertThatExceptionOfType(VariableNotAvailableException.class).isThrownBy(() ->
new SpelExpressionParser().parseExpression("#result").getValue(context)) new SpelExpressionParser().parseExpression("#result").getValue(context))
@ -131,7 +131,7 @@ public class ExpressionEvaluatorTests {
} }
@Test @Test
public void resolveBeanReference() { void resolveBeanReference() {
StaticApplicationContext applicationContext = new StaticApplicationContext(); StaticApplicationContext applicationContext = new StaticApplicationContext();
BeanDefinition beanDefinition = new RootBeanDefinition(String.class); BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
applicationContext.registerBeanDefinition("myBean", beanDefinition); applicationContext.registerBeanDefinition("myBean", beanDefinition);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,13 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class SimpleKeyGeneratorTests { class SimpleKeyGeneratorTests {
private final SimpleKeyGenerator generator = new SimpleKeyGenerator(); private final SimpleKeyGenerator generator = new SimpleKeyGenerator();
@Test @Test
public void noValues() { void noValues() {
Object k1 = generateKey(new Object[] {}); Object k1 = generateKey(new Object[] {});
Object k2 = generateKey(new Object[] {}); Object k2 = generateKey(new Object[] {});
Object k3 = generateKey(new Object[] { "different" }); Object k3 = generateKey(new Object[] { "different" });
@ -50,7 +50,7 @@ public class SimpleKeyGeneratorTests {
} }
@Test @Test
public void singleValue() { void singleValue() {
Object k1 = generateKey(new Object[] { "a" }); Object k1 = generateKey(new Object[] { "a" });
Object k2 = generateKey(new Object[] { "a" }); Object k2 = generateKey(new Object[] { "a" });
Object k3 = generateKey(new Object[] { "different" }); Object k3 = generateKey(new Object[] { "different" });
@ -62,7 +62,7 @@ public class SimpleKeyGeneratorTests {
} }
@Test @Test
public void multipleValues() { void multipleValues() {
Object k1 = generateKey(new Object[] { "a", 1, "b" }); Object k1 = generateKey(new Object[] { "a", 1, "b" });
Object k2 = generateKey(new Object[] { "a", 1, "b" }); Object k2 = generateKey(new Object[] { "a", 1, "b" });
Object k3 = generateKey(new Object[] { "b", 1, "a" }); Object k3 = generateKey(new Object[] { "b", 1, "a" });
@ -73,7 +73,7 @@ public class SimpleKeyGeneratorTests {
} }
@Test @Test
public void singleNullValue() { void singleNullValue() {
Object k1 = generateKey(new Object[] { null }); Object k1 = generateKey(new Object[] { null });
Object k2 = generateKey(new Object[] { null }); Object k2 = generateKey(new Object[] { null });
Object k3 = generateKey(new Object[] { "different" }); Object k3 = generateKey(new Object[] { "different" });
@ -85,7 +85,7 @@ public class SimpleKeyGeneratorTests {
} }
@Test @Test
public void multipleNullValues() { void multipleNullValues() {
Object k1 = generateKey(new Object[] { "a", null, "b", null }); Object k1 = generateKey(new Object[] { "a", null, "b", null });
Object k2 = generateKey(new Object[] { "a", null, "b", null }); Object k2 = generateKey(new Object[] { "a", null, "b", null });
Object k3 = generateKey(new Object[] { "a", null, "b" }); Object k3 = generateKey(new Object[] { "a", null, "b" });
@ -96,7 +96,7 @@ public class SimpleKeyGeneratorTests {
} }
@Test @Test
public void plainArray() { void plainArray() {
Object k1 = generateKey(new Object[] { new String[]{"a", "b"} }); Object k1 = generateKey(new Object[] { new String[]{"a", "b"} });
Object k2 = generateKey(new Object[] { new String[]{"a", "b"} }); Object k2 = generateKey(new Object[] { new String[]{"a", "b"} });
Object k3 = generateKey(new Object[] { new String[]{"b", "a"} }); Object k3 = generateKey(new Object[] { new String[]{"b", "a"} });
@ -107,7 +107,7 @@ public class SimpleKeyGeneratorTests {
} }
@Test @Test
public void arrayWithExtraParameter() { void arrayWithExtraParameter() {
Object k1 = generateKey(new Object[] { new String[]{"a", "b"}, "c" }); Object k1 = generateKey(new Object[] { new String[]{"a", "b"}, "c" });
Object k2 = generateKey(new Object[] { new String[]{"a", "b"}, "c" }); Object k2 = generateKey(new Object[] { new String[]{"a", "b"}, "c" });
Object k3 = generateKey(new Object[] { new String[]{"b", "a"}, "c" }); Object k3 = generateKey(new Object[] { new String[]{"b", "a"}, "c" });
@ -118,7 +118,7 @@ public class SimpleKeyGeneratorTests {
} }
@Test @Test
public void serializedKeys() throws Exception { void serializedKeys() throws Exception {
Object k1 = SerializationTestUtils.serializeAndDeserialize(generateKey(new Object[] { "a", 1, "b" })); Object k1 = SerializationTestUtils.serializeAndDeserialize(generateKey(new Object[] { "a", 1, "b" }));
Object k2 = SerializationTestUtils.serializeAndDeserialize(generateKey(new Object[] { "a", 1, "b" })); Object k2 = SerializationTestUtils.serializeAndDeserialize(generateKey(new Object[] { "a", 1, "b" }));
Object k3 = SerializationTestUtils.serializeAndDeserialize(generateKey(new Object[] { "b", 1, "a" })); Object k3 = SerializationTestUtils.serializeAndDeserialize(generateKey(new Object[] { "b", 1, "a" }));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,11 +33,11 @@ public abstract class AbstractCircularImportDetectionTests {
protected abstract ConfigurationClassParser newParser(); protected abstract ConfigurationClassParser newParser();
protected abstract String loadAsConfigurationSource(Class<?> clazz) throws Exception; protected abstract String loadAsConfigurationSource(Class<?> clazz);
@Test @Test
public void simpleCircularImportIsDetected() throws Exception { void simpleCircularImportIsDetected() throws Exception {
boolean threw = false; boolean threw = false;
try { try {
newParser().parse(loadAsConfigurationSource(A.class), "A"); newParser().parse(loadAsConfigurationSource(A.class), "A");
@ -52,7 +52,7 @@ public abstract class AbstractCircularImportDetectionTests {
} }
@Test @Test
public void complexCircularImportIsDetected() throws Exception { void complexCircularImportIsDetected() throws Exception {
boolean threw = false; boolean threw = false;
try { try {
newParser().parse(loadAsConfigurationSource(X.class), "X"); newParser().parse(loadAsConfigurationSource(X.class), "X");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,10 +34,10 @@ import static org.assertj.core.api.Assertions.fail;
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Liu Dongmiao * @author Liu Dongmiao
*/ */
public class AggressiveFactoryBeanInstantiationTests { class AggressiveFactoryBeanInstantiationTests {
@Test @Test
public void directlyRegisteredFactoryBean() { void directlyRegisteredFactoryBean() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(SimpleFactoryBean.class); context.register(SimpleFactoryBean.class);
context.addBeanFactoryPostProcessor(factory -> context.addBeanFactoryPostProcessor(factory ->
@ -48,7 +48,7 @@ public class AggressiveFactoryBeanInstantiationTests {
} }
@Test @Test
public void beanMethodFactoryBean() { void beanMethodFactoryBean() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(BeanMethodConfiguration.class); context.register(BeanMethodConfiguration.class);
context.addBeanFactoryPostProcessor(factory -> context.addBeanFactoryPostProcessor(factory ->
@ -59,7 +59,7 @@ public class AggressiveFactoryBeanInstantiationTests {
} }
@Test @Test
public void checkLinkageError() { void checkLinkageError() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(BeanMethodConfigurationWithExceptionInInitializer.class); context.register(BeanMethodConfigurationWithExceptionInInitializer.class);
context.refresh(); context.refresh();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -307,8 +307,8 @@ class AnnotationConfigApplicationContextTests {
assertThat(ObjectUtils.containsElement(context.getBeanNamesForType(BeanC.class), "c")).isTrue(); assertThat(ObjectUtils.containsElement(context.getBeanNamesForType(BeanC.class), "c")).isTrue();
assertThat(context.getBeansOfType(BeanA.class)).isEmpty(); assertThat(context.getBeansOfType(BeanA.class)).isEmpty();
assertThat(context.getBeansOfType(BeanB.class).values()).element(0).isSameAs(context.getBean(BeanB.class)); assertThat(context.getBeansOfType(BeanB.class).values()).singleElement().isSameAs(context.getBean(BeanB.class));
assertThat(context.getBeansOfType(BeanC.class).values()).element(0).isSameAs(context.getBean(BeanC.class)); assertThat(context.getBeansOfType(BeanC.class).values()).singleElement().isSameAs(context.getBean(BeanC.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class) assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBeanFactory().resolveNamedBean(BeanA.class)); .isThrownBy(() -> context.getBeanFactory().resolveNamedBean(BeanA.class));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,13 +44,13 @@ import static org.springframework.context.annotation.ScopedProxyMode.TARGET_CLAS
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
*/ */
public class AnnotationScopeMetadataResolverTests { class AnnotationScopeMetadataResolverTests {
private AnnotationScopeMetadataResolver scopeMetadataResolver = new AnnotationScopeMetadataResolver(); private AnnotationScopeMetadataResolver scopeMetadataResolver = new AnnotationScopeMetadataResolver();
@Test @Test
public void resolveScopeMetadataShouldNotApplyScopedProxyModeToSingleton() { void resolveScopeMetadataShouldNotApplyScopedProxyModeToSingleton() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull(); assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
@ -59,7 +59,7 @@ public class AnnotationScopeMetadataResolverTests {
} }
@Test @Test
public void resolveScopeMetadataShouldApplyScopedProxyModeToPrototype() { void resolveScopeMetadataShouldApplyScopedProxyModeToPrototype() {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(INTERFACES); this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(INTERFACES);
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
@ -69,7 +69,7 @@ public class AnnotationScopeMetadataResolverTests {
} }
@Test @Test
public void resolveScopeMetadataShouldReadScopedProxyModeFromAnnotation() { void resolveScopeMetadataShouldReadScopedProxyModeFromAnnotation() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithScopedProxy.class); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithScopedProxy.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull(); assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
@ -78,7 +78,7 @@ public class AnnotationScopeMetadataResolverTests {
} }
@Test @Test
public void customRequestScope() { void customRequestScope() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScope.class); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull(); assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
@ -87,7 +87,7 @@ public class AnnotationScopeMetadataResolverTests {
} }
@Test @Test
public void customRequestScopeViaAsm() throws IOException { void customRequestScopeViaAsm() throws IOException {
MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory(); MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScope.class.getName()); MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScope.class.getName());
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata()); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
@ -98,7 +98,7 @@ public class AnnotationScopeMetadataResolverTests {
} }
@Test @Test
public void customRequestScopeWithAttribute() { void customRequestScopeWithAttribute() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition( AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(
AnnotatedWithCustomRequestScopeWithAttributeOverride.class); AnnotatedWithCustomRequestScopeWithAttributeOverride.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
@ -108,7 +108,7 @@ public class AnnotationScopeMetadataResolverTests {
} }
@Test @Test
public void customRequestScopeWithAttributeViaAsm() throws IOException { void customRequestScopeWithAttributeViaAsm() throws IOException {
MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory(); MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScopeWithAttributeOverride.class.getName()); MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScopeWithAttributeOverride.class.getName());
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata()); AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
@ -119,13 +119,13 @@ public class AnnotationScopeMetadataResolverTests {
} }
@Test @Test
public void ctorWithNullScopedProxyMode() { void ctorWithNullScopedProxyMode() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new AnnotationScopeMetadataResolver(null)); new AnnotationScopeMetadataResolver(null));
} }
@Test @Test
public void setScopeAnnotationTypeWithNullType() { void setScopeAnnotationTypeWithNullType() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
scopeMetadataResolver.setScopeAnnotationType(null)); scopeMetadataResolver.setScopeAnnotationType(null));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,7 +28,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
* *
* @author Chris Beams * @author Chris Beams
*/ */
public class AsmCircularImportDetectionTests extends AbstractCircularImportDetectionTests { class AsmCircularImportDetectionTests extends AbstractCircularImportDetectionTests {
@Override @Override
protected ConfigurationClassParser newParser() { protected ConfigurationClassParser newParser() {
@ -42,7 +42,7 @@ public class AsmCircularImportDetectionTests extends AbstractCircularImportDetec
} }
@Override @Override
protected String loadAsConfigurationSource(Class<?> clazz) throws Exception { protected String loadAsConfigurationSource(Class<?> clazz) {
return clazz.getName(); return clazz.getName();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class BeanMethodMetadataTests { class BeanMethodMetadataTests {
@Test @Test
void providesBeanMethodBeanDefinition() throws Exception { void providesBeanMethodBeanDefinition() {
AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext(Conf.class); AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext(Conf.class);
BeanDefinition beanDefinition = context.getBeanDefinition("myBean"); BeanDefinition beanDefinition = context.getBeanDefinition("myBean");
assertThat(beanDefinition).as("should provide AnnotatedBeanDefinition").isInstanceOf(AnnotatedBeanDefinition.class); assertThat(beanDefinition).as("should provide AnnotatedBeanDefinition").isInstanceOf(AnnotatedBeanDefinition.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,13 +39,13 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BeanMethodPolymorphismTests { public class BeanMethodPolymorphismTests {
@Test @Test
public void beanMethodDetectedOnSuperClass() { void beanMethodDetectedOnSuperClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
assertThat(ctx.getBean("testBean", BaseTestBean.class)).isNotNull(); assertThat(ctx.getBean("testBean", BaseTestBean.class)).isNotNull();
} }
@Test @Test
public void beanMethodOverriding() { void beanMethodOverriding() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(OverridingConfig.class); ctx.register(OverridingConfig.class);
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -56,7 +56,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverridingOnASM() { void beanMethodOverridingOnASM() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(OverridingConfig.class.getName())); ctx.registerBeanDefinition("config", new RootBeanDefinition(OverridingConfig.class.getName()));
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -67,7 +67,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverridingWithNarrowedReturnType() { void beanMethodOverridingWithNarrowedReturnType() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(NarrowedOverridingConfig.class); ctx.register(NarrowedOverridingConfig.class);
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -78,7 +78,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverridingWithNarrowedReturnTypeOnASM() { void beanMethodOverridingWithNarrowedReturnTypeOnASM() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(NarrowedOverridingConfig.class.getName())); ctx.registerBeanDefinition("config", new RootBeanDefinition(NarrowedOverridingConfig.class.getName()));
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -89,7 +89,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverloadingWithoutInheritance() { void beanMethodOverloadingWithoutInheritance() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithOverloading.class); ctx.register(ConfigWithOverloading.class);
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -98,7 +98,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverloadingWithoutInheritanceAndExtraDependency() { void beanMethodOverloadingWithoutInheritanceAndExtraDependency() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithOverloading.class); ctx.register(ConfigWithOverloading.class);
ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5); ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5);
@ -108,7 +108,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverloadingWithAdditionalMetadata() { void beanMethodOverloadingWithAdditionalMetadata() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithOverloadingAndAdditionalMetadata.class); ctx.register(ConfigWithOverloadingAndAdditionalMetadata.class);
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -119,7 +119,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverloadingWithAdditionalMetadataButOtherMethodExecuted() { void beanMethodOverloadingWithAdditionalMetadataButOtherMethodExecuted() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithOverloadingAndAdditionalMetadata.class); ctx.register(ConfigWithOverloadingAndAdditionalMetadata.class);
ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5); ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5);
@ -131,7 +131,7 @@ public class BeanMethodPolymorphismTests {
} }
@Test @Test
public void beanMethodOverloadingWithInheritance() { void beanMethodOverloadingWithInheritance() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(SubConfig.class); ctx.register(SubConfig.class);
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -143,7 +143,7 @@ public class BeanMethodPolymorphismTests {
// SPR-11025 // SPR-11025
@Test @Test
public void beanMethodOverloadingWithInheritanceAndList() { void beanMethodOverloadingWithInheritanceAndList() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(SubConfigWithList.class); ctx.register(SubConfigWithList.class);
ctx.setAllowBeanDefinitionOverriding(false); ctx.setAllowBeanDefinitionOverriding(false);
@ -159,13 +159,13 @@ public class BeanMethodPolymorphismTests {
* so it's referred to here as 'shadowing' to distinguish the difference. * so it's referred to here as 'shadowing' to distinguish the difference.
*/ */
@Test @Test
public void beanMethodShadowing() { void beanMethodShadowing() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ShadowConfig.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ShadowConfig.class);
assertThat(ctx.getBean(String.class)).isEqualTo("shadow"); assertThat(ctx.getBean(String.class)).isEqualTo("shadow");
} }
@Test @Test
public void beanMethodThroughAopProxy() { void beanMethodThroughAopProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class); ctx.register(Config.class);
ctx.register(AnnotationAwareAspectJAutoProxyCreator.class); ctx.register(AnnotationAwareAspectJAutoProxyCreator.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,13 +51,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class ClassPathBeanDefinitionScannerTests { class ClassPathBeanDefinitionScannerTests {
private static final String BASE_PACKAGE = "example.scannable"; private static final String BASE_PACKAGE = "example.scannable";
@Test @Test
public void testSimpleScanWithDefaultFiltersAndPostProcessors() { void testSimpleScanWithDefaultFiltersAndPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE); int beanCount = scanner.scan(BASE_PACKAGE);
@ -83,7 +83,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndPrimaryLazyBean() { void testSimpleScanWithDefaultFiltersAndPrimaryLazyBean() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.scan(BASE_PACKAGE); scanner.scan(BASE_PACKAGE);
@ -105,7 +105,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testDoubleScan() { void testDoubleScan() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@ -130,7 +130,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testWithIndex() { void testWithIndex() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.setClassLoader(CandidateComponentsTestClassLoader.index( context.setClassLoader(CandidateComponentsTestClassLoader.index(
ClassPathScanningCandidateComponentProviderTests.class.getClassLoader(), ClassPathScanningCandidateComponentProviderTests.class.getClassLoader(),
@ -149,7 +149,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testDoubleScanWithIndex() { void testDoubleScanWithIndex() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.setClassLoader(CandidateComponentsTestClassLoader.index( context.setClassLoader(CandidateComponentsTestClassLoader.index(
ClassPathScanningCandidateComponentProviderTests.class.getClassLoader(), ClassPathScanningCandidateComponentProviderTests.class.getClassLoader(),
@ -177,7 +177,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndNoPostProcessors() { void testSimpleScanWithDefaultFiltersAndNoPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false); scanner.setIncludeAnnotationConfig(false);
@ -192,7 +192,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndOverridingBean() { void testSimpleScanWithDefaultFiltersAndOverridingBean() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class)); context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@ -203,7 +203,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndOverridingBeanNotAllowed() { void testSimpleScanWithDefaultFiltersAndOverridingBeanNotAllowed() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.getDefaultListableBeanFactory().setAllowBeanDefinitionOverriding(false); context.getDefaultListableBeanFactory().setAllowBeanDefinitionOverriding(false);
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class)); context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
@ -216,7 +216,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndOverridingBeanAcceptedForSameBeanClass() { void testSimpleScanWithDefaultFiltersAndOverridingBeanAcceptedForSameBeanClass() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.getDefaultListableBeanFactory().setAllowBeanDefinitionOverriding(false); context.getDefaultListableBeanFactory().setAllowBeanDefinitionOverriding(false);
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(StubFooDao.class)); context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(StubFooDao.class));
@ -228,7 +228,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() { void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false); scanner.setIncludeAnnotationConfig(false);
@ -240,7 +240,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() { void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class)); context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
int initialBeanCount = context.getBeanDefinitionCount(); int initialBeanCount = context.getBeanDefinitionCount();
@ -258,7 +258,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() { void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class); RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
@ -278,7 +278,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndSameBeanTwice() { void testSimpleScanWithDefaultFiltersAndSameBeanTwice() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false); scanner.setIncludeAnnotationConfig(false);
@ -288,7 +288,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testSimpleScanWithDefaultFiltersAndSpecifiedBeanNameClash() { void testSimpleScanWithDefaultFiltersAndSpecifiedBeanNameClash() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false); scanner.setIncludeAnnotationConfig(false);
@ -300,7 +300,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testCustomIncludeFilterWithoutDefaultsButIncludingPostProcessors() { void testCustomIncludeFilterWithoutDefaultsButIncludingPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
@ -315,7 +315,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() { void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
@ -335,7 +335,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testCustomIncludeFilterAndDefaults() { void testCustomIncludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
@ -355,7 +355,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testCustomAnnotationExcludeFilterAndDefaults() { void testCustomAnnotationExcludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class)); scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
@ -373,7 +373,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testCustomAssignableTypeExcludeFilterAndDefaults() { void testCustomAssignableTypeExcludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class)); scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
@ -392,7 +392,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testCustomAssignableTypeExcludeFilterAndDefaultsWithoutPostProcessors() { void testCustomAssignableTypeExcludeFilterAndDefaultsWithoutPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.setIncludeAnnotationConfig(false); scanner.setIncludeAnnotationConfig(false);
@ -410,7 +410,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testMultipleCustomExcludeFiltersAndDefaults() { void testMultipleCustomExcludeFiltersAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class)); scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
@ -430,7 +430,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testCustomBeanNameGenerator() { void testCustomBeanNameGenerator() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator()); scanner.setBeanNameGenerator(new TestBeanNameGenerator());
@ -450,7 +450,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testMultipleBasePackagesWithDefaultsOnly() { void testMultipleBasePackagesWithDefaultsOnly() {
GenericApplicationContext singlePackageContext = new GenericApplicationContext(); GenericApplicationContext singlePackageContext = new GenericApplicationContext();
ClassPathBeanDefinitionScanner singlePackageScanner = new ClassPathBeanDefinitionScanner(singlePackageContext); ClassPathBeanDefinitionScanner singlePackageScanner = new ClassPathBeanDefinitionScanner(singlePackageContext);
GenericApplicationContext multiPackageContext = new GenericApplicationContext(); GenericApplicationContext multiPackageContext = new GenericApplicationContext();
@ -462,7 +462,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testMultipleScanCalls() { void testMultipleScanCalls() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int initialBeanCount = context.getBeanDefinitionCount(); int initialBeanCount = context.getBeanDefinitionCount();
@ -474,7 +474,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testBeanAutowiredWithAnnotationConfigEnabled() { void testBeanAutowiredWithAnnotationConfigEnabled() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class)); context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@ -504,7 +504,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testBeanNotAutowiredWithAnnotationConfigDisabled() { void testBeanNotAutowiredWithAnnotationConfigDisabled() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false); scanner.setIncludeAnnotationConfig(false);
@ -523,7 +523,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testAutowireCandidatePatternMatches() { void testAutowireCandidatePatternMatches() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(true); scanner.setIncludeAnnotationConfig(true);
@ -538,7 +538,7 @@ public class ClassPathBeanDefinitionScannerTests {
} }
@Test @Test
public void testAutowireCandidatePatternDoesNotMatch() { void testAutowireCandidatePatternDoesNotMatch() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(true); scanner.setIncludeAnnotationConfig(true);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,13 +37,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Mark Pollack * @author Mark Pollack
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class ClassPathFactoryBeanDefinitionScannerTests { class ClassPathFactoryBeanDefinitionScannerTests {
private static final String BASE_PACKAGE = FactoryMethodComponent.class.getPackage().getName(); private static final String BASE_PACKAGE = FactoryMethodComponent.class.getPackage().getName();
@Test @Test
public void testSingletonScopedFactoryMethod() { void testSingletonScopedFactoryMethod() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,10 +49,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class CommonAnnotationBeanPostProcessorTests { class CommonAnnotationBeanPostProcessorTests {
@Test @Test
public void testPostConstructAndPreDestroy() { void testPostConstructAndPreDestroy() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor()); bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class)); bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
@ -64,7 +64,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testPostConstructAndPreDestroyWithPostProcessor() { void testPostConstructAndPreDestroyWithPostProcessor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addBeanPostProcessor(new InitDestroyBeanPostProcessor()); bf.addBeanPostProcessor(new InitDestroyBeanPostProcessor());
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor()); bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
@ -77,7 +77,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testPostConstructAndPreDestroyWithApplicationContextAndPostProcessor() { void testPostConstructAndPreDestroyWithApplicationContextAndPostProcessor() {
GenericApplicationContext ctx = new GenericApplicationContext(); GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition("bpp1", new RootBeanDefinition(InitDestroyBeanPostProcessor.class)); ctx.registerBeanDefinition("bpp1", new RootBeanDefinition(InitDestroyBeanPostProcessor.class));
ctx.registerBeanDefinition("bpp2", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ctx.registerBeanDefinition("bpp2", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
@ -91,7 +91,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testPostConstructAndPreDestroyWithLegacyAnnotations() { void testPostConstructAndPreDestroyWithLegacyAnnotations() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor()); bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LegacyAnnotatedInitDestroyBean.class)); bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LegacyAnnotatedInitDestroyBean.class));
@ -103,7 +103,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testPostConstructAndPreDestroyWithManualConfiguration() { void testPostConstructAndPreDestroyWithManualConfiguration() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor(); InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
bpp.setInitAnnotationType(PostConstruct.class); bpp.setInitAnnotationType(PostConstruct.class);
@ -118,7 +118,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testPostProcessorWithNullBean() { void testPostProcessorWithNullBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor()); bf.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
RootBeanDefinition rbd = new RootBeanDefinition(NullFactory.class); RootBeanDefinition rbd = new RootBeanDefinition(NullFactory.class);
@ -130,7 +130,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testSerialization() throws Exception { void testSerialization() throws Exception {
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
CommonAnnotationBeanPostProcessor bpp2 = SerializationTestUtils.serializeAndDeserialize(bpp); CommonAnnotationBeanPostProcessor bpp2 = SerializationTestUtils.serializeAndDeserialize(bpp);
@ -140,7 +140,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testSerializationWithManualConfiguration() throws Exception { void testSerializationWithManualConfiguration() throws Exception {
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor(); InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
bpp.setInitAnnotationType(PostConstruct.class); bpp.setInitAnnotationType(PostConstruct.class);
bpp.setDestroyAnnotationType(PreDestroy.class); bpp.setDestroyAnnotationType(PreDestroy.class);
@ -152,7 +152,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testResourceInjection() { void testResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setResourceFactory(bf); bpp.setResourceFactory(bf);
@ -176,7 +176,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testResourceInjectionWithPrototypes() { void testResourceInjectionWithPrototypes() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setResourceFactory(bf); bpp.setResourceFactory(bf);
@ -213,7 +213,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testResourceInjectionWithLegacyAnnotations() { void testResourceInjectionWithLegacyAnnotations() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setResourceFactory(bf); bpp.setResourceFactory(bf);
@ -237,7 +237,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testResourceInjectionWithResolvableDependencyType() { void testResourceInjectionWithResolvableDependencyType() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -273,7 +273,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testResourceInjectionWithDefaultMethod() { void testResourceInjectionWithDefaultMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -293,7 +293,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testResourceInjectionWithTwoProcessors() { void testResourceInjectionWithTwoProcessors() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setResourceFactory(bf); bpp.setResourceFactory(bf);
@ -318,7 +318,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testResourceInjectionFromJndi() { void testResourceInjectionFromJndi() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory(); SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory();
@ -343,7 +343,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testExtendedResourceInjection() { void testExtendedResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -396,7 +396,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testExtendedResourceInjectionWithOverriding() { void testExtendedResourceInjectionWithOverriding() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -453,7 +453,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testExtendedEjbInjection() { void testExtendedEjbInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -490,7 +490,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testLazyResolutionWithResourceField() { void testLazyResolutionWithResourceField() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -508,7 +508,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testLazyResolutionWithResourceMethod() { void testLazyResolutionWithResourceMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -526,7 +526,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testLazyResolutionWithCglibProxy() { void testLazyResolutionWithCglibProxy() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
@ -544,7 +544,7 @@ public class CommonAnnotationBeanPostProcessorTests {
} }
@Test @Test
public void testLazyResolutionWithFallbackTypeMatch() { void testLazyResolutionWithFallbackTypeMatch() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver()); bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Mark Fisher * @author Mark Fisher
* @author Chris Beams * @author Chris Beams
*/ */
public class ComponentScanParserBeanDefinitionDefaultsTests { class ComponentScanParserBeanDefinitionDefaultsTests {
private static final String TEST_BEAN_NAME = "componentScanParserBeanDefinitionDefaultsTests.DefaultsTestBean"; private static final String TEST_BEAN_NAME = "componentScanParserBeanDefinitionDefaultsTests.DefaultsTestBean";
@ -38,12 +38,12 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
DefaultsTestBean.INIT_COUNT = 0; DefaultsTestBean.INIT_COUNT = 0;
} }
@Test @Test
public void testDefaultLazyInit() { void testDefaultLazyInit() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
@ -54,7 +54,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testLazyInitTrue() { void testLazyInitTrue() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitTrueTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitTrueTests.xml");
@ -67,7 +67,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testLazyInitFalse() { void testLazyInitFalse() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitFalseTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitFalseTests.xml");
@ -78,7 +78,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testDefaultAutowire() { void testDefaultAutowire() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
@ -90,7 +90,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testAutowireNo() { void testAutowireNo() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireNoTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireNoTests.xml");
@ -102,7 +102,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testAutowireConstructor() { void testAutowireConstructor() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireConstructorTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireConstructorTests.xml");
@ -115,7 +115,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testAutowireByType() { void testAutowireByType() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByTypeTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByTypeTests.xml");
@ -124,7 +124,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testAutowireByName() { void testAutowireByName() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByNameTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByNameTests.xml");
@ -137,7 +137,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testDefaultDependencyCheck() { void testDefaultDependencyCheck() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
@ -149,7 +149,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testDefaultInitAndDestroyMethodsNotDefined() { void testDefaultInitAndDestroyMethodsNotDefined() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
@ -161,7 +161,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testDefaultInitAndDestroyMethodsDefined() { void testDefaultInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultInitAndDestroyMethodsTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultInitAndDestroyMethodsTests.xml");
@ -173,7 +173,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
} }
@Test @Test
public void testDefaultNonExistingInitAndDestroyMethodsDefined() { void testDefaultNonExistingInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultNonExistingInitAndDestroyMethodsTests.xml"); reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultNonExistingInitAndDestroyMethodsTests.xml");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,10 +34,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
*/ */
public class ComponentScanParserScopedProxyTests { class ComponentScanParserScopedProxyTests {
@Test @Test
public void testDefaultScopedProxy() { void testDefaultScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyDefaultTests.xml"); "org/springframework/context/annotation/scopedProxyDefaultTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope()); context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
@ -49,7 +49,7 @@ public class ComponentScanParserScopedProxyTests {
} }
@Test @Test
public void testNoScopedProxy() { void testNoScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyNoTests.xml"); "org/springframework/context/annotation/scopedProxyNoTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope()); context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
@ -61,7 +61,7 @@ public class ComponentScanParserScopedProxyTests {
} }
@Test @Test
public void testInterfacesScopedProxy() throws Exception { void testInterfacesScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml"); "org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope()); context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
@ -79,7 +79,7 @@ public class ComponentScanParserScopedProxyTests {
} }
@Test @Test
public void testTargetClassScopedProxy() throws Exception { void testTargetClassScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml"); "org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope()); context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
@ -97,7 +97,7 @@ public class ComponentScanParserScopedProxyTests {
@Test @Test
@SuppressWarnings("resource") @SuppressWarnings("resource")
public void testInvalidConfigScopedProxy() throws Exception { public void testInvalidConfigScopedProxy() {
assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(() -> assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(() ->
new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml")) new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml"))
.withMessageContaining("Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag") .withMessageContaining("Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
* @author Sam Brannen * @author Sam Brannen
*/ */
public class ComponentScanParserTests { class ComponentScanParserTests {
private ClassPathXmlApplicationContext loadContext(String path) { private ClassPathXmlApplicationContext loadContext(String path) {
return new ClassPathXmlApplicationContext(path, getClass()); return new ClassPathXmlApplicationContext(path, getClass());
@ -49,7 +49,7 @@ public class ComponentScanParserTests {
@Test @Test
public void aspectjTypeFilter() { void aspectjTypeFilter() {
ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTests.xml"); ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTests.xml");
assertThat(context.containsBean("fooServiceImpl")).isTrue(); assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue(); assertThat(context.containsBean("stubFooDao")).isTrue();
@ -58,7 +58,7 @@ public class ComponentScanParserTests {
} }
@Test @Test
public void aspectjTypeFilterWithPlaceholders() { void aspectjTypeFilterWithPlaceholders() {
System.setProperty("basePackage", "example.scannable, test"); System.setProperty("basePackage", "example.scannable, test");
System.setProperty("scanInclude", "example.scannable.FooService+"); System.setProperty("scanInclude", "example.scannable.FooService+");
System.setProperty("scanExclude", "example..Scoped*Test*"); System.setProperty("scanExclude", "example..Scoped*Test*");
@ -77,21 +77,21 @@ public class ComponentScanParserTests {
} }
@Test @Test
public void nonMatchingResourcePattern() { void nonMatchingResourcePattern() {
ClassPathXmlApplicationContext context = loadContext("nonMatchingResourcePatternTests.xml"); ClassPathXmlApplicationContext context = loadContext("nonMatchingResourcePatternTests.xml");
assertThat(context.containsBean("fooServiceImpl")).isFalse(); assertThat(context.containsBean("fooServiceImpl")).isFalse();
context.close(); context.close();
} }
@Test @Test
public void matchingResourcePattern() { void matchingResourcePattern() {
ClassPathXmlApplicationContext context = loadContext("matchingResourcePatternTests.xml"); ClassPathXmlApplicationContext context = loadContext("matchingResourcePatternTests.xml");
assertThat(context.containsBean("fooServiceImpl")).isTrue(); assertThat(context.containsBean("fooServiceImpl")).isTrue();
context.close(); context.close();
} }
@Test @Test
public void componentScanWithAutowiredQualifier() { void componentScanWithAutowiredQualifier() {
ClassPathXmlApplicationContext context = loadContext("componentScanWithAutowiredQualifierTests.xml"); ClassPathXmlApplicationContext context = loadContext("componentScanWithAutowiredQualifierTests.xml");
AutowiredQualifierFooService fooService = (AutowiredQualifierFooService) context.getBean("fooService"); AutowiredQualifierFooService fooService = (AutowiredQualifierFooService) context.getBean("fooService");
assertThat(fooService.isInitCalled()).isTrue(); assertThat(fooService.isInitCalled()).isTrue();
@ -100,7 +100,7 @@ public class ComponentScanParserTests {
} }
@Test @Test
public void customAnnotationUsedForBothComponentScanAndQualifier() { void customAnnotationUsedForBothComponentScanAndQualifier() {
ClassPathXmlApplicationContext context = loadContext("customAnnotationUsedForBothComponentScanAndQualifierTests.xml"); ClassPathXmlApplicationContext context = loadContext("customAnnotationUsedForBothComponentScanAndQualifierTests.xml");
KustomAnnotationAutowiredBean testBean = (KustomAnnotationAutowiredBean) context.getBean("testBean"); KustomAnnotationAutowiredBean testBean = (KustomAnnotationAutowiredBean) context.getBean("testBean");
assertThat(testBean.getDependency()).isNotNull(); assertThat(testBean.getDependency()).isNotNull();
@ -108,7 +108,7 @@ public class ComponentScanParserTests {
} }
@Test @Test
public void customTypeFilter() { void customTypeFilter() {
ClassPathXmlApplicationContext context = loadContext("customTypeFilterTests.xml"); ClassPathXmlApplicationContext context = loadContext("customTypeFilterTests.xml");
KustomAnnotationAutowiredBean testBean = (KustomAnnotationAutowiredBean) context.getBean("testBean"); KustomAnnotationAutowiredBean testBean = (KustomAnnotationAutowiredBean) context.getBean("testBean");
assertThat(testBean.getDependency()).isNotNull(); assertThat(testBean.getDependency()).isNotNull();
@ -116,7 +116,7 @@ public class ComponentScanParserTests {
} }
@Test @Test
public void componentScanRespectsProfileAnnotation() { void componentScanRespectsProfileAnnotation() {
String xmlLocation = "org/springframework/context/annotation/componentScanRespectsProfileAnnotationTests.xml"; String xmlLocation = "org/springframework/context/annotation/componentScanRespectsProfileAnnotationTests.xml";
{ // should exclude the profile-annotated bean if active profiles remains unset { // should exclude the profile-annotated bean if active profiles remains unset
GenericXmlApplicationContext context = new GenericXmlApplicationContext(); GenericXmlApplicationContext context = new GenericXmlApplicationContext();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,14 +39,14 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
* @since 3.1 * @since 3.1
*/ */
public class ConfigurationClassPostConstructAndAutowiringTests { class ConfigurationClassPostConstructAndAutowiringTests {
/** /**
* Prior to the fix for SPR-8080, this method would succeed due to ordering of * Prior to the fix for SPR-8080, this method would succeed due to ordering of
* configuration class registration. * configuration class registration.
*/ */
@Test @Test
public void control() { void control() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config1.class, Config2.class); ctx.register(Config1.class, Config2.class);
ctx.refresh(); ctx.refresh();
@ -62,7 +62,7 @@ public class ConfigurationClassPostConstructAndAutowiringTests {
* configuration class registration. * configuration class registration.
*/ */
@Test @Test
public void originalReproCase() { void originalReproCase() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config2.class, Config1.class); ctx.register(Config2.class, Config1.class);
ctx.refresh(); ctx.refresh();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -238,7 +238,7 @@ class ConfigurationClassPostProcessorAotContributionTests {
} }
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() {
Assert.notNull(this.metadata, "Metadata was not injected"); Assert.notNull(this.metadata, "Metadata was not injected");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -1155,11 +1155,13 @@ class ConfigurationClassPostProcessorTests {
@Configuration @Configuration
static class StaticSingletonBeanConfig { static class StaticSingletonBeanConfig {
public static @Bean Foo foo() { @Bean
public static Foo foo() {
return new Foo(); return new Foo();
} }
public static @Bean Bar bar() { @Bean
public static Bar bar() {
return new Bar(foo()); return new Bar(foo());
} }
} }
@ -1598,7 +1600,7 @@ class ConfigurationClassPostProcessorTests {
public static class WildcardWithGenericExtendsConfiguration { public static class WildcardWithGenericExtendsConfiguration {
@Bean @Bean
public Repository<? extends Object> genericRepo() { public Repository<?> genericRepo() {
return new Repository<String>(); return new Repository<String>();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ConfigurationClassWithConditionTests { public class ConfigurationClassWithConditionTests {
@Test @Test
public void conditionalOnMissingBeanMatch() throws Exception { void conditionalOnMissingBeanMatch() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanOneConfiguration.class, BeanTwoConfiguration.class); ctx.register(BeanOneConfiguration.class, BeanTwoConfiguration.class);
ctx.refresh(); ctx.refresh();
@ -53,7 +53,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void conditionalOnMissingBeanNoMatch() throws Exception { void conditionalOnMissingBeanNoMatch() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanTwoConfiguration.class); ctx.register(BeanTwoConfiguration.class);
ctx.refresh(); ctx.refresh();
@ -63,7 +63,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void conditionalOnBeanMatch() throws Exception { void conditionalOnBeanMatch() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanOneConfiguration.class, BeanThreeConfiguration.class); ctx.register(BeanOneConfiguration.class, BeanThreeConfiguration.class);
ctx.refresh(); ctx.refresh();
@ -72,7 +72,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void conditionalOnBeanNoMatch() throws Exception { void conditionalOnBeanNoMatch() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanThreeConfiguration.class); ctx.register(BeanThreeConfiguration.class);
ctx.refresh(); ctx.refresh();
@ -81,7 +81,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void metaConditional() throws Exception { void metaConditional() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigurationWithMetaCondition.class); ctx.register(ConfigurationWithMetaCondition.class);
ctx.refresh(); ctx.refresh();
@ -89,7 +89,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void metaConditionalWithAsm() throws Exception { void metaConditionalWithAsm() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithMetaCondition.class.getName())); ctx.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithMetaCondition.class.getName()));
ctx.refresh(); ctx.refresh();
@ -97,7 +97,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void nonConfigurationClass() throws Exception { void nonConfigurationClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(NonConfigurationClass.class); ctx.register(NonConfigurationClass.class);
ctx.refresh(); ctx.refresh();
@ -105,7 +105,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void nonConfigurationClassWithAsm() throws Exception { void nonConfigurationClassWithAsm() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(NonConfigurationClass.class.getName())); ctx.registerBeanDefinition("config", new RootBeanDefinition(NonConfigurationClass.class.getName()));
ctx.refresh(); ctx.refresh();
@ -113,7 +113,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void methodConditional() throws Exception { void methodConditional() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConditionOnMethodConfiguration.class); ctx.register(ConditionOnMethodConfiguration.class);
ctx.refresh(); ctx.refresh();
@ -121,7 +121,7 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void methodConditionalWithAsm() throws Exception { void methodConditionalWithAsm() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(ConditionOnMethodConfiguration.class.getName())); ctx.registerBeanDefinition("config", new RootBeanDefinition(ConditionOnMethodConfiguration.class.getName()));
ctx.refresh(); ctx.refresh();
@ -129,27 +129,27 @@ public class ConfigurationClassWithConditionTests {
} }
@Test @Test
public void importsNotCreated() throws Exception { void importsNotCreated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportsNotCreated.class); ctx.register(ImportsNotCreated.class);
ctx.refresh(); ctx.refresh();
} }
@Test @Test
public void conditionOnOverriddenMethodHonored() { void conditionOnOverriddenMethodHonored() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithBeanSkipped.class); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithBeanSkipped.class);
assertThat(context.getBeansOfType(ExampleBean.class)).isEmpty(); assertThat(context.getBeansOfType(ExampleBean.class)).isEmpty();
} }
@Test @Test
public void noConditionOnOverriddenMethodHonored() { void noConditionOnOverriddenMethodHonored() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithBeanReactivated.class); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithBeanReactivated.class);
Map<String, ExampleBean> beans = context.getBeansOfType(ExampleBean.class); Map<String, ExampleBean> beans = context.getBeansOfType(ExampleBean.class);
assertThat(beans).containsOnlyKeys("baz"); assertThat(beans).containsOnlyKeys("baz");
} }
@Test @Test
public void configWithAlternativeBeans() { void configWithAlternativeBeans() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAlternativeBeans.class); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAlternativeBeans.class);
Map<String, ExampleBean> beans = context.getBeansOfType(ExampleBean.class); Map<String, ExampleBean> beans = context.getBeansOfType(ExampleBean.class);
assertThat(beans).containsOnlyKeys("baz"); assertThat(beans).containsOnlyKeys("baz");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -108,12 +108,12 @@ class ConfigurationWithFactoryBeanAndAutowiringTests {
private boolean initialized = false; private boolean initialized = false;
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() {
this.initialized = true; this.initialized = true;
} }
@Override @Override
public String getObject() throws Exception { public String getObject() {
return "foo"; return "foo";
} }
@ -142,7 +142,7 @@ class ConfigurationWithFactoryBeanAndAutowiringTests {
} }
@Override @Override
public T getObject() throws Exception { public T getObject() {
return obj; return obj;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,50 +40,50 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests { class ConfigurationWithFactoryBeanBeanEarlyDeductionTests {
@Test @Test
public void preFreezeDirect() { void preFreezeDirect() {
assertPreFreeze(DirectConfiguration.class); assertPreFreeze(DirectConfiguration.class);
} }
@Test @Test
public void postFreezeDirect() { void postFreezeDirect() {
assertPostFreeze(DirectConfiguration.class); assertPostFreeze(DirectConfiguration.class);
} }
@Test @Test
public void preFreezeGenericMethod() { void preFreezeGenericMethod() {
assertPreFreeze(GenericMethodConfiguration.class); assertPreFreeze(GenericMethodConfiguration.class);
} }
@Test @Test
public void postFreezeGenericMethod() { void postFreezeGenericMethod() {
assertPostFreeze(GenericMethodConfiguration.class); assertPostFreeze(GenericMethodConfiguration.class);
} }
@Test @Test
public void preFreezeGenericClass() { void preFreezeGenericClass() {
assertPreFreeze(GenericClassConfiguration.class); assertPreFreeze(GenericClassConfiguration.class);
} }
@Test @Test
public void postFreezeGenericClass() { void postFreezeGenericClass() {
assertPostFreeze(GenericClassConfiguration.class); assertPostFreeze(GenericClassConfiguration.class);
} }
@Test @Test
public void preFreezeAttribute() { void preFreezeAttribute() {
assertPreFreeze(AttributeClassConfiguration.class); assertPreFreeze(AttributeClassConfiguration.class);
} }
@Test @Test
public void postFreezeAttribute() { void postFreezeAttribute() {
assertPostFreeze(AttributeClassConfiguration.class); assertPostFreeze(AttributeClassConfiguration.class);
} }
@Test @Test
public void preFreezeUnresolvedGenericFactoryBean() { void preFreezeUnresolvedGenericFactoryBean() {
// Covers the case where a @Configuration is picked up via component scanning // Covers the case where a @Configuration is picked up via component scanning
// and its bean definition only has a String bean class. In such cases // and its bean definition only has a String bean class. In such cases
// beanDefinition.hasBeanClass() returns false so we need to actually // beanDefinition.hasBeanClass() returns false so we need to actually
@ -212,7 +212,7 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests {
} }
@Override @Override
public T getObject() throws Exception { public T getObject() {
return this.instance; return this.instance;
} }
@ -236,7 +236,7 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests {
private final Object object = new MyBean(); private final Object object = new MyBean();
@Override @Override
public Object getObject() throws Exception { public Object getObject() {
return object; return object;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,28 +29,28 @@ import static org.mockito.Mockito.mock;
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class DeferredImportSelectorTests { class DeferredImportSelectorTests {
@Test @Test
public void entryEqualsSameInstance() { void entryEqualsSameInstance() {
AnnotationMetadata metadata = mock(); AnnotationMetadata metadata = mock();
Group.Entry entry = new Group.Entry(metadata, "com.example.Test"); Group.Entry entry = new Group.Entry(metadata, "com.example.Test");
assertThat(entry).isEqualTo(entry); assertThat(entry).isEqualTo(entry);
} }
@Test @Test
public void entryEqualsSameMetadataAndClassName() { void entryEqualsSameMetadataAndClassName() {
AnnotationMetadata metadata = mock(); AnnotationMetadata metadata = mock();
assertThat(new Group.Entry(metadata, "com.example.Test")).isEqualTo(new Group.Entry(metadata, "com.example.Test")); assertThat(new Group.Entry(metadata, "com.example.Test")).isEqualTo(new Group.Entry(metadata, "com.example.Test"));
} }
@Test @Test
public void entryEqualDifferentMetadataAndSameClassName() { void entryEqualDifferentMetadataAndSameClassName() {
assertThat(new Group.Entry(mock(), "com.example.Test")).isNotEqualTo(new Group.Entry(mock(), "com.example.Test")); assertThat(new Group.Entry(mock(), "com.example.Test")).isNotEqualTo(new Group.Entry(mock(), "com.example.Test"));
} }
@Test @Test
public void entryEqualSameMetadataAnDifferentClassName() { void entryEqualSameMetadataAnDifferentClassName() {
AnnotationMetadata metadata = mock(); AnnotationMetadata metadata = mock();
assertThat(new Group.Entry(metadata, "com.example.AnotherTest")).isNotEqualTo(new Group.Entry(metadata, "com.example.Test")); assertThat(new Group.Entry(metadata, "com.example.AnotherTest")).isNotEqualTo(new Group.Entry(metadata, "com.example.Test"));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class DestroyMethodInferenceTests { class DestroyMethodInferenceTests {
@Test @Test
public void beanMethods() { void beanMethods() {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class); ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
WithExplicitDestroyMethod c0 = ctx.getBean(WithExplicitDestroyMethod.class); WithExplicitDestroyMethod c0 = ctx.getBean(WithExplicitDestroyMethod.class);
WithLocalCloseMethod c1 = ctx.getBean("c1", WithLocalCloseMethod.class); WithLocalCloseMethod c1 = ctx.getBean("c1", WithLocalCloseMethod.class);
@ -83,7 +83,7 @@ public class DestroyMethodInferenceTests {
} }
@Test @Test
public void xml() { void xml() {
ConfigurableApplicationContext ctx = new GenericXmlApplicationContext( ConfigurableApplicationContext ctx = new GenericXmlApplicationContext(
getClass(), "DestroyMethodInferenceTests-context.xml"); getClass(), "DestroyMethodInferenceTests-context.xml");
WithLocalCloseMethod x1 = ctx.getBean("x1", WithLocalCloseMethod.class); WithLocalCloseMethod x1 = ctx.getBean("x1", WithLocalCloseMethod.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,7 @@ package org.springframework.context.annotation;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class DoubleScanTests extends SimpleScanTests { class DoubleScanTests extends SimpleScanTests {
@Override @Override
protected String[] getConfigLocations() { protected String[] getConfigLocations() {

View File

@ -70,7 +70,7 @@ public class ImportSelectorTests {
@BeforeEach @BeforeEach
public void cleanup() { void cleanup() {
ImportSelectorTests.importFrom.clear(); ImportSelectorTests.importFrom.clear();
SampleImportSelector.cleanup(); SampleImportSelector.cleanup();
TestImportGroup.cleanup(); TestImportGroup.cleanup();
@ -78,7 +78,7 @@ public class ImportSelectorTests {
@Test @Test
public void importSelectors() { void importSelectors() {
DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
context.register(Config.class); context.register(Config.class);
@ -92,7 +92,7 @@ public class ImportSelectorTests {
} }
@Test @Test
public void invokeAwareMethodsInImportSelector() { void invokeAwareMethodsInImportSelector() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class);
assertThat(SampleImportSelector.beanFactory).isEqualTo(context.getBeanFactory()); assertThat(SampleImportSelector.beanFactory).isEqualTo(context.getBeanFactory());
assertThat(SampleImportSelector.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader()); assertThat(SampleImportSelector.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader());
@ -101,7 +101,7 @@ public class ImportSelectorTests {
} }
@Test @Test
public void correctMetadataOnIndirectImports() { void correctMetadataOnIndirectImports() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(IndirectConfig.class); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(IndirectConfig.class);
String indirectImport = IndirectImport.class.getName(); String indirectImport = IndirectImport.class.getName();
assertThat(importFrom.get(ImportSelector1.class)).isEqualTo(indirectImport); assertThat(importFrom.get(ImportSelector1.class)).isEqualTo(indirectImport);
@ -115,7 +115,7 @@ public class ImportSelectorTests {
} }
@Test @Test
public void importSelectorsWithGroup() { void importSelectorsWithGroup() {
DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
context.register(GroupedConfig.class); context.register(GroupedConfig.class);
@ -131,7 +131,7 @@ public class ImportSelectorTests {
} }
@Test @Test
public void importSelectorsSeparateWithGroup() { void importSelectorsSeparateWithGroup() {
DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
context.register(GroupedConfig1.class); context.register(GroupedConfig1.class);
@ -146,7 +146,7 @@ public class ImportSelectorTests {
} }
@Test @Test
public void importSelectorsWithNestedGroup() { void importSelectorsWithNestedGroup() {
DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
context.register(ParentConfiguration1.class); context.register(ParentConfiguration1.class);
@ -166,7 +166,7 @@ public class ImportSelectorTests {
} }
@Test @Test
public void importSelectorsWithNestedGroupSameDeferredImport() { void importSelectorsWithNestedGroupSameDeferredImport() {
DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
context.register(ParentConfiguration2.class); context.register(ParentConfiguration2.class);
@ -185,7 +185,7 @@ public class ImportSelectorTests {
} }
@Test @Test
public void invokeAwareMethodsInImportGroup() { void invokeAwareMethodsInImportGroup() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(GroupedConfig1.class); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(GroupedConfig1.class);
assertThat(TestImportGroup.beanFactory).isEqualTo(context.getBeanFactory()); assertThat(TestImportGroup.beanFactory).isEqualTo(context.getBeanFactory());
assertThat(TestImportGroup.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader()); assertThat(TestImportGroup.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,10 +26,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/** /**
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
public class ImportVersusDirectRegistrationTests { class ImportVersusDirectRegistrationTests {
@Test @Test
public void thingIsNotAvailableWhenOuterConfigurationIsRegisteredDirectly() { void thingIsNotAvailableWhenOuterConfigurationIsRegisteredDirectly() {
try (AnnotationConfigApplicationContext directRegistration = new AnnotationConfigApplicationContext()) { try (AnnotationConfigApplicationContext directRegistration = new AnnotationConfigApplicationContext()) {
directRegistration.register(AccidentalLiteConfiguration.class); directRegistration.register(AccidentalLiteConfiguration.class);
directRegistration.refresh(); directRegistration.refresh();
@ -39,7 +39,7 @@ public class ImportVersusDirectRegistrationTests {
} }
@Test @Test
public void thingIsNotAvailableWhenOuterConfigurationIsRegisteredWithClassName() { void thingIsNotAvailableWhenOuterConfigurationIsRegisteredWithClassName() {
try (AnnotationConfigApplicationContext directRegistration = new AnnotationConfigApplicationContext()) { try (AnnotationConfigApplicationContext directRegistration = new AnnotationConfigApplicationContext()) {
directRegistration.registerBeanDefinition("config", directRegistration.registerBeanDefinition("config",
new RootBeanDefinition(AccidentalLiteConfiguration.class.getName())); new RootBeanDefinition(AccidentalLiteConfiguration.class.getName()));
@ -50,7 +50,7 @@ public class ImportVersusDirectRegistrationTests {
} }
@Test @Test
public void thingIsNotAvailableWhenOuterConfigurationIsImported() { void thingIsNotAvailableWhenOuterConfigurationIsImported() {
try (AnnotationConfigApplicationContext viaImport = new AnnotationConfigApplicationContext()) { try (AnnotationConfigApplicationContext viaImport = new AnnotationConfigApplicationContext()) {
viaImport.register(Importer.class); viaImport.register(Importer.class);
viaImport.refresh(); viaImport.refresh();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.ro
* *
* @author Chris Beams * @author Chris Beams
*/ */
public class InvalidConfigurationClassDefinitionTests { class InvalidConfigurationClassDefinitionTests {
@Test @Test
public void configurationClassesMayNotBeFinal() { void configurationClassesMayNotBeFinal() {
@Configuration @Configuration
final class Config { } final class Config { }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ import static org.mockito.Mockito.reset;
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class ParserStrategyUtilsTests { class ParserStrategyUtilsTests {
@Mock @Mock
private Environment environment; private Environment environment;
@ -66,7 +66,7 @@ public class ParserStrategyUtilsTests {
} }
@Test @Test
public void instantiateClassWhenHasNoArgsConstructorCallsAware() { void instantiateClassWhenHasNoArgsConstructorCallsAware() {
NoArgsConstructor instance = instantiateClass(NoArgsConstructor.class); NoArgsConstructor instance = instantiateClass(NoArgsConstructor.class);
assertThat(instance.setEnvironment).isSameAs(this.environment); assertThat(instance.setEnvironment).isSameAs(this.environment);
assertThat(instance.setBeanFactory).isSameAs(this.registry); assertThat(instance.setBeanFactory).isSameAs(this.registry);
@ -75,7 +75,7 @@ public class ParserStrategyUtilsTests {
} }
@Test @Test
public void instantiateClassWhenHasSingleConstructorInjectsParams() { void instantiateClassWhenHasSingleConstructorInjectsParams() {
ArgsConstructor instance = instantiateClass(ArgsConstructor.class); ArgsConstructor instance = instantiateClass(ArgsConstructor.class);
assertThat(instance.environment).isSameAs(this.environment); assertThat(instance.environment).isSameAs(this.environment);
assertThat(instance.beanFactory).isSameAs(this.registry); assertThat(instance.beanFactory).isSameAs(this.registry);
@ -84,7 +84,7 @@ public class ParserStrategyUtilsTests {
} }
@Test @Test
public void instantiateClassWhenHasSingleConstructorAndAwareInjectsParamsAndCallsAware() { void instantiateClassWhenHasSingleConstructorAndAwareInjectsParamsAndCallsAware() {
ArgsConstructorAndAware instance = instantiateClass(ArgsConstructorAndAware.class); ArgsConstructorAndAware instance = instantiateClass(ArgsConstructorAndAware.class);
assertThat(instance.environment).isSameAs(this.environment); assertThat(instance.environment).isSameAs(this.environment);
assertThat(instance.setEnvironment).isSameAs(this.environment); assertThat(instance.setEnvironment).isSameAs(this.environment);
@ -97,20 +97,20 @@ public class ParserStrategyUtilsTests {
} }
@Test @Test
public void instantiateClassWhenHasMultipleConstructorsUsesNoArgsConstructor() { void instantiateClassWhenHasMultipleConstructorsUsesNoArgsConstructor() {
// Remain back-compatible by using the default constructor if there's more than one // Remain back-compatible by using the default constructor if there's more than one
MultipleConstructors instance = instantiateClass(MultipleConstructors.class); MultipleConstructors instance = instantiateClass(MultipleConstructors.class);
assertThat(instance.usedDefaultConstructor).isTrue(); assertThat(instance.usedDefaultConstructor).isTrue();
} }
@Test @Test
public void instantiateClassWhenHasMultipleConstructorsAndNotDefaultThrowsException() { void instantiateClassWhenHasMultipleConstructorsAndNotDefaultThrowsException() {
assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() ->
instantiateClass(MultipleConstructorsWithNoDefault.class)); instantiateClass(MultipleConstructorsWithNoDefault.class));
} }
@Test @Test
public void instantiateClassWhenHasUnsupportedParameterThrowsException() { void instantiateClassWhenHasUnsupportedParameterThrowsException() {
assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() ->
instantiateClass(InvalidConstructorParameterType.class)) instantiateClass(InvalidConstructorParameterType.class))
.withCauseInstanceOf(IllegalStateException.class) .withCauseInstanceOf(IllegalStateException.class)
@ -118,7 +118,7 @@ public class ParserStrategyUtilsTests {
} }
@Test @Test
public void instantiateClassHasSubclassParameterThrowsException() { void instantiateClassHasSubclassParameterThrowsException() {
// To keep the algorithm simple we don't support subtypes // To keep the algorithm simple we don't support subtypes
assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() ->
instantiateClass(InvalidConstructorParameterSubType.class)) instantiateClass(InvalidConstructorParameterSubType.class))
@ -127,14 +127,14 @@ public class ParserStrategyUtilsTests {
} }
@Test @Test
public void instantiateClassWhenHasNoBeanClassLoaderInjectsNull() { void instantiateClassWhenHasNoBeanClassLoaderInjectsNull() {
reset(this.resourceLoader); reset(this.resourceLoader);
ArgsConstructor instance = instantiateClass(ArgsConstructor.class); ArgsConstructor instance = instantiateClass(ArgsConstructor.class);
assertThat(instance.beanClassLoader).isNull(); assertThat(instance.beanClassLoader).isNull();
} }
@Test @Test
public void instantiateClassWhenHasNoBeanClassLoaderDoesNotCallAware() { void instantiateClassWhenHasNoBeanClassLoaderDoesNotCallAware() {
reset(this.resourceLoader); reset(this.resourceLoader);
NoArgsConstructor instance = instantiateClass(NoArgsConstructor.class); NoArgsConstructor instance = instantiateClass(NoArgsConstructor.class);
assertThat(instance.setBeanClassLoader).isNull(); assertThat(instance.setBeanClassLoader).isNull();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @since 3.1 * @since 3.1
* @see org.springframework.util.ReflectionUtilsTests * @see org.springframework.util.ReflectionUtilsTests
*/ */
public class ReflectionUtilsIntegrationTests { class ReflectionUtilsIntegrationTests {
@Test @Test
public void getUniqueDeclaredMethods_withCovariantReturnType_andCglibRewrittenMethodNames() throws Exception { void getUniqueDeclaredMethods_withCovariantReturnType_andCglibRewrittenMethodNames() {
Class<?> cglibLeaf = new ConfigurationClassEnhancer().enhance(Leaf.class, null); Class<?> cglibLeaf = new ConfigurationClassEnhancer().enhance(Leaf.class, null);
int m1MethodCount = 0; int m1MethodCount = 0;
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(cglibLeaf); Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(cglibLeaf);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Mark Fisher * @author Mark Fisher
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class SimpleConfigTests { class SimpleConfigTests {
@Test @Test
public void testFooService() throws Exception { void testFooService() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass()); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass());
FooService fooService = ctx.getBean("fooServiceImpl", FooService.class); FooService fooService = ctx.getBean("fooServiceImpl", FooService.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,14 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class SimpleScanTests { class SimpleScanTests {
protected String[] getConfigLocations() { protected String[] getConfigLocations() {
return new String[] {"simpleScanTests.xml"}; return new String[] {"simpleScanTests.xml"};
} }
@Test @Test
public void testFooService() throws Exception { void testFooService() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass()); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass());
FooService fooService = (FooService) ctx.getBean("fooServiceImpl"); FooService fooService = (FooService) ctx.getBean("fooServiceImpl");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -77,7 +77,7 @@ class Spr11202Tests {
} }
@Bean @Bean
public String value() throws Exception { public String value() {
String name = foo().getObject().getName(); String name = foo().getObject().getName();
Assert.state(name != null, "Name cannot be null"); Assert.state(name != null, "Name cannot be null");
return name; return name;
@ -85,7 +85,7 @@ class Spr11202Tests {
@Bean @Bean
@Conditional(NoBarCondition.class) @Conditional(NoBarCondition.class)
public String bar() throws Exception { public String bar() {
return "bar"; return "bar";
} }
} }
@ -115,7 +115,7 @@ class Spr11202Tests {
private Foo foo = new Foo(); private Foo foo = new Foo();
@Override @Override
public Foo getObject() throws Exception { public Foo getObject() {
return foo; return foo;
} }
@ -130,7 +130,7 @@ class Spr11202Tests {
} }
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() {
this.foo.name = "foo"; this.foo.name = "foo";
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,33 +27,33 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/** /**
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class Spr12278Tests { class Spr12278Tests {
private AnnotationConfigApplicationContext context; private AnnotationConfigApplicationContext context;
@AfterEach @AfterEach
public void close() { void close() {
if (context != null) { if (context != null) {
context.close(); context.close();
} }
} }
@Test @Test
public void componentSingleConstructor() { void componentSingleConstructor() {
this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class, this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class,
SingleConstructorComponent.class); SingleConstructorComponent.class);
assertThat(this.context.getBean(SingleConstructorComponent.class).autowiredName).isEqualTo("foo"); assertThat(this.context.getBean(SingleConstructorComponent.class).autowiredName).isEqualTo("foo");
} }
@Test @Test
public void componentTwoConstructorsNoHint() { void componentTwoConstructorsNoHint() {
this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class, this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class,
TwoConstructorsComponent.class); TwoConstructorsComponent.class);
assertThat(this.context.getBean(TwoConstructorsComponent.class).name).isEqualTo("fallback"); assertThat(this.context.getBean(TwoConstructorsComponent.class).name).isEqualTo("fallback");
} }
@Test @Test
public void componentTwoSpecificConstructorsNoHint() { void componentTwoSpecificConstructorsNoHint() {
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
new AnnotationConfigApplicationContext(BaseConfiguration.class, TwoSpecificConstructorsComponent.class)) new AnnotationConfigApplicationContext(BaseConfiguration.class, TwoSpecificConstructorsComponent.class))
.withMessageContaining("No default constructor found"); .withMessageContaining("No default constructor found");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,29 +34,30 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class Spr12636Tests { class Spr12636Tests {
private ConfigurableApplicationContext context; private ConfigurableApplicationContext context;
@AfterEach @AfterEach
public void closeContext() { void closeContext() {
if (this.context != null) { if (this.context != null) {
this.context.close(); this.context.close();
} }
} }
@Test @Test
public void orderOnImplementation() { void orderOnImplementation() {
this.context = new AnnotationConfigApplicationContext( this.context = new AnnotationConfigApplicationContext(
UserServiceTwo.class, UserServiceOne.class, UserServiceCollector.class); UserServiceTwo.class, UserServiceOne.class, UserServiceCollector.class);
UserServiceCollector bean = this.context.getBean(UserServiceCollector.class); UserServiceCollector bean = this.context.getBean(UserServiceCollector.class);
assertThat(bean.userServices).element(0).isSameAs(context.getBean("serviceOne", UserService.class)); assertThat(bean.userServices).containsExactly(
assertThat(bean.userServices).element(1).isSameAs(context.getBean("serviceTwo", UserService.class)); context.getBean("serviceOne", UserService.class),
context.getBean("serviceTwo", UserService.class));
} }
@Test @Test
public void orderOnImplementationWithProxy() { void orderOnImplementationWithProxy() {
this.context = new AnnotationConfigApplicationContext( this.context = new AnnotationConfigApplicationContext(
UserServiceTwo.class, UserServiceOne.class, UserServiceCollector.class, AsyncConfig.class); UserServiceTwo.class, UserServiceOne.class, UserServiceCollector.class, AsyncConfig.class);
@ -67,8 +68,7 @@ public class Spr12636Tests {
assertThat(AopUtils.isAopProxy(serviceTwo)).isTrue(); assertThat(AopUtils.isAopProxy(serviceTwo)).isTrue();
UserServiceCollector bean = this.context.getBean(UserServiceCollector.class); UserServiceCollector bean = this.context.getBean(UserServiceCollector.class);
assertThat(bean.userServices).element(0).isSameAs(serviceOne); assertThat(bean.userServices).containsExactly(serviceOne, serviceTwo);
assertThat(bean.userServices).element(1).isSameAs(serviceTwo);
} }
@Configuration @Configuration

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -204,7 +204,7 @@ class Spr15275Tests {
} }
@Bean @Bean
public Bar bar() throws Exception { public Bar bar() {
assertThat(foo().isSingleton()).isTrue(); assertThat(foo().isSingleton()).isTrue();
return new Bar(foo().getObject()); return new Bar(foo().getObject());
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class Spr16217Tests { class Spr16217Tests {
@Test @Test
@Disabled("TODO") @Disabled("TODO")
@ -37,7 +37,7 @@ public class Spr16217Tests {
} }
@Test @Test
public void baseConfigurationIsIncludedWhenFirstSuperclassReferenceIsSkippedInParseConfigurationPhase() { void baseConfigurationIsIncludedWhenFirstSuperclassReferenceIsSkippedInParseConfigurationPhase() {
try (AnnotationConfigApplicationContext context = try (AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(ParseConfigurationPhaseImportingConfiguration.class)) { new AnnotationConfigApplicationContext(ParseConfigurationPhaseImportingConfiguration.class)) {
context.getBean("someBean"); context.getBean("someBean");
@ -45,17 +45,14 @@ public class Spr16217Tests {
} }
@Test @Test
public void baseConfigurationIsIncludedOnceWhenBothConfigurationClassesAreActive() { void baseConfigurationIsIncludedOnceWhenBothConfigurationClassesAreActive() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.setAllowBeanDefinitionOverriding(false); try (context) {
context.register(UnconditionalImportingConfiguration.class); context.setAllowBeanDefinitionOverriding(false);
context.refresh(); context.register(UnconditionalImportingConfiguration.class);
try { context.refresh();
context.getBean("someBean"); context.getBean("someBean");
} }
finally {
context.close();
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,19 +31,19 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Chris Beams * @author Chris Beams
*/ */
public class Spr6602Tests { class Spr6602Tests {
@Test @Test
public void testXmlBehavior() throws Exception { void testXmlBehavior() throws Exception {
doAssertions(new ClassPathXmlApplicationContext("Spr6602Tests-context.xml", Spr6602Tests.class)); doAssertions(new ClassPathXmlApplicationContext("Spr6602Tests-context.xml", Spr6602Tests.class));
} }
@Test @Test
public void testConfigurationClassBehavior() throws Exception { void testConfigurationClassBehavior() throws Exception {
doAssertions(new AnnotationConfigApplicationContext(FooConfig.class)); doAssertions(new AnnotationConfigApplicationContext(FooConfig.class));
} }
private void doAssertions(ApplicationContext ctx) throws Exception { private void doAssertions(ApplicationContext ctx) {
Foo foo = ctx.getBean(Foo.class); Foo foo = ctx.getBean(Foo.class);
Bar bar1 = ctx.getBean(Bar.class); Bar bar1 = ctx.getBean(Bar.class);
@ -65,7 +65,7 @@ public class Spr6602Tests {
public static class FooConfig { public static class FooConfig {
@Bean @Bean
public Foo foo() throws Exception { public Foo foo() {
return new Foo(barFactory().getObject()); return new Foo(barFactory().getObject());
} }
@ -93,7 +93,7 @@ public class Spr6602Tests {
public static class BarFactory implements FactoryBean<Bar> { public static class BarFactory implements FactoryBean<Bar> {
@Override @Override
public Bar getObject() throws Exception { public Bar getObject() {
return new Bar(); return new Bar();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class Spr8954Tests { public class Spr8954Tests {
@Test @Test
public void repro() { void repro() {
AnnotationConfigApplicationContext bf = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext bf = new AnnotationConfigApplicationContext();
bf.registerBeanDefinition("fooConfig", new RootBeanDefinition(FooConfig.class)); bf.registerBeanDefinition("fooConfig", new RootBeanDefinition(FooConfig.class));
bf.getBeanFactory().addBeanPostProcessor(new PredictingBPP()); bf.getBeanFactory().addBeanPostProcessor(new PredictingBPP());
@ -64,7 +64,7 @@ public class Spr8954Tests {
} }
@Test @Test
public void findsBeansByTypeIfNotInstantiated() { void findsBeansByTypeIfNotInstantiated() {
AnnotationConfigApplicationContext bf = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext bf = new AnnotationConfigApplicationContext();
bf.registerBeanDefinition("fooConfig", new RootBeanDefinition(FooConfig.class)); bf.registerBeanDefinition("fooConfig", new RootBeanDefinition(FooConfig.class));
bf.getBeanFactory().addBeanPostProcessor(new PredictingBPP()); bf.getBeanFactory().addBeanPostProcessor(new PredictingBPP());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -281,7 +281,7 @@ class AutowiredConfigurationTests {
return new TestBean(""); return new TestBean("");
} }
else { else {
return new TestBean(colour.get().toString() + "-" + colours.get().get(0).toString()); return new TestBean(colour.get() + "-" + colours.get().get(0).toString());
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,10 +43,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class BeanAnnotationAttributePropagationTests { class BeanAnnotationAttributePropagationTests {
@Test @Test
public void autowireCandidateMetadataIsPropagated() { void autowireCandidateMetadataIsPropagated() {
@Configuration class Config { @Configuration class Config {
@Bean(autowireCandidate=false) Object foo() { return null; } @Bean(autowireCandidate=false) Object foo() { return null; }
} }
@ -55,7 +55,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void initMethodMetadataIsPropagated() { void initMethodMetadataIsPropagated() {
@Configuration class Config { @Configuration class Config {
@Bean(initMethod="start") Object foo() { return null; } @Bean(initMethod="start") Object foo() { return null; }
} }
@ -64,7 +64,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void destroyMethodMetadataIsPropagated() { void destroyMethodMetadataIsPropagated() {
@Configuration class Config { @Configuration class Config {
@Bean(destroyMethod="destroy") Object foo() { return null; } @Bean(destroyMethod="destroy") Object foo() { return null; }
} }
@ -73,7 +73,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void dependsOnMetadataIsPropagated() { void dependsOnMetadataIsPropagated() {
@Configuration class Config { @Configuration class Config {
@Bean() @DependsOn({"bar", "baz"}) Object foo() { return null; } @Bean() @DependsOn({"bar", "baz"}) Object foo() { return null; }
} }
@ -82,7 +82,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void primaryMetadataIsPropagated() { void primaryMetadataIsPropagated() {
@Configuration class Config { @Configuration class Config {
@Primary @Bean @Primary @Bean
Object foo() { return null; } Object foo() { return null; }
@ -92,7 +92,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void primaryMetadataIsFalseByDefault() { void primaryMetadataIsFalseByDefault() {
@Configuration class Config { @Configuration class Config {
@Bean Object foo() { return null; } @Bean Object foo() { return null; }
} }
@ -101,7 +101,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void lazyMetadataIsPropagated() { void lazyMetadataIsPropagated() {
@Configuration class Config { @Configuration class Config {
@Lazy @Bean @Lazy @Bean
Object foo() { return null; } Object foo() { return null; }
@ -111,7 +111,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void lazyMetadataIsFalseByDefault() { void lazyMetadataIsFalseByDefault() {
@Configuration class Config { @Configuration class Config {
@Bean Object foo() { return null; } @Bean Object foo() { return null; }
} }
@ -120,7 +120,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void defaultLazyConfigurationPropagatesToIndividualBeans() { void defaultLazyConfigurationPropagatesToIndividualBeans() {
@Lazy @Configuration class Config { @Lazy @Configuration class Config {
@Bean Object foo() { return null; } @Bean Object foo() { return null; }
} }
@ -129,7 +129,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void eagerBeanOverridesDefaultLazyConfiguration() { void eagerBeanOverridesDefaultLazyConfiguration() {
@Lazy @Configuration class Config { @Lazy @Configuration class Config {
@Lazy(false) @Bean Object foo() { return null; } @Lazy(false) @Bean Object foo() { return null; }
} }
@ -138,7 +138,7 @@ public class BeanAnnotationAttributePropagationTests {
} }
@Test @Test
public void eagerConfigurationProducesEagerBeanDefinitions() { void eagerConfigurationProducesEagerBeanDefinitions() {
@Lazy(false) @Configuration class Config { // will probably never happen, doesn't make much sense @Lazy(false) @Configuration class Config { // will probably never happen, doesn't make much sense
@Bean Object foo() { return null; } @Bean Object foo() { return null; }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
*/ */
public class ConfigurationClassWithPlaceholderConfigurerBeanTests { class ConfigurationClassWithPlaceholderConfigurerBeanTests {
/** /**
* Test which proves that a non-static property placeholder bean cannot be declared * Test which proves that a non-static property placeholder bean cannot be declared

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ImportAnnotationDetectionTests { public class ImportAnnotationDetectionTests {
@Test @Test
public void multipleMetaImportsAreProcessed() { void multipleMetaImportsAreProcessed() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiMetaImportConfig.class); ctx.register(MultiMetaImportConfig.class);
ctx.refresh(); ctx.refresh();
@ -53,7 +53,7 @@ public class ImportAnnotationDetectionTests {
} }
@Test @Test
public void localAndMetaImportsAreProcessed() { void localAndMetaImportsAreProcessed() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiMetaImportConfigWithLocalImport.class); ctx.register(MultiMetaImportConfigWithLocalImport.class);
ctx.refresh(); ctx.refresh();
@ -63,7 +63,7 @@ public class ImportAnnotationDetectionTests {
} }
@Test @Test
public void localImportIsProcessedLast() { void localImportIsProcessedLast() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiMetaImportConfigWithLocalImportWithBeanOverride.class); ctx.register(MultiMetaImportConfigWithLocalImportWithBeanOverride.class);
ctx.refresh(); ctx.refresh();
@ -73,7 +73,7 @@ public class ImportAnnotationDetectionTests {
} }
@Test @Test
public void importFromBean() throws Exception { void importFromBean() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportFromBean.class); ctx.register(ImportFromBean.class);
ctx.refresh(); ctx.refresh();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,10 +42,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
*/ */
public class ImportResourceTests { class ImportResourceTests {
@Test @Test
public void importXml() { void importXml() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
assertThat(ctx.containsBean("javaDeclaredBean")).as("did not contain java-declared bean").isTrue(); assertThat(ctx.containsBean("javaDeclaredBean")).as("did not contain java-declared bean").isTrue();
assertThat(ctx.containsBean("xmlDeclaredBean")).as("did not contain xml-declared bean").isTrue(); assertThat(ctx.containsBean("xmlDeclaredBean")).as("did not contain xml-declared bean").isTrue();
@ -55,14 +55,14 @@ public class ImportResourceTests {
} }
@Test @Test
public void importXmlIsInheritedFromSuperclassDeclarations() { void importXmlIsInheritedFromSuperclassDeclarations() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class);
assertThat(ctx.containsBean("xmlDeclaredBean")).isTrue(); assertThat(ctx.containsBean("xmlDeclaredBean")).isTrue();
ctx.close(); ctx.close();
} }
@Test @Test
public void importXmlIsMergedFromSuperclassDeclarations() { void importXmlIsMergedFromSuperclassDeclarations() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class);
assertThat(ctx.containsBean("secondLevelXmlDeclaredBean")).as("failed to pick up second-level-declared XML bean").isTrue(); assertThat(ctx.containsBean("secondLevelXmlDeclaredBean")).as("failed to pick up second-level-declared XML bean").isTrue();
assertThat(ctx.containsBean("xmlDeclaredBean")).as("failed to pick up parent-declared XML bean").isTrue(); assertThat(ctx.containsBean("xmlDeclaredBean")).as("failed to pick up parent-declared XML bean").isTrue();
@ -70,7 +70,7 @@ public class ImportResourceTests {
} }
@Test @Test
public void importXmlWithNamespaceConfig() { void importXmlWithNamespaceConfig() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class);
Object bean = ctx.getBean("proxiedXmlBean"); Object bean = ctx.getBean("proxiedXmlBean");
assertThat(AopUtils.isAopProxy(bean)).isTrue(); assertThat(AopUtils.isAopProxy(bean)).isTrue();
@ -78,7 +78,7 @@ public class ImportResourceTests {
} }
@Test @Test
public void importXmlWithOtherConfigurationClass() { void importXmlWithOtherConfigurationClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithConfigurationClass.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithConfigurationClass.class);
assertThat(ctx.containsBean("javaDeclaredBean")).as("did not contain java-declared bean").isTrue(); assertThat(ctx.containsBean("javaDeclaredBean")).as("did not contain java-declared bean").isTrue();
assertThat(ctx.containsBean("xmlDeclaredBean")).as("did not contain xml-declared bean").isTrue(); assertThat(ctx.containsBean("xmlDeclaredBean")).as("did not contain xml-declared bean").isTrue();
@ -88,7 +88,7 @@ public class ImportResourceTests {
} }
@Test @Test
public void importWithPlaceholder() throws Exception { void importWithPlaceholder() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
PropertySource<?> propertySource = new MapPropertySource("test", PropertySource<?> propertySource = new MapPropertySource("test",
Collections.<String, Object> singletonMap("test", "springframework")); Collections.<String, Object> singletonMap("test", "springframework"));
@ -100,7 +100,7 @@ public class ImportResourceTests {
} }
@Test @Test
public void importXmlWithAutowiredConfig() { void importXmlWithAutowiredConfig() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class);
String name = ctx.getBean("xmlBeanName", String.class); String name = ctx.getBean("xmlBeanName", String.class);
assertThat(name).isEqualTo("xml.declared"); assertThat(name).isEqualTo("xml.declared");
@ -108,7 +108,7 @@ public class ImportResourceTests {
} }
@Test @Test
public void importNonXmlResource() { void importNonXmlResource() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class);
assertThat(ctx.containsBean("propertiesDeclaredBean")).isTrue(); assertThat(ctx.containsBean("propertiesDeclaredBean")).isTrue();
ctx.close(); ctx.close();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,12 +33,12 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
public class ImportWithConditionTests { class ImportWithConditionTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test @Test
public void conditionalThenUnconditional() throws Exception { void conditionalThenUnconditional() {
this.context.register(ConditionalThenUnconditional.class); this.context.register(ConditionalThenUnconditional.class);
this.context.refresh(); this.context.refresh();
assertThat(this.context.containsBean("beanTwo")).isFalse(); assertThat(this.context.containsBean("beanTwo")).isFalse();
@ -46,7 +46,7 @@ public class ImportWithConditionTests {
} }
@Test @Test
public void unconditionalThenConditional() throws Exception { void unconditionalThenConditional() {
this.context.register(UnconditionalThenConditional.class); this.context.register(UnconditionalThenConditional.class);
this.context.refresh(); this.context.refresh();
assertThat(this.context.containsBean("beanTwo")).isFalse(); assertThat(this.context.containsBean("beanTwo")).isFalse();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Costin Leau * @author Costin Leau
* @author Chris Beams * @author Chris Beams
*/ */
public class ScopingTests { class ScopingTests {
public static String flag = "1"; public static String flag = "1";
@ -61,13 +61,13 @@ public class ScopingTests {
@BeforeEach @BeforeEach
public void setUp() throws Exception { void setUp() {
customScope = new CustomScope(); customScope = new CustomScope();
ctx = createContext(ScopedConfigurationClass.class); ctx = createContext(ScopedConfigurationClass.class);
} }
@AfterEach @AfterEach
public void tearDown() throws Exception { void tearDown() {
if (ctx != null) { if (ctx != null) {
ctx.close(); ctx.close();
} }
@ -86,16 +86,16 @@ public class ScopingTests {
@Test @Test
public void testScopeOnClasses() throws Exception { void testScopeOnClasses() {
genericTestScope("scopedClass"); genericTestScope("scopedClass");
} }
@Test @Test
public void testScopeOnInterfaces() throws Exception { void testScopeOnInterfaces() {
genericTestScope("scopedInterface"); genericTestScope("scopedInterface");
} }
private void genericTestScope(String beanName) throws Exception { private void genericTestScope(String beanName) {
String message = "scope is ignored"; String message = "scope is ignored";
Object bean1 = ctx.getBean(beanName); Object bean1 = ctx.getBean(beanName);
Object bean2 = ctx.getBean(beanName); Object bean2 = ctx.getBean(beanName);
@ -130,7 +130,7 @@ public class ScopingTests {
} }
@Test @Test
public void testSameScopeOnDifferentBeans() throws Exception { void testSameScopeOnDifferentBeans() {
Object beanAInScope = ctx.getBean("scopedClass"); Object beanAInScope = ctx.getBean("scopedClass");
Object beanBInScope = ctx.getBean("scopedInterface"); Object beanBInScope = ctx.getBean("scopedInterface");
@ -147,7 +147,7 @@ public class ScopingTests {
} }
@Test @Test
public void testRawScopes() throws Exception { void testRawScopes() {
String beanName = "scopedProxyInterface"; String beanName = "scopedProxyInterface";
// get hidden bean // get hidden bean
@ -158,7 +158,7 @@ public class ScopingTests {
} }
@Test @Test
public void testScopedProxyConfiguration() throws Exception { void testScopedProxyConfiguration() {
TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedInterfaceDep"); TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedInterfaceDep");
ITestBean spouse = singleton.getSpouse(); ITestBean spouse = singleton.getSpouse();
boolean condition = spouse instanceof ScopedObject; boolean condition = spouse instanceof ScopedObject;
@ -191,7 +191,7 @@ public class ScopingTests {
} }
@Test @Test
public void testScopedProxyConfigurationWithClasses() throws Exception { void testScopedProxyConfigurationWithClasses() {
TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedClassDep"); TestBean singleton = (TestBean) ctx.getBean("singletonWithScopedClassDep");
ITestBean spouse = singleton.getSpouse(); ITestBean spouse = singleton.getSpouse();
boolean condition = spouse instanceof ScopedObject; boolean condition = spouse instanceof ScopedObject;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Oliver Gierke * @author Oliver Gierke
* @author Phillip Webb * @author Phillip Webb
*/ */
public class Spr10668Tests { class Spr10668Tests {
@Test @Test
public void testSelfInjectHierarchy() throws Exception { void testSelfInjectHierarchy() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ChildConfig.class); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ChildConfig.class);
assertThat(context.getBean(MyComponent.class)).isNotNull(); assertThat(context.getBean(MyComponent.class)).isNotNull();
context.close(); context.close();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Phillip Webb * @author Phillip Webb
*/ */
public class Spr10744Tests { class Spr10744Tests {
private static int createCount = 0; private static int createCount = 0;
@ -41,7 +41,7 @@ public class Spr10744Tests {
@Test @Test
public void testSpr10744() throws Exception { void testSpr10744() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.getBeanFactory().registerScope("myTestScope", new MyTestScope()); context.getBeanFactory().registerScope("myTestScope", new MyTestScope());
context.register(MyTestConfiguration.class); context.register(MyTestConfiguration.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import org.springframework.context.support.GenericApplicationContext;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 3.0 * @since 3.0
*/ */
public class SpringAtInjectTckTests { class SpringAtInjectTckTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Test suite() { public static Test suite() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,11 +31,11 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Rob Winch * @author Rob Winch
*/ */
public class Spr10546Tests { class Spr10546Tests {
private ConfigurableApplicationContext context; private ConfigurableApplicationContext context;
@AfterEach @AfterEach
public void closeContext() { void closeContext() {
if (context != null) { if (context != null) {
context.close(); context.close();
} }
@ -44,7 +44,7 @@ public class Spr10546Tests {
// These fail prior to fixing SPR-10546 // These fail prior to fixing SPR-10546
@Test @Test
public void enclosingConfigFirstParentDefinesBean() { void enclosingConfigFirstParentDefinesBean() {
assertLoadsMyBean(AEnclosingConfig.class,AEnclosingConfig.ChildConfig.class); assertLoadsMyBean(AEnclosingConfig.class,AEnclosingConfig.ChildConfig.class);
} }
@ -59,7 +59,7 @@ public class Spr10546Tests {
* classpath scanning implementation being used by the author of this test. * classpath scanning implementation being used by the author of this test.
*/ */
@Test @Test
public void enclosingConfigFirstParentDefinesBeanWithScanning() { void enclosingConfigFirstParentDefinesBeanWithScanning() {
AnnotationConfigApplicationContext ctx= new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx= new AnnotationConfigApplicationContext();
context = ctx; context = ctx;
ctx.scan(AEnclosingConfig.class.getPackage().getName()); ctx.scan(AEnclosingConfig.class.getPackage().getName());
@ -68,7 +68,7 @@ public class Spr10546Tests {
} }
@Test @Test
public void enclosingConfigFirstParentDefinesBeanWithImportResource() { void enclosingConfigFirstParentDefinesBeanWithImportResource() {
assertLoadsMyBean(AEnclosingWithImportResourceConfig.class,AEnclosingWithImportResourceConfig.ChildConfig.class); assertLoadsMyBean(AEnclosingWithImportResourceConfig.class,AEnclosingWithImportResourceConfig.ChildConfig.class);
} }
@ -79,7 +79,7 @@ public class Spr10546Tests {
} }
@Test @Test
public void enclosingConfigFirstParentDefinesBeanWithComponentScan() { void enclosingConfigFirstParentDefinesBeanWithComponentScan() {
assertLoadsMyBean(AEnclosingWithComponentScanConfig.class,AEnclosingWithComponentScanConfig.ChildConfig.class); assertLoadsMyBean(AEnclosingWithComponentScanConfig.class,AEnclosingWithComponentScanConfig.ChildConfig.class);
} }
@ -90,7 +90,7 @@ public class Spr10546Tests {
} }
@Test @Test
public void enclosingConfigFirstParentWithParentDefinesBean() { void enclosingConfigFirstParentWithParentDefinesBean() {
assertLoadsMyBean(AEnclosingWithGrandparentConfig.class,AEnclosingWithGrandparentConfig.ChildConfig.class); assertLoadsMyBean(AEnclosingWithGrandparentConfig.class,AEnclosingWithGrandparentConfig.ChildConfig.class);
} }
@ -101,7 +101,7 @@ public class Spr10546Tests {
} }
@Test @Test
public void importChildConfigThenChildConfig() { void importChildConfigThenChildConfig() {
assertLoadsMyBean(ImportChildConfig.class,ChildConfig.class); assertLoadsMyBean(ImportChildConfig.class,ChildConfig.class);
} }
@ -116,7 +116,7 @@ public class Spr10546Tests {
// These worked prior, but validating they continue to work // These worked prior, but validating they continue to work
@Test @Test
public void enclosingConfigFirstParentDefinesBeanWithImport() { void enclosingConfigFirstParentDefinesBeanWithImport() {
assertLoadsMyBean(AEnclosingWithImportConfig.class,AEnclosingWithImportConfig.ChildConfig.class); assertLoadsMyBean(AEnclosingWithImportConfig.class,AEnclosingWithImportConfig.ChildConfig.class);
} }
@ -127,17 +127,17 @@ public class Spr10546Tests {
} }
@Test @Test
public void childConfigFirst() { void childConfigFirst() {
assertLoadsMyBean(AEnclosingConfig.ChildConfig.class, AEnclosingConfig.class); assertLoadsMyBean(AEnclosingConfig.ChildConfig.class, AEnclosingConfig.class);
} }
@Test @Test
public void enclosingConfigOnly() { void enclosingConfigOnly() {
assertLoadsMyBean(AEnclosingConfig.class); assertLoadsMyBean(AEnclosingConfig.class);
} }
@Test @Test
public void childConfigOnly() { void childConfigOnly() {
assertLoadsMyBean(AEnclosingConfig.ChildConfig.class); assertLoadsMyBean(AEnclosingConfig.ChildConfig.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,10 +35,10 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class Spr12233Tests { class Spr12233Tests {
@Test @Test
public void spr12233() throws Exception { void spr12233() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PropertySourcesPlaceholderConfigurer.class); ctx.register(PropertySourcesPlaceholderConfigurer.class);
ctx.register(ImportConfiguration.class); ctx.register(ImportConfiguration.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -87,7 +87,7 @@ class AnnotationDrivenEventListenerTests {
@AfterEach @AfterEach
public void closeContext() { void closeContext() {
if (this.context != null) { if (this.context != null) {
this.context.close(); this.context.close();
} }
@ -196,8 +196,7 @@ class AnnotationDrivenEventListenerTests {
failingContext.register(BasicConfiguration.class, failingContext.register(BasicConfiguration.class,
InvalidMethodSignatureEventListener.class); InvalidMethodSignatureEventListener.class);
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(failingContext::refresh)
failingContext.refresh())
.withMessageContaining(InvalidMethodSignatureEventListener.class.getName()) .withMessageContaining(InvalidMethodSignatureEventListener.class.getName())
.withMessageContaining("cannotBeCalled"); .withMessageContaining("cannotBeCalled");
} }
@ -680,14 +679,14 @@ class AnnotationDrivenEventListenerTests {
List<Class<?>> allClasses = new ArrayList<>(); List<Class<?>> allClasses = new ArrayList<>();
allClasses.add(BasicConfiguration.class); allClasses.add(BasicConfiguration.class);
allClasses.addAll(Arrays.asList(classes)); allClasses.addAll(Arrays.asList(classes));
doLoad(allClasses.toArray(new Class<?>[allClasses.size()])); doLoad(allClasses.toArray(new Class<?>[0]));
} }
private void loadAsync(Class<?>... classes) { private void loadAsync(Class<?>... classes) {
List<Class<?>> allClasses = new ArrayList<>(); List<Class<?>> allClasses = new ArrayList<>();
allClasses.add(AsyncConfiguration.class); allClasses.add(AsyncConfiguration.class);
allClasses.addAll(Arrays.asList(classes)); allClasses.addAll(Arrays.asList(classes));
doLoad(allClasses.toArray(new Class<?>[allClasses.size()])); doLoad(allClasses.toArray(new Class<?>[0]));
} }
private void doLoad(Class<?>... classes) { private void doLoad(Class<?>... classes) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -78,10 +78,10 @@ import static org.springframework.context.support.AbstractApplicationContext.APP
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class ApplicationContextEventTests extends AbstractApplicationEventListenerTests { class ApplicationContextEventTests extends AbstractApplicationEventListenerTests {
@Test @Test
public void multicastSimpleEvent() { void multicastSimpleEvent() {
multicastEvent(true, ApplicationListener.class, multicastEvent(true, ApplicationListener.class,
new ContextRefreshedEvent(new StaticApplicationContext()), null); new ContextRefreshedEvent(new StaticApplicationContext()), null);
multicastEvent(true, ApplicationListener.class, multicastEvent(true, ApplicationListener.class,
@ -89,40 +89,40 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void multicastGenericEvent() { void multicastGenericEvent() {
multicastEvent(true, StringEventListener.class, createGenericTestEvent("test"), multicastEvent(true, StringEventListener.class, createGenericTestEvent("test"),
ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class));
} }
@Test @Test
public void multicastGenericEventWrongType() { void multicastGenericEventWrongType() {
multicastEvent(false, StringEventListener.class, createGenericTestEvent(123L), multicastEvent(false, StringEventListener.class, createGenericTestEvent(123L),
ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class));
} }
@Test @Test
public void multicastGenericEventWildcardSubType() { void multicastGenericEventWildcardSubType() {
multicastEvent(false, StringEventListener.class, createGenericTestEvent("test"), multicastEvent(false, StringEventListener.class, createGenericTestEvent("test"),
getGenericApplicationEventType("wildcardEvent")); getGenericApplicationEventType("wildcardEvent"));
} }
@Test @Test
public void multicastConcreteTypeGenericListener() { void multicastConcreteTypeGenericListener() {
multicastEvent(true, StringEventListener.class, new StringEvent(this, "test"), null); multicastEvent(true, StringEventListener.class, new StringEvent(this, "test"), null);
} }
@Test @Test
public void multicastConcreteWrongTypeGenericListener() { void multicastConcreteWrongTypeGenericListener() {
multicastEvent(false, StringEventListener.class, new LongEvent(this, 123L), null); multicastEvent(false, StringEventListener.class, new LongEvent(this, 123L), null);
} }
@Test @Test
public void multicastSmartGenericTypeGenericListener() { void multicastSmartGenericTypeGenericListener() {
multicastEvent(true, StringEventListener.class, new SmartGenericTestEvent<>(this, "test"), null); multicastEvent(true, StringEventListener.class, new SmartGenericTestEvent<>(this, "test"), null);
} }
@Test @Test
public void multicastSmartGenericWrongTypeGenericListener() { void multicastSmartGenericWrongTypeGenericListener() {
multicastEvent(false, StringEventListener.class, new SmartGenericTestEvent<>(this, 123L), null); multicastEvent(false, StringEventListener.class, new SmartGenericTestEvent<>(this, 123L), null);
} }
@ -144,7 +144,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void simpleApplicationEventMulticasterWithTaskExecutor() { void simpleApplicationEventMulticasterWithTaskExecutor() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(); ApplicationListener<ApplicationEvent> listener = mock();
willReturn(true).given(listener).supportsAsyncExecution(); willReturn(true).given(listener).supportsAsyncExecution();
@ -165,7 +165,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void simpleApplicationEventMulticasterWithTaskExecutorAndNonAsyncListener() { void simpleApplicationEventMulticasterWithTaskExecutorAndNonAsyncListener() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(); ApplicationListener<ApplicationEvent> listener = mock();
willReturn(false).given(listener).supportsAsyncExecution(); willReturn(false).given(listener).supportsAsyncExecution();
@ -186,7 +186,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void simpleApplicationEventMulticasterWithException() { void simpleApplicationEventMulticasterWithException() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(); ApplicationListener<ApplicationEvent> listener = mock();
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext()); ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
@ -202,7 +202,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void simpleApplicationEventMulticasterWithErrorHandler() { void simpleApplicationEventMulticasterWithErrorHandler() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ApplicationListener<ApplicationEvent> listener = mock(); ApplicationListener<ApplicationEvent> listener = mock();
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext()); ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
@ -216,7 +216,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void orderedListeners() { void orderedListeners() {
MyOrderedListener1 listener1 = new MyOrderedListener1(); MyOrderedListener1 listener1 = new MyOrderedListener1();
MyOrderedListener2 listener2 = new MyOrderedListener2(listener1); MyOrderedListener2 listener2 = new MyOrderedListener2(listener1);
@ -230,7 +230,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void orderedListenersWithAnnotation() { void orderedListenersWithAnnotation() {
MyOrderedListener3 listener1 = new MyOrderedListener3(); MyOrderedListener3 listener1 = new MyOrderedListener3();
MyOrderedListener4 listener2 = new MyOrderedListener4(listener1); MyOrderedListener4 listener2 = new MyOrderedListener4(listener1);
@ -289,7 +289,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
* were added to the list of application listener beans twice (both proxy and unwrapped target). * were added to the list of application listener beans twice (both proxy and unwrapped target).
*/ */
@Test @Test
public void eventForSelfInjectedProxiedListenerFiredOnlyOnce() { void eventForSelfInjectedProxiedListenerFiredOnlyOnce() {
AbstractApplicationContext context = new AnnotationConfigApplicationContext( AbstractApplicationContext context = new AnnotationConfigApplicationContext(
MyAspect.class, MyEventListener.class, MyEventPublisher.class); MyAspect.class, MyEventListener.class, MyEventPublisher.class);
context.getBean(MyEventPublisher.class).publishMyEvent("hello"); context.getBean(MyEventPublisher.class).publishMyEvent("hello");
@ -298,7 +298,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void testEventPublicationInterceptor() throws Throwable { void testEventPublicationInterceptor() throws Throwable {
MethodInvocation invocation = mock(); MethodInvocation invocation = mock();
ApplicationContext ctx = mock(); ApplicationContext ctx = mock();
@ -314,7 +314,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void listenersInApplicationContext() { void listenersInApplicationContext() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("listener1", new RootBeanDefinition(MyOrderedListener1.class)); context.registerBeanDefinition("listener1", new RootBeanDefinition(MyOrderedListener1.class));
RootBeanDefinition listener2 = new RootBeanDefinition(MyOrderedListener2.class); RootBeanDefinition listener2 = new RootBeanDefinition(MyOrderedListener2.class);
@ -351,7 +351,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void listenersInApplicationContextWithPayloadEvents() { void listenersInApplicationContextWithPayloadEvents() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("listener", new RootBeanDefinition(MyPayloadListener.class)); context.registerBeanDefinition("listener", new RootBeanDefinition(MyPayloadListener.class));
context.refresh(); context.refresh();
@ -370,7 +370,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void listenersInApplicationContextWithNestedChild() { void listenersInApplicationContextWithNestedChild() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition nestedChild = new RootBeanDefinition(StaticApplicationContext.class); RootBeanDefinition nestedChild = new RootBeanDefinition(StaticApplicationContext.class);
nestedChild.getPropertyValues().add("parent", context); nestedChild.getPropertyValues().add("parent", context);
@ -394,7 +394,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void nonSingletonListenerInApplicationContext() { void nonSingletonListenerInApplicationContext() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition listener = new RootBeanDefinition(MyNonSingletonListener.class); RootBeanDefinition listener = new RootBeanDefinition(MyNonSingletonListener.class);
listener.setScope(BeanDefinition.SCOPE_PROTOTYPE); listener.setScope(BeanDefinition.SCOPE_PROTOTYPE);
@ -426,7 +426,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void listenerAndBroadcasterWithCircularReference() { void listenerAndBroadcasterWithCircularReference() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("broadcaster", new RootBeanDefinition(BeanThatBroadcasts.class)); context.registerBeanDefinition("broadcaster", new RootBeanDefinition(BeanThatBroadcasts.class));
RootBeanDefinition listenerDef = new RootBeanDefinition(BeanThatListens.class); RootBeanDefinition listenerDef = new RootBeanDefinition(BeanThatListens.class);
@ -442,7 +442,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void innerBeanAsListener() { void innerBeanAsListener() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition listenerDef = new RootBeanDefinition(TestBean.class); RootBeanDefinition listenerDef = new RootBeanDefinition(TestBean.class);
listenerDef.getPropertyValues().add("friends", new RootBeanDefinition(BeanThatListens.class)); listenerDef.getPropertyValues().add("friends", new RootBeanDefinition(BeanThatListens.class));
@ -458,7 +458,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void anonymousClassAsListener() { void anonymousClassAsListener() {
final Set<MyEvent> seenEvents = new HashSet<>(); final Set<MyEvent> seenEvents = new HashSet<>();
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
context.addApplicationListener((MyEvent event) -> seenEvents.add(event)); context.addApplicationListener((MyEvent event) -> seenEvents.add(event));
@ -475,7 +475,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void lambdaAsListener() { void lambdaAsListener() {
final Set<MyEvent> seenEvents = new HashSet<>(); final Set<MyEvent> seenEvents = new HashSet<>();
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
ApplicationListener<MyEvent> listener = seenEvents::add; ApplicationListener<MyEvent> listener = seenEvents::add;
@ -493,7 +493,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void lambdaAsListenerWithErrorHandler() { void lambdaAsListenerWithErrorHandler() {
final Set<MyEvent> seenEvents = new HashSet<>(); final Set<MyEvent> seenEvents = new HashSet<>();
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster(); SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster();
@ -514,7 +514,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void lambdaAsListenerWithJava8StyleClassCastMessage() { void lambdaAsListenerWithJava8StyleClassCastMessage() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
ApplicationListener<ApplicationEvent> listener = ApplicationListener<ApplicationEvent> listener =
event -> { throw new ClassCastException(event.getClass().getName()); }; event -> { throw new ClassCastException(event.getClass().getName()); };
@ -526,7 +526,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void lambdaAsListenerWithJava9StyleClassCastMessage() { void lambdaAsListenerWithJava9StyleClassCastMessage() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
ApplicationListener<ApplicationEvent> listener = ApplicationListener<ApplicationEvent> listener =
event -> { throw new ClassCastException("spring.context/" + event.getClass().getName()); }; event -> { throw new ClassCastException("spring.context/" + event.getClass().getName()); };
@ -552,7 +552,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void beanPostProcessorPublishesEvents() { void beanPostProcessorPublishesEvents() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class)); context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class));
context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class)); context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class));
@ -567,7 +567,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void initMethodPublishesEvent() { void initMethodPublishesEvent() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class)); context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class));
context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class)); context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class));
@ -582,7 +582,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Test @Test
public void initMethodPublishesAsyncEvent() { void initMethodPublishesAsyncEvent() {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class)); context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class));
context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class)); context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class));
@ -743,7 +743,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
} }
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() {
this.publisher.publishEvent(new MyEvent(this)); this.publisher.publishEvent(new MyEvent(this));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,7 +51,7 @@ import static org.mockito.Mockito.verify;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Simon Baslé * @author Simon Baslé
*/ */
public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEventListenerTests { class ApplicationListenerMethodAdapterTests extends AbstractApplicationEventListenerTests {
private final SampleEvents sampleEvents = spy(new SampleEvents()); private final SampleEvents sampleEvents = spy(new SampleEvents());
@ -59,89 +59,89 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void rawListener() { void rawListener() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class);
supportsEventType(true, method, ResolvableType.forClass(ApplicationEvent.class)); supportsEventType(true, method, ResolvableType.forClass(ApplicationEvent.class));
} }
@Test @Test
public void rawListenerWithGenericEvent() { void rawListenerWithGenericEvent() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class);
supportsEventType(true, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); supportsEventType(true, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class));
} }
@Test @Test
public void genericListener() { void genericListener() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
supportsEventType(true, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); supportsEventType(true, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class));
} }
@Test @Test
public void genericListenerWrongParameterizedType() { void genericListenerWrongParameterizedType() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
supportsEventType(false, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); supportsEventType(false, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class));
} }
@Test @Test
public void genericListenerWithUnresolvedGenerics() { void genericListenerWithUnresolvedGenerics() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
supportsEventType(true, method, ResolvableType.forClass(GenericTestEvent.class)); supportsEventType(true, method, ResolvableType.forClass(GenericTestEvent.class));
} }
@Test @Test
public void listenerWithPayloadAndGenericInformation() { void listenerWithPayloadAndGenericInformation() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
supportsEventType(true, method, createPayloadEventType(String.class)); supportsEventType(true, method, createPayloadEventType(String.class));
} }
@Test @Test
public void listenerWithInvalidPayloadAndGenericInformation() { void listenerWithInvalidPayloadAndGenericInformation() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
supportsEventType(false, method, createPayloadEventType(Integer.class)); supportsEventType(false, method, createPayloadEventType(Integer.class));
} }
@Test @Test
public void listenerWithPayloadTypeErasure() { // Always accept such event when the type is unknown void listenerWithPayloadTypeErasure() { // Always accept such event when the type is unknown
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
supportsEventType(true, method, ResolvableType.forClass(PayloadApplicationEvent.class)); supportsEventType(true, method, ResolvableType.forClass(PayloadApplicationEvent.class));
} }
@Test @Test
public void listenerWithSubTypeSeveralGenerics() { void listenerWithSubTypeSeveralGenerics() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
supportsEventType(true, method, ResolvableType.forClass(PayloadTestEvent.class)); supportsEventType(true, method, ResolvableType.forClass(PayloadTestEvent.class));
} }
@Test @Test
public void listenerWithSubTypeSeveralGenericsResolved() { void listenerWithSubTypeSeveralGenericsResolved() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
supportsEventType(true, method, ResolvableType.forClass(PayloadStringTestEvent.class)); supportsEventType(true, method, ResolvableType.forClass(PayloadStringTestEvent.class));
} }
@Test @Test
public void listenerWithAnnotationValue() { void listenerWithAnnotationValue() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationValue"); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationValue");
supportsEventType(true, method, createPayloadEventType(String.class)); supportsEventType(true, method, createPayloadEventType(String.class));
} }
@Test @Test
public void listenerWithAnnotationClasses() { void listenerWithAnnotationClasses() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationClasses"); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationClasses");
supportsEventType(true, method, createPayloadEventType(String.class)); supportsEventType(true, method, createPayloadEventType(String.class));
} }
@Test @Test
public void listenerWithAnnotationValueAndParameter() { void listenerWithAnnotationValueAndParameter() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleStringAnnotationValueAndParameter", String.class); SampleEvents.class, "handleStringAnnotationValueAndParameter", String.class);
supportsEventType(true, method, createPayloadEventType(String.class)); supportsEventType(true, method, createPayloadEventType(String.class));
} }
@Test @Test
public void listenerWithSeveralTypes() { void listenerWithSeveralTypes() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger"); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger");
supportsEventType(true, method, createPayloadEventType(String.class)); supportsEventType(true, method, createPayloadEventType(String.class));
supportsEventType(true, method, createPayloadEventType(Integer.class)); supportsEventType(true, method, createPayloadEventType(Integer.class));
@ -149,27 +149,27 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void listenerWithTooManyParameters() { void listenerWithTooManyParameters() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "tooManyParameters", String.class, String.class); SampleEvents.class, "tooManyParameters", String.class, String.class);
assertThatIllegalStateException().isThrownBy(() -> createTestInstance(method)); assertThatIllegalStateException().isThrownBy(() -> createTestInstance(method));
} }
@Test @Test
public void listenerWithNoParameter() { void listenerWithNoParameter() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "noParameter"); Method method = ReflectionUtils.findMethod(SampleEvents.class, "noParameter");
assertThatIllegalStateException().isThrownBy(() -> createTestInstance(method)); assertThatIllegalStateException().isThrownBy(() -> createTestInstance(method));
} }
@Test @Test
public void listenerWithMoreThanOneParameter() { void listenerWithMoreThanOneParameter() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "moreThanOneParameter", String.class, Integer.class); SampleEvents.class, "moreThanOneParameter", String.class, Integer.class);
assertThatIllegalStateException().isThrownBy(() -> createTestInstance(method)); assertThatIllegalStateException().isThrownBy(() -> createTestInstance(method));
} }
@Test @Test
public void defaultOrder() { void defaultOrder() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
ApplicationListenerMethodAdapter adapter = createTestInstance(method); ApplicationListenerMethodAdapter adapter = createTestInstance(method);
@ -177,7 +177,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void specifiedOrder() { void specifiedOrder() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleRaw", ApplicationEvent.class); SampleEvents.class, "handleRaw", ApplicationEvent.class);
ApplicationListenerMethodAdapter adapter = createTestInstance(method); ApplicationListenerMethodAdapter adapter = createTestInstance(method);
@ -185,7 +185,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListener() { void invokeListener() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("test"); GenericTestEvent<String> event = createGenericTestEvent("test");
@ -194,7 +194,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithGenericEvent() { void invokeListenerWithGenericEvent() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
GenericTestEvent<String> event = new SmartGenericTestEvent<>(this, "test"); GenericTestEvent<String> event = new SmartGenericTestEvent<>(this, "test");
@ -203,7 +203,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithGenericPayload() { void invokeListenerWithGenericPayload() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericStringPayload", EntityWrapper.class); SampleEvents.class, "handleGenericStringPayload", EntityWrapper.class);
EntityWrapper<String> payload = new EntityWrapper<>("test"); EntityWrapper<String> payload = new EntityWrapper<>("test");
@ -212,7 +212,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithWrongGenericPayload() { void invokeListenerWithWrongGenericPayload() {
Method method = ReflectionUtils.findMethod Method method = ReflectionUtils.findMethod
(SampleEvents.class, "handleGenericStringPayload", EntityWrapper.class); (SampleEvents.class, "handleGenericStringPayload", EntityWrapper.class);
EntityWrapper<Integer> payload = new EntityWrapper<>(123); EntityWrapper<Integer> payload = new EntityWrapper<>(123);
@ -221,7 +221,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithAnyGenericPayload() { void invokeListenerWithAnyGenericPayload() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericAnyPayload", EntityWrapper.class); SampleEvents.class, "handleGenericAnyPayload", EntityWrapper.class);
EntityWrapper<String> payload = new EntityWrapper<>("test"); EntityWrapper<String> payload = new EntityWrapper<>("test");
@ -230,7 +230,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerRuntimeException() { void invokeListenerRuntimeException() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "generateRuntimeException", GenericTestEvent.class); SampleEvents.class, "generateRuntimeException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail"); GenericTestEvent<String> event = createGenericTestEvent("fail");
@ -242,7 +242,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerCheckedException() { void invokeListenerCheckedException() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "generateCheckedException", GenericTestEvent.class); SampleEvents.class, "generateCheckedException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail"); GenericTestEvent<String> event = createGenericTestEvent("fail");
@ -253,7 +253,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerInvalidProxy() { void invokeListenerInvalidProxy() {
Object target = new InvalidProxyTestBean(); Object target = new InvalidProxyTestBean();
ProxyFactory proxyFactory = new ProxyFactory(); ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(target); proxyFactory.setTarget(target);
@ -270,7 +270,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithPayload() { void invokeListenerWithPayload() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
@ -278,7 +278,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithPayloadWrongType() { void invokeListenerWithPayloadWrongType() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
PayloadApplicationEvent<Long> event = new PayloadApplicationEvent<>(this, 123L); PayloadApplicationEvent<Long> event = new PayloadApplicationEvent<>(this, 123L);
invokeListener(method, event); invokeListener(method, event);
@ -286,7 +286,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithAnnotationValue() { void invokeListenerWithAnnotationValue() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationClasses"); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationClasses");
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
@ -294,7 +294,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithAnnotationValueAndParameter() { void invokeListenerWithAnnotationValueAndParameter() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleStringAnnotationValueAndParameter", String.class); SampleEvents.class, "handleStringAnnotationValueAndParameter", String.class);
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
@ -303,7 +303,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void invokeListenerWithSeveralTypes() { void invokeListenerWithSeveralTypes() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger"); Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger");
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
@ -317,7 +317,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
@Test @Test
public void beanInstanceRetrievedAtEveryInvocation() { void beanInstanceRetrievedAtEveryInvocation() {
Method method = ReflectionUtils.findMethod( Method method = ReflectionUtils.findMethod(
SampleEvents.class, "handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
given(this.context.getBean("testBean")).willReturn(this.sampleEvents); given(this.context.getBean("testBean")).willReturn(this.sampleEvents);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@ import static org.mockito.Mockito.verify;
/** /**
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class GenericApplicationListenerAdapterTests extends AbstractApplicationEventListenerTests { class GenericApplicationListenerAdapterTests extends AbstractApplicationEventListenerTests {
@Test @Test
public void supportsEventTypeWithSmartApplicationListener() { void supportsEventTypeWithSmartApplicationListener() {
SmartApplicationListener smartListener = mock(); SmartApplicationListener smartListener = mock();
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener); GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
ResolvableType type = ResolvableType.forClass(ApplicationEvent.class); ResolvableType type = ResolvableType.forClass(ApplicationEvent.class);
@ -44,7 +44,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
} }
@Test @Test
public void supportsSourceTypeWithSmartApplicationListener() { void supportsSourceTypeWithSmartApplicationListener() {
SmartApplicationListener smartListener = mock(); SmartApplicationListener smartListener = mock();
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener); GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
listener.supportsSourceType(Object.class); listener.supportsSourceType(Object.class);
@ -52,7 +52,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
} }
@Test @Test
public void genericListenerStrictType() { void genericListenerStrictType() {
supportsEventType(true, StringEventListener.class, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); supportsEventType(true, StringEventListener.class, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class));
} }
@ -84,44 +84,44 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
} }
@Test @Test
public void genericListenerStrictTypeNotMatching() { void genericListenerStrictTypeNotMatching() {
supportsEventType(false, StringEventListener.class, ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); supportsEventType(false, StringEventListener.class, ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class));
} }
@Test @Test
public void genericListenerStrictTypeEventSubTypeNotMatching() { void genericListenerStrictTypeEventSubTypeNotMatching() {
LongEvent stringEvent = new LongEvent(this, 123L); LongEvent stringEvent = new LongEvent(this, 123L);
ResolvableType eventType = ResolvableType.forType(stringEvent.getClass()); ResolvableType eventType = ResolvableType.forType(stringEvent.getClass());
supportsEventType(false, StringEventListener.class, eventType); supportsEventType(false, StringEventListener.class, eventType);
} }
@Test @Test
public void genericListenerStrictTypeNotMatchTypeErasure() { void genericListenerStrictTypeNotMatchTypeErasure() {
GenericTestEvent<Long> longEvent = createGenericTestEvent(123L); GenericTestEvent<Long> longEvent = createGenericTestEvent(123L);
ResolvableType eventType = ResolvableType.forType(longEvent.getClass()); ResolvableType eventType = ResolvableType.forType(longEvent.getClass());
supportsEventType(false, StringEventListener.class, eventType); supportsEventType(false, StringEventListener.class, eventType);
} }
@Test @Test
public void genericListenerStrictTypeSubClass() { void genericListenerStrictTypeSubClass() {
supportsEventType(false, ObjectEventListener.class, supportsEventType(false, ObjectEventListener.class,
ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class));
} }
@Test @Test
public void genericListenerUpperBoundType() { void genericListenerUpperBoundType() {
supportsEventType(true, UpperBoundEventListener.class, supportsEventType(true, UpperBoundEventListener.class,
ResolvableType.forClassWithGenerics(GenericTestEvent.class, IllegalStateException.class)); ResolvableType.forClassWithGenerics(GenericTestEvent.class, IllegalStateException.class));
} }
@Test @Test
public void genericListenerUpperBoundTypeNotMatching() { void genericListenerUpperBoundTypeNotMatching() {
supportsEventType(false, UpperBoundEventListener.class, supportsEventType(false, UpperBoundEventListener.class,
ResolvableType.forClassWithGenerics(GenericTestEvent.class, IOException.class)); ResolvableType.forClassWithGenerics(GenericTestEvent.class, IOException.class));
} }
@Test @Test
public void genericListenerWildcardType() { void genericListenerWildcardType() {
supportsEventType(true, GenericEventListener.class, supportsEventType(true, GenericEventListener.class,
ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class));
} }
@ -134,7 +134,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
} }
@Test @Test
public void genericListenerRawType() { void genericListenerRawType() {
supportsEventType(true, RawApplicationListener.class, supportsEventType(true, RawApplicationListener.class,
ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Mark Fisher * @author Mark Fisher
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class LifecycleEventTests { class LifecycleEventTests {
@Test @Test
public void contextStartedEvent() { void contextStartedEvent() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("lifecycle", LifecycleTestBean.class); context.registerSingleton("lifecycle", LifecycleTestBean.class);
context.registerSingleton("listener", LifecycleListener.class); context.registerSingleton("listener", LifecycleListener.class);
@ -49,7 +49,7 @@ public class LifecycleEventTests {
} }
@Test @Test
public void contextStoppedEvent() { void contextStoppedEvent() {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("lifecycle", LifecycleTestBean.class); context.registerSingleton("lifecycle", LifecycleTestBean.class);
context.registerSingleton("listener", LifecycleListener.class); context.registerSingleton("listener", LifecycleListener.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -165,7 +165,7 @@ class PayloadApplicationEventTests {
void testProgrammaticEventListener() { void testProgrammaticEventListener() {
List<Auditable> events = new ArrayList<>(); List<Auditable> events = new ArrayList<>();
ApplicationListener<AuditablePayloadEvent<String>> listener = events::add; ApplicationListener<AuditablePayloadEvent<String>> listener = events::add;
ApplicationListener<AuditablePayloadEvent<Integer>> mismatch = (event -> event.getPayload()); ApplicationListener<AuditablePayloadEvent<Integer>> mismatch = (PayloadApplicationEvent::getPayload);
ConfigurableApplicationContext ac = new GenericApplicationContext(); ConfigurableApplicationContext ac = new GenericApplicationContext();
ac.addApplicationListener(listener); ac.addApplicationListener(listener);
@ -183,7 +183,7 @@ class PayloadApplicationEventTests {
void testProgrammaticEventListenerOnParentContext() { void testProgrammaticEventListenerOnParentContext() {
List<Auditable> events = new ArrayList<>(); List<Auditable> events = new ArrayList<>();
ApplicationListener<AuditablePayloadEvent<String>> listener = events::add; ApplicationListener<AuditablePayloadEvent<String>> listener = events::add;
ApplicationListener<AuditablePayloadEvent<Integer>> mismatch = (event -> event.getPayload()); ApplicationListener<AuditablePayloadEvent<Integer>> mismatch = (PayloadApplicationEvent::getPayload);
ConfigurableApplicationContext parent = new GenericApplicationContext(); ConfigurableApplicationContext parent = new GenericApplicationContext();
parent.addApplicationListener(listener); parent.addApplicationListener(listener);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,12 +35,12 @@ import static org.mockito.Mockito.verify;
/** /**
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class CachedExpressionEvaluatorTests { class CachedExpressionEvaluatorTests {
private final TestExpressionEvaluator expressionEvaluator = new TestExpressionEvaluator(); private final TestExpressionEvaluator expressionEvaluator = new TestExpressionEvaluator();
@Test @Test
public void parseNewExpression() { void parseNewExpression() {
Method method = ReflectionUtils.findMethod(getClass(), "toString"); Method method = ReflectionUtils.findMethod(getClass(), "toString");
Expression expression = expressionEvaluator.getTestExpression("true", method, getClass()); Expression expression = expressionEvaluator.getTestExpression("true", method, getClass());
hasParsedExpression("true"); hasParsedExpression("true");
@ -49,7 +49,7 @@ public class CachedExpressionEvaluatorTests {
} }
@Test @Test
public void cacheExpression() { void cacheExpression() {
Method method = ReflectionUtils.findMethod(getClass(), "toString"); Method method = ReflectionUtils.findMethod(getClass(), "toString");
expressionEvaluator.getTestExpression("true", method, getClass()); expressionEvaluator.getTestExpression("true", method, getClass());
@ -60,7 +60,7 @@ public class CachedExpressionEvaluatorTests {
} }
@Test @Test
public void cacheExpressionBasedOnConcreteType() { void cacheExpressionBasedOnConcreteType() {
Method method = ReflectionUtils.findMethod(getClass(), "toString"); Method method = ReflectionUtils.findMethod(getClass(), "toString");
expressionEvaluator.getTestExpression("true", method, getClass()); expressionEvaluator.getTestExpression("true", method, getClass());
expressionEvaluator.getTestExpression("true", method, Object.class); expressionEvaluator.getTestExpression("true", method, Object.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,10 +34,10 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.ge
* *
* @author Chris Beams * @author Chris Beams
*/ */
public class EnvironmentAccessorIntegrationTests { class EnvironmentAccessorIntegrationTests {
@Test @Test
public void braceAccess() { void braceAccess() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", bf.registerBeanDefinition("testBean",
genericBeanDefinition(TestBean.class) genericBeanDefinition(TestBean.class)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,7 +23,6 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.expression.FactoryBeanAccessTests.SimpleBeanResolver.CarFactoryBean; import org.springframework.context.expression.FactoryBeanAccessTests.SimpleBeanResolver.CarFactoryBean;
import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticApplicationContext;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
@ -37,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* *
* @author Andy Clement * @author Andy Clement
*/ */
public class FactoryBeanAccessTests { class FactoryBeanAccessTests {
@Test @Test
public void factoryBeanAccess() { // SPR9511 void factoryBeanAccess() { // SPR9511
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new SimpleBeanResolver()); context.setBeanResolver(new SimpleBeanResolver());
Expression expr = new SpelExpressionParser().parseRaw("@car.colour"); Expression expr = new SpelExpressionParser().parseRaw("@car.colour");
@ -110,8 +109,7 @@ public class FactoryBeanAccessTests {
} }
@Override @Override
public Object resolve(EvaluationContext context, String beanName) public Object resolve(EvaluationContext context, String beanName) {
throws AccessException {
return ac.getBean(beanName); return ac.getBean(beanName);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Andy Clement * @author Andy Clement
*/ */
public class MapAccessorTests { class MapAccessorTests {
@Test @Test
public void mapAccessorCompilable() { void mapAccessorCompilable() {
Map<String, Object> testMap = getSimpleTestMap(); Map<String, Object> testMap = getSimpleTestMap();
StandardEvaluationContext sec = new StandardEvaluationContext(); StandardEvaluationContext sec = new StandardEvaluationContext();
sec.addPropertyAccessor(new MapAccessor()); sec.addPropertyAccessor(new MapAccessor());

Some files were not shown because too many files have changed in this diff Show More