Skip to content

Commit 9a5891e

Browse files
committed
Explicitly close ApplicationContexts and clean up warnings in tests
This commit also ensures that various test methods actually test something now.
1 parent 64b64d9 commit 9a5891e

File tree

110 files changed

+1571
-1174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1571
-1174
lines changed

spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.aop.aspectj;
1818

19+
import org.junit.jupiter.api.AfterEach;
1920
import org.junit.jupiter.api.BeforeEach;
2021
import org.junit.jupiter.api.Test;
2122

@@ -37,7 +38,9 @@
3738
* @author Rod Johnson
3839
* @author Chris Beams
3940
*/
40-
public class AfterAdviceBindingTests {
41+
class AfterAdviceBindingTests {
42+
43+
private ClassPathXmlApplicationContext ctx;
4144

4245
private AdviceBindingCollaborator mockCollaborator;
4346

@@ -47,9 +50,8 @@ public class AfterAdviceBindingTests {
4750

4851

4952
@BeforeEach
50-
public void setup() throws Exception {
51-
ClassPathXmlApplicationContext ctx =
52-
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
53+
void setup() throws Exception {
54+
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
5355
AdviceBindingTestAspect afterAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
5456

5557
testBeanProxy = (ITestBean) ctx.getBean("testBean");
@@ -62,39 +64,44 @@ public void setup() throws Exception {
6264
afterAdviceAspect.setCollaborator(mockCollaborator);
6365
}
6466

67+
@AfterEach
68+
void tearDown() throws Exception {
69+
this.ctx.close();
70+
}
71+
6572

6673
@Test
67-
public void testOneIntArg() {
74+
void oneIntArg() {
6875
testBeanProxy.setAge(5);
6976
verify(mockCollaborator).oneIntArg(5);
7077
}
7178

7279
@Test
73-
public void testOneObjectArgBindingProxyWithThis() {
80+
void oneObjectArgBindingProxyWithThis() {
7481
testBeanProxy.getAge();
7582
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
7683
}
7784

7885
@Test
79-
public void testOneObjectArgBindingTarget() {
86+
void oneObjectArgBindingTarget() {
8087
testBeanProxy.getDoctor();
8188
verify(mockCollaborator).oneObjectArg(this.testBeanTarget);
8289
}
8390

8491
@Test
85-
public void testOneIntAndOneObjectArgs() {
92+
void oneIntAndOneObjectArgs() {
8693
testBeanProxy.setAge(5);
8794
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanProxy);
8895
}
8996

9097
@Test
91-
public void testNeedsJoinPoint() {
98+
void needsJoinPoint() {
9299
testBeanProxy.getAge();
93100
verify(mockCollaborator).needsJoinPoint("getAge");
94101
}
95102

96103
@Test
97-
public void testNeedsJoinPointStaticPart() {
104+
void needsJoinPointStaticPart() {
98105
testBeanProxy.getAge();
99106
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
100107
}

spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.aop.aspectj;
1818

19+
import org.junit.jupiter.api.AfterEach;
1920
import org.junit.jupiter.api.BeforeEach;
2021
import org.junit.jupiter.api.Test;
2122

@@ -39,7 +40,9 @@
3940
* @author Juergen Hoeller
4041
* @author Chris Beams
4142
*/
42-
public class AfterReturningAdviceBindingTests {
43+
class AfterReturningAdviceBindingTests {
44+
45+
private ClassPathXmlApplicationContext ctx;
4346

4447
private AfterReturningAdviceBindingTestAspect afterAdviceAspect;
4548

@@ -51,9 +54,8 @@ public class AfterReturningAdviceBindingTests {
5154

5255

5356
@BeforeEach
54-
public void setup() throws Exception {
55-
ClassPathXmlApplicationContext ctx =
56-
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
57+
void setup() throws Exception {
58+
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
5759

5860
afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect");
5961

@@ -67,79 +69,84 @@ public void setup() throws Exception {
6769
this.testBeanTarget = (TestBean) ((Advised)testBeanProxy).getTargetSource().getTarget();
6870
}
6971

72+
@AfterEach
73+
void tearDown() {
74+
this.ctx.close();
75+
}
76+
7077

7178
@Test
72-
public void testOneIntArg() {
79+
void oneIntArg() {
7380
testBeanProxy.setAge(5);
7481
verify(mockCollaborator).oneIntArg(5);
7582
}
7683

7784
@Test
78-
public void testOneObjectArg() {
85+
void oneObjectArg() {
7986
testBeanProxy.getAge();
8087
verify(mockCollaborator).oneObjectArg(this.testBeanProxy);
8188
}
8289

8390
@Test
84-
public void testOneIntAndOneObjectArgs() {
91+
void oneIntAndOneObjectArgs() {
8592
testBeanProxy.setAge(5);
8693
verify(mockCollaborator).oneIntAndOneObject(5,this.testBeanProxy);
8794
}
8895

8996
@Test
90-
public void testNeedsJoinPoint() {
97+
void needsJoinPoint() {
9198
testBeanProxy.getAge();
9299
verify(mockCollaborator).needsJoinPoint("getAge");
93100
}
94101

95102
@Test
96-
public void testNeedsJoinPointStaticPart() {
103+
void needsJoinPointStaticPart() {
97104
testBeanProxy.getAge();
98105
verify(mockCollaborator).needsJoinPointStaticPart("getAge");
99106
}
100107

101108
@Test
102-
public void testReturningString() {
109+
void returningString() {
103110
testBeanProxy.setName("adrian");
104111
testBeanProxy.getName();
105112
verify(mockCollaborator).oneString("adrian");
106113
}
107114

108115
@Test
109-
public void testReturningObject() {
116+
void returningObject() {
110117
testBeanProxy.returnsThis();
111118
verify(mockCollaborator).oneObjectArg(this.testBeanTarget);
112119
}
113120

114121
@Test
115-
public void testReturningBean() {
122+
void returningBean() {
116123
testBeanProxy.returnsThis();
117124
verify(mockCollaborator).oneTestBeanArg(this.testBeanTarget);
118125
}
119126

120127
@Test
121-
public void testReturningBeanArray() {
128+
void returningBeanArray() {
122129
this.testBeanTarget.setSpouse(new TestBean());
123130
ITestBean[] spouses = this.testBeanTarget.getSpouses();
124131
testBeanProxy.getSpouses();
125132
verify(mockCollaborator).testBeanArrayArg(spouses);
126133
}
127134

128135
@Test
129-
public void testNoInvokeWhenReturningParameterTypeDoesNotMatch() {
136+
void noInvokeWhenReturningParameterTypeDoesNotMatch() {
130137
testBeanProxy.setSpouse(this.testBeanProxy);
131138
testBeanProxy.getSpouse();
132139
verifyNoInteractions(mockCollaborator);
133140
}
134141

135142
@Test
136-
public void testReturningByType() {
143+
void returningByType() {
137144
testBeanProxy.returnsThis();
138145
verify(mockCollaborator).objectMatchNoArgs();
139146
}
140147

141148
@Test
142-
public void testReturningPrimitive() {
149+
void returningPrimitive() {
143150
testBeanProxy.setAge(20);
144151
testBeanProxy.haveBirthday();
145152
verify(mockCollaborator).oneInt(20);

spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.aop.aspectj;
1818

19+
import org.junit.jupiter.api.AfterEach;
1920
import org.junit.jupiter.api.BeforeEach;
2021
import org.junit.jupiter.api.Test;
2122

@@ -33,7 +34,9 @@
3334
* @author Adrian Colyer
3435
* @author Chris Beams
3536
*/
36-
public class AfterThrowingAdviceBindingTests {
37+
class AfterThrowingAdviceBindingTests {
38+
39+
private ClassPathXmlApplicationContext ctx;
3740

3841
private ITestBean testBean;
3942

@@ -43,9 +46,8 @@ public class AfterThrowingAdviceBindingTests {
4346

4447

4548
@BeforeEach
46-
public void setup() {
47-
ClassPathXmlApplicationContext ctx =
48-
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
49+
void setup() {
50+
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
4951

5052
testBean = (ITestBean) ctx.getBean("testBean");
5153
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
@@ -54,24 +56,29 @@ public void setup() {
5456
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
5557
}
5658

59+
@AfterEach
60+
void tearDown() {
61+
this.ctx.close();
62+
}
63+
5764

5865
@Test
59-
public void testSimpleAfterThrowing() throws Throwable {
66+
void simpleAfterThrowing() throws Throwable {
6067
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
6168
this.testBean.exceptional(new Throwable()));
6269
verify(mockCollaborator).noArgs();
6370
}
6471

6572
@Test
66-
public void testAfterThrowingWithBinding() throws Throwable {
73+
void afterThrowingWithBinding() throws Throwable {
6774
Throwable t = new Throwable();
6875
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
6976
this.testBean.exceptional(t));
7077
verify(mockCollaborator).oneThrowable(t);
7178
}
7279

7380
@Test
74-
public void testAfterThrowingWithNamedTypeRestriction() throws Throwable {
81+
void afterThrowingWithNamedTypeRestriction() throws Throwable {
7582
Throwable t = new Throwable();
7683
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
7784
this.testBean.exceptional(t));
@@ -81,22 +88,22 @@ public void testAfterThrowingWithNamedTypeRestriction() throws Throwable {
8188
}
8289

8390
@Test
84-
public void testAfterThrowingWithRuntimeExceptionBinding() throws Throwable {
91+
void afterThrowingWithRuntimeExceptionBinding() throws Throwable {
8592
RuntimeException ex = new RuntimeException();
8693
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
8794
this.testBean.exceptional(ex));
8895
verify(mockCollaborator).oneRuntimeException(ex);
8996
}
9097

9198
@Test
92-
public void testAfterThrowingWithTypeSpecified() throws Throwable {
99+
void afterThrowingWithTypeSpecified() throws Throwable {
93100
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
94101
this.testBean.exceptional(new Throwable()));
95102
verify(mockCollaborator).noArgsOnThrowableMatch();
96103
}
97104

98105
@Test
99-
public void testAfterThrowingWithRuntimeTypeSpecified() throws Throwable {
106+
void afterThrowingWithRuntimeTypeSpecified() throws Throwable {
100107
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
101108
this.testBean.exceptional(new RuntimeException()));
102109
verify(mockCollaborator).noArgsOnRuntimeExceptionMatch();

spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.lang.reflect.Method;
2020

2121
import org.aspectj.lang.ProceedingJoinPoint;
22+
import org.junit.jupiter.api.AfterEach;
2223
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Test;
2425

@@ -33,7 +34,9 @@
3334
* @author Adrian Colyer
3435
* @author Chris Beams
3536
*/
36-
public class AspectAndAdvicePrecedenceTests {
37+
class AspectAndAdvicePrecedenceTests {
38+
39+
private ClassPathXmlApplicationContext ctx;
3740

3841
private PrecedenceTestAspect highPrecedenceAspect;
3942

@@ -47,19 +50,23 @@ public class AspectAndAdvicePrecedenceTests {
4750

4851

4952
@BeforeEach
50-
public void setup() {
51-
ClassPathXmlApplicationContext ctx =
52-
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
53+
void setup() {
54+
this.ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
5355
highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect");
5456
lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect");
5557
highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice");
5658
lowPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("lowPrecedenceSpringAdvice");
5759
testBean = (ITestBean) ctx.getBean("testBean");
5860
}
5961

62+
@AfterEach
63+
void tearDown() {
64+
this.ctx.close();
65+
}
66+
6067

6168
@Test
62-
public void testAdviceOrder() {
69+
void testAdviceOrder() {
6370
PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator();
6471
this.highPrecedenceAspect.setCollaborator(collaborator);
6572
this.lowPrecedenceAspect.setCollaborator(collaborator);

0 commit comments

Comments
 (0)