Skip to content

Commit 2f5dc26

Browse files
sbrannenkenny5he
authored andcommitted
Polishing
1 parent abc94b5 commit 2f5dc26

File tree

2 files changed

+36
-63
lines changed

2 files changed

+36
-63
lines changed

spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java

+14-31
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-2020 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,7 +16,6 @@
1616

1717
package org.springframework.aop.framework.autoproxy;
1818

19-
import org.junit.jupiter.api.BeforeEach;
2019
import org.junit.jupiter.api.Test;
2120
import test.mixin.Lockable;
2221
import test.mixin.LockedException;
@@ -40,42 +39,36 @@
4039
* @author Rob Harrop
4140
* @author Chris Beams
4241
*/
43-
public class BeanNameAutoProxyCreatorTests {
42+
class BeanNameAutoProxyCreatorTests {
4443

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());
5447

5548

5649
@Test
57-
public void testNoProxy() {
50+
void noProxy() {
5851
TestBean tb = (TestBean) beanFactory.getBean("noproxy");
5952
assertThat(AopUtils.isAopProxy(tb)).isFalse();
6053
assertThat(tb.getName()).isEqualTo("noproxy");
6154
}
6255

6356
@Test
64-
public void testJdkProxyWithExactNameMatch() {
57+
void proxyWithExactNameMatch() {
6558
ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk");
6659
jdkAssertions(tb, 1);
6760
assertThat(tb.getName()).isEqualTo("onlyJdk");
6861
}
6962

7063
@Test
71-
public void testJdkProxyWithDoubleProxying() {
64+
void proxyWithDoubleProxying() {
7265
ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk");
7366
jdkAssertions(tb, 2);
7467
assertThat(tb.getName()).isEqualTo("doubleJdk");
7568
}
7669

7770
@Test
78-
public void testJdkIntroduction() {
71+
void jdkIntroduction() {
7972
ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
8073
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
8174
assertThat(nop.getCount()).isEqualTo(0);
@@ -110,16 +103,15 @@ public void testJdkIntroduction() {
110103
}
111104

112105
@Test
113-
public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
106+
void jdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
114107
ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
115108
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
116109
assertThat(nop.getCount()).as("NOP should not have done any work yet").isEqualTo(0);
117110
assertThat(AopUtils.isJdkDynamicProxy(tb)).isTrue();
118111
int age = 5;
119112
tb.setAge(age);
120113
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);
123115
assertThat(((TimeStamped) tb).getTimeStamp()).isEqualTo(0);
124116
assertThat(nop.getCount()).isEqualTo(3);
125117

@@ -144,21 +136,21 @@ public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
144136
}
145137

146138
@Test
147-
public void testJdkProxyWithWildcardMatch() {
139+
void proxyWithWildcardMatch() {
148140
ITestBean tb = (ITestBean) beanFactory.getBean("jdk1");
149141
jdkAssertions(tb, 1);
150142
assertThat(tb.getName()).isEqualTo("jdk1");
151143
}
152144

153145
@Test
154-
public void testCglibProxyWithWildcardMatch() {
146+
void cglibProxyWithWildcardMatch() {
155147
TestBean tb = (TestBean) beanFactory.getBean("cglib1");
156148
cglibAssertions(tb);
157149
assertThat(tb.getName()).isEqualTo("cglib1");
158150
}
159151

160152
@Test
161-
public void testWithFrozenProxy() {
153+
void withFrozenProxy() {
162154
ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
163155
assertThat(((Advised)testBean).isFrozen()).isTrue();
164156
}
@@ -195,25 +187,16 @@ private void cglibAssertions(TestBean tb) {
195187

196188
class CreatesTestBean implements FactoryBean<Object> {
197189

198-
/**
199-
* @see org.springframework.beans.factory.FactoryBean#getObject()
200-
*/
201190
@Override
202191
public Object getObject() throws Exception {
203192
return new TestBean();
204193
}
205194

206-
/**
207-
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
208-
*/
209195
@Override
210196
public Class<?> getObjectType() {
211197
return TestBean.class;
212198
}
213199

214-
/**
215-
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
216-
*/
217200
@Override
218201
public boolean isSingleton() {
219202
return true;

spring-context/src/test/resources/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests-context.xml

+22-32
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,28 @@
44
<beans>
55

66
<bean id="frozenProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
7-
<property name="beanNames" value="frozenBean"/>
8-
<property name="frozen" value="true"/>
9-
<property name="interceptorNames" value="nopInterceptor"/>
7+
<property name="beanNames" value="frozenBean" />
8+
<property name="frozen" value="true" />
9+
<property name="interceptorNames" value="nopInterceptor" />
1010
</bean>
1111

1212
<bean id="_jdkBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
13-
<description>
14-
Automatically proxies using JDK dynamic proxies
15-
</description>
16-
<property name="beanNames"><value>jdk*,onlyJdk,doubleJdk</value></property>
17-
<property name="interceptorNames">
18-
<list>
19-
<value>nopInterceptor</value>
20-
</list>
21-
</property>
13+
<description>Automatically proxies using JDK dynamic proxies</description>
14+
<property name="beanNames" value="jdk*,onlyJdk,doubleJdk" />
15+
<property name="interceptorNames" value="nopInterceptor" />
2216
</bean>
2317

2418
<bean id="doubleJdkBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
25-
<property name="beanNames" value="doubleJdk"/>
26-
<property name="interceptorNames" value="nopInterceptor"/>
19+
<property name="beanNames" value="doubleJdk" />
20+
<property name="interceptorNames" value="nopInterceptor" />
2721
</bean>
2822

2923
<bean id="_cglibBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
30-
<property name="beanNames">
31-
<value>
32-
cglib*
33-
</value>
24+
<property name="beanNames" value="cglib*" />
25+
<property name="proxyTargetClass">
26+
<description>Use the inherited ProxyConfig property to force CGLIB proxying</description>
27+
<value>true</value>
3428
</property>
35-
<property name="proxyTargetClass">
36-
<description>Use the inherited ProxyConfig property to force CGLIB proxying</description>
37-
<value>true</value>
38-
</property>
3929
<property name="interceptorNames">
4030
<description>Interceptors and Advisors to apply automatically</description>
4131
<list>
@@ -49,14 +39,14 @@
4939
<description>
5040
Illustrates a JDK introduction
5141
</description>
52-
<property name="beanNames"><value>*introductionUsingJdk</value></property>
53-
<property name="interceptorNames">
42+
<property name="beanNames" value="*introductionUsingJdk" />
43+
<property name="interceptorNames">
5444
<list>
5545
<value>introductionNopInterceptor</value>
5646
<value>timestampIntroduction</value>
5747
<value>lockableAdvisor</value>
5848
</list>
59-
</property>
49+
</property>
6050
</bean>
6151

6252
<bean id="timestampIntroduction" class="org.springframework.aop.testfixture.advice.TimestampIntroductionAdvisor"/>
@@ -74,11 +64,11 @@
7464
<bean id="introductionNopInterceptor" class="org.springframework.aop.testfixture.interceptor.NopInterceptor"/>
7565

7666
<bean id="introductionUsingJdk" class="org.springframework.beans.testfixture.beans.TestBean">
77-
<property name="name"><value>introductionUsingJdk</value></property>
67+
<property name="name" value="introductionUsingJdk" />
7868
</bean>
7969

8070
<bean id="second-introductionUsingJdk" class="org.springframework.beans.testfixture.beans.TestBean">
81-
<property name="name"><value>second-introductionUsingJdk</value></property>
71+
<property name="name" value="second-introductionUsingJdk" />
8272
</bean>
8373

8474
<!--
@@ -89,7 +79,7 @@
8979
</bean>
9080

9181
<bean id="jdk1" class="org.springframework.beans.testfixture.beans.TestBean">
92-
<property name="name"><value>jdk1</value></property>
82+
<property name="name" value="jdk1" />
9383
</bean>
9484

9585
<bean id="frozen" class="org.springframework.beans.testfixture.beans.TestBean">
@@ -99,19 +89,19 @@
9989
<alias name="frozen" alias="frozenBean"/>
10090

10191
<bean id="cglib1" class="org.springframework.beans.testfixture.beans.TestBean">
102-
<property name="name"><value>cglib1</value></property>
92+
<property name="name" value="cglib1" />
10393
</bean>
10494

10595
<bean id="onlyJdk" class="org.springframework.beans.testfixture.beans.TestBean">
106-
<property name="name"><value>onlyJdk</value></property>
96+
<property name="name" value="onlyJdk" />
10797
</bean>
10898

10999
<bean id="doubleJdk" class="org.springframework.beans.testfixture.beans.TestBean">
110-
<property name="name"><value>doubleJdk</value></property>
100+
<property name="name" value="doubleJdk" />
111101
</bean>
112102

113103
<bean id="noproxy" class="org.springframework.beans.testfixture.beans.TestBean">
114-
<property name="name"><value>noproxy</value></property>
104+
<property name="name" value="noproxy" />
115105
</bean>
116106

117107
</beans>

0 commit comments

Comments
 (0)