1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .aop .framework .autoproxy ;
18
18
19
- import org .junit .jupiter .api .BeforeEach ;
20
19
import org .junit .jupiter .api .Test ;
21
20
import test .mixin .Lockable ;
22
21
import test .mixin .LockedException ;
40
39
* @author Rob Harrop
41
40
* @author Chris Beams
42
41
*/
43
- public class BeanNameAutoProxyCreatorTests {
42
+ class BeanNameAutoProxyCreatorTests {
44
43
45
- private BeanFactory beanFactory ;
46
-
47
-
48
- @ BeforeEach
49
- public void setup () {
50
- // Note that we need an ApplicationContext, not just a BeanFactory,
51
- // for post-processing and hence auto-proxying to work.
52
- beanFactory = new ClassPathXmlApplicationContext (getClass ().getSimpleName () + "-context.xml" , getClass ());
53
- }
44
+ // Note that we need an ApplicationContext, not just a BeanFactory,
45
+ // for post-processing and hence auto-proxying to work.
46
+ private final BeanFactory beanFactory = new ClassPathXmlApplicationContext (getClass ().getSimpleName () + "-context.xml" , getClass ());
54
47
55
48
56
49
@ Test
57
- public void testNoProxy () {
50
+ void noProxy () {
58
51
TestBean tb = (TestBean ) beanFactory .getBean ("noproxy" );
59
52
assertThat (AopUtils .isAopProxy (tb )).isFalse ();
60
53
assertThat (tb .getName ()).isEqualTo ("noproxy" );
61
54
}
62
55
63
56
@ Test
64
- public void testJdkProxyWithExactNameMatch () {
57
+ void proxyWithExactNameMatch () {
65
58
ITestBean tb = (ITestBean ) beanFactory .getBean ("onlyJdk" );
66
59
jdkAssertions (tb , 1 );
67
60
assertThat (tb .getName ()).isEqualTo ("onlyJdk" );
68
61
}
69
62
70
63
@ Test
71
- public void testJdkProxyWithDoubleProxying () {
64
+ void proxyWithDoubleProxying () {
72
65
ITestBean tb = (ITestBean ) beanFactory .getBean ("doubleJdk" );
73
66
jdkAssertions (tb , 2 );
74
67
assertThat (tb .getName ()).isEqualTo ("doubleJdk" );
75
68
}
76
69
77
70
@ Test
78
- public void testJdkIntroduction () {
71
+ void jdkIntroduction () {
79
72
ITestBean tb = (ITestBean ) beanFactory .getBean ("introductionUsingJdk" );
80
73
NopInterceptor nop = (NopInterceptor ) beanFactory .getBean ("introductionNopInterceptor" );
81
74
assertThat (nop .getCount ()).isEqualTo (0 );
@@ -110,16 +103,15 @@ public void testJdkIntroduction() {
110
103
}
111
104
112
105
@ Test
113
- public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean () {
106
+ void jdkIntroductionAppliesToCreatedObjectsNotFactoryBean () {
114
107
ITestBean tb = (ITestBean ) beanFactory .getBean ("factory-introductionUsingJdk" );
115
108
NopInterceptor nop = (NopInterceptor ) beanFactory .getBean ("introductionNopInterceptor" );
116
109
assertThat (nop .getCount ()).as ("NOP should not have done any work yet" ).isEqualTo (0 );
117
110
assertThat (AopUtils .isJdkDynamicProxy (tb )).isTrue ();
118
111
int age = 5 ;
119
112
tb .setAge (age );
120
113
assertThat (tb .getAge ()).isEqualTo (age );
121
- boolean condition = tb instanceof TimeStamped ;
122
- assertThat (condition ).as ("Introduction was made" ).isTrue ();
114
+ assertThat (tb ).as ("Introduction was made" ).isInstanceOf (TimeStamped .class );
123
115
assertThat (((TimeStamped ) tb ).getTimeStamp ()).isEqualTo (0 );
124
116
assertThat (nop .getCount ()).isEqualTo (3 );
125
117
@@ -144,21 +136,21 @@ public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
144
136
}
145
137
146
138
@ Test
147
- public void testJdkProxyWithWildcardMatch () {
139
+ void proxyWithWildcardMatch () {
148
140
ITestBean tb = (ITestBean ) beanFactory .getBean ("jdk1" );
149
141
jdkAssertions (tb , 1 );
150
142
assertThat (tb .getName ()).isEqualTo ("jdk1" );
151
143
}
152
144
153
145
@ Test
154
- public void testCglibProxyWithWildcardMatch () {
146
+ void cglibProxyWithWildcardMatch () {
155
147
TestBean tb = (TestBean ) beanFactory .getBean ("cglib1" );
156
148
cglibAssertions (tb );
157
149
assertThat (tb .getName ()).isEqualTo ("cglib1" );
158
150
}
159
151
160
152
@ Test
161
- public void testWithFrozenProxy () {
153
+ void withFrozenProxy () {
162
154
ITestBean testBean = (ITestBean ) beanFactory .getBean ("frozenBean" );
163
155
assertThat (((Advised )testBean ).isFrozen ()).isTrue ();
164
156
}
@@ -195,25 +187,16 @@ private void cglibAssertions(TestBean tb) {
195
187
196
188
class CreatesTestBean implements FactoryBean <Object > {
197
189
198
- /**
199
- * @see org.springframework.beans.factory.FactoryBean#getObject()
200
- */
201
190
@ Override
202
191
public Object getObject () throws Exception {
203
192
return new TestBean ();
204
193
}
205
194
206
- /**
207
- * @see org.springframework.beans.factory.FactoryBean#getObjectType()
208
- */
209
195
@ Override
210
196
public Class <?> getObjectType () {
211
197
return TestBean .class ;
212
198
}
213
199
214
- /**
215
- * @see org.springframework.beans.factory.FactoryBean#isSingleton()
216
- */
217
200
@ Override
218
201
public boolean isSingleton () {
219
202
return true ;
0 commit comments