Skip to content

Commit 974e7b8

Browse files
committed
Polishing
1 parent 069704f commit 974e7b8

File tree

8 files changed

+198
-194
lines changed

8 files changed

+198
-194
lines changed

Diff for: spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -253,7 +253,7 @@ public ResolvableType getResolvableType() {
253253
/**
254254
* Return whether a fallback match is allowed.
255255
* <p>This is {@code false} by default but may be overridden to return {@code true} in order
256-
* to suggest to a {@link org.springframework.beans.factory.support.AutowireCandidateResolver}
256+
* to suggest to an {@link org.springframework.beans.factory.support.AutowireCandidateResolver}
257257
* that a fallback match is acceptable as well.
258258
* @since 4.0
259259
*/
@@ -308,7 +308,6 @@ public Class<?> getDependencyType() {
308308
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
309309
type = args[args.length - 1];
310310
}
311-
// TODO: Object.class if unresolvable
312311
}
313312
if (type instanceof Class) {
314313
return (Class<?>) type;

Diff for: spring-test/src/main/java/org/springframework/test/context/support/DependencyInjectionTestExecutionListener.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -49,7 +49,7 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
4949
* <p>Permissible values include {@link Boolean#TRUE} and {@link Boolean#FALSE}.
5050
*/
5151
public static final String REINJECT_DEPENDENCIES_ATTRIBUTE = Conventions.getQualifiedAttributeName(
52-
DependencyInjectionTestExecutionListener.class, "reinjectDependencies");
52+
DependencyInjectionTestExecutionListener.class, "reinjectDependencies");
5353

5454
private static final Log logger = LogFactory.getLog(DependencyInjectionTestExecutionListener.class);
5555

@@ -76,7 +76,7 @@ public final int getOrder() {
7676
* from the test context, regardless of its value.
7777
*/
7878
@Override
79-
public void prepareTestInstance(final TestContext testContext) throws Exception {
79+
public void prepareTestInstance(TestContext testContext) throws Exception {
8080
if (logger.isDebugEnabled()) {
8181
logger.debug("Performing dependency injection for test context [" + testContext + "].");
8282
}
@@ -91,7 +91,7 @@ public void prepareTestInstance(final TestContext testContext) throws Exception
9191
* otherwise, this method will have no effect.
9292
*/
9393
@Override
94-
public void beforeTestMethod(final TestContext testContext) throws Exception {
94+
public void beforeTestMethod(TestContext testContext) throws Exception {
9595
if (Boolean.TRUE.equals(testContext.getAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE))) {
9696
if (logger.isDebugEnabled()) {
9797
logger.debug("Reinjecting dependencies for test context [" + testContext + "].");
@@ -112,7 +112,7 @@ public void beforeTestMethod(final TestContext testContext) throws Exception {
112112
* @see #prepareTestInstance(TestContext)
113113
* @see #beforeTestMethod(TestContext)
114114
*/
115-
protected void injectDependencies(final TestContext testContext) throws Exception {
115+
protected void injectDependencies(TestContext testContext) throws Exception {
116116
Object bean = testContext.getTestInstance();
117117
AutowireCapableBeanFactory beanFactory = testContext.getApplicationContext().getAutowireCapableBeanFactory();
118118
beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false);

Diff for: spring-test/src/test/java/org/springframework/test/context/groovy/GroovySpringContextTests.java

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -43,13 +43,6 @@
4343
@ContextConfiguration("context.groovy")
4444
public class GroovySpringContextTests implements BeanNameAware, InitializingBean {
4545

46-
private boolean beanInitialized = false;
47-
48-
private String beanName = "replace me with [" + getClass().getName() + "]";
49-
50-
@Autowired
51-
private ApplicationContext applicationContext;
52-
5346
private Employee employee;
5447

5548
@Autowired
@@ -63,60 +56,68 @@ public class GroovySpringContextTests implements BeanNameAware, InitializingBean
6356

6457
protected String bar;
6558

59+
@Autowired
60+
private ApplicationContext applicationContext;
61+
62+
private String beanName;
63+
64+
private boolean beanInitialized = false;
65+
6666

6767
@Autowired
68-
protected final void setEmployee(final Employee employee) {
68+
protected void setEmployee(Employee employee) {
6969
this.employee = employee;
7070
}
7171

7272
@Resource
73-
protected final void setBar(final String bar) {
73+
protected void setBar(String bar) {
7474
this.bar = bar;
7575
}
7676

7777
@Override
78-
public final void setBeanName(final String beanName) {
78+
public void setBeanName(String beanName) {
7979
this.beanName = beanName;
8080
}
8181

8282
@Override
83-
public final void afterPropertiesSet() throws Exception {
83+
public void afterPropertiesSet() {
8484
this.beanInitialized = true;
8585
}
8686

87+
8788
@Test
88-
public final void verifyBeanInitialized() {
89-
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
90-
this.beanInitialized);
89+
public void verifyBeanNameSet() {
90+
assertTrue("The bean name of this test instance should have been set to the fully qualified class name " +
91+
"due to BeanNameAware semantics.", this.beanName.startsWith(getClass().getName()));
9192
}
9293

9394
@Test
94-
public final void verifyBeanNameSet() {
95-
assertEquals("The bean name of this test instance should have been set to the fully qualified class name "
96-
+ "due to BeanNameAware semantics.", getClass().getName(), this.beanName);
95+
public void verifyBeanInitialized() {
96+
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
97+
this.beanInitialized);
9798
}
9899

99100
@Test
100-
public final void verifyAnnotationAutowiredFields() {
101+
public void verifyAnnotationAutowiredFields() {
101102
assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong);
102103
assertNotNull("The application context should have been autowired.", this.applicationContext);
103104
assertNotNull("The pet field should have been autowired.", this.pet);
104105
assertEquals("Dogbert", this.pet.getName());
105106
}
106107

107108
@Test
108-
public final void verifyAnnotationAutowiredMethods() {
109+
public void verifyAnnotationAutowiredMethods() {
109110
assertNotNull("The employee setter method should have been autowired.", this.employee);
110111
assertEquals("Dilbert", this.employee.getName());
111112
}
112113

113114
@Test
114-
public final void verifyResourceAnnotationWiredFields() {
115+
public void verifyResourceAnnotationWiredFields() {
115116
assertEquals("The foo field should have been wired via @Resource.", "Foo", this.foo);
116117
}
117118

118119
@Test
119-
public final void verifyResourceAnnotationWiredMethods() {
120+
public void verifyResourceAnnotationWiredMethods() {
120121
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
121122
}
122123

Diff for: spring-test/src/test/java/org/springframework/test/context/junit4/ConcreteTransactionalJUnit4SpringContextTests.java

+54-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -51,10 +51,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
5151
private static final String SUE = "sue";
5252
private static final String YODA = "yoda";
5353

54-
private boolean beanInitialized = false;
55-
56-
private String beanName = "replace me with [" + getClass().getName() + "]";
57-
5854
private Employee employee;
5955

6056
@Autowired
@@ -68,54 +64,86 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
6864

6965
private String bar;
7066

67+
private String beanName;
68+
69+
private boolean beanInitialized = false;
70+
7171

7272
@Autowired
73-
private final void setEmployee(final Employee employee) {
73+
private void setEmployee(Employee employee) {
7474
this.employee = employee;
7575
}
7676

7777
@Resource
78-
private final void setBar(final String bar) {
78+
private void setBar(String bar) {
7979
this.bar = bar;
8080
}
8181

8282
@Override
83-
public final void setBeanName(final String beanName) {
83+
public void setBeanName(String beanName) {
8484
this.beanName = beanName;
8585
}
8686

8787
@Override
88-
public final void afterPropertiesSet() throws Exception {
88+
public void afterPropertiesSet() {
8989
this.beanInitialized = true;
9090
}
9191

92+
93+
@Before
94+
public void setUp() {
95+
assertEquals("Verifying the number of rows in the person table before a test method.",
96+
(inTransaction() ? 2 : 1), countRowsInPersonTable());
97+
}
98+
99+
@After
100+
public void tearDown() {
101+
assertEquals("Verifying the number of rows in the person table after a test method.",
102+
(inTransaction() ? 4 : 1), countRowsInPersonTable());
103+
}
104+
105+
@BeforeTransaction
106+
public void beforeTransaction() {
107+
assertEquals("Verifying the number of rows in the person table before a transactional test method.",
108+
1, countRowsInPersonTable());
109+
assertEquals("Adding yoda", 1, addPerson(YODA));
110+
}
111+
112+
@AfterTransaction
113+
public void afterTransaction() {
114+
assertEquals("Deleting yoda", 1, deletePerson(YODA));
115+
assertEquals("Verifying the number of rows in the person table after a transactional test method.",
116+
1, countRowsInPersonTable());
117+
}
118+
119+
92120
@Test
93121
@Transactional(propagation = Propagation.NOT_SUPPORTED)
94-
public final void verifyApplicationContext() {
122+
public void verifyBeanNameSet() {
95123
assertInTransaction(false);
96-
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
97-
super.applicationContext);
124+
assertTrue("The bean name of this test instance should have been set to the fully qualified class name " +
125+
"due to BeanNameAware semantics.", this.beanName.startsWith(getClass().getName()));
98126
}
99127

100128
@Test
101129
@Transactional(propagation = Propagation.NOT_SUPPORTED)
102-
public final void verifyBeanInitialized() {
130+
public void verifyApplicationContext() {
103131
assertInTransaction(false);
104-
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
105-
this.beanInitialized);
132+
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
133+
super.applicationContext);
106134
}
107135

108136
@Test
109137
@Transactional(propagation = Propagation.NOT_SUPPORTED)
110-
public final void verifyBeanNameSet() {
138+
public void verifyBeanInitialized() {
111139
assertInTransaction(false);
112-
assertEquals("The bean name of this test instance should have been set to the fully qualified class name "
113-
+ "due to BeanNameAware semantics.", getClass().getName(), this.beanName);
140+
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
141+
this.beanInitialized);
114142
}
115143

116144
@Test
117145
@Transactional(propagation = Propagation.NOT_SUPPORTED)
118-
public final void verifyAnnotationAutowiredFields() {
146+
public void verifyAnnotationAutowiredFields() {
119147
assertInTransaction(false);
120148
assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong);
121149
assertNotNull("The pet field should have been autowired.", this.pet);
@@ -124,66 +152,41 @@ public final void verifyAnnotationAutowiredFields() {
124152

125153
@Test
126154
@Transactional(propagation = Propagation.NOT_SUPPORTED)
127-
public final void verifyAnnotationAutowiredMethods() {
155+
public void verifyAnnotationAutowiredMethods() {
128156
assertInTransaction(false);
129157
assertNotNull("The employee setter method should have been autowired.", this.employee);
130158
assertEquals("John Smith", this.employee.getName());
131159
}
132160

133161
@Test
134162
@Transactional(propagation = Propagation.NOT_SUPPORTED)
135-
public final void verifyResourceAnnotationWiredFields() {
163+
public void verifyResourceAnnotationWiredFields() {
136164
assertInTransaction(false);
137165
assertEquals("The foo field should have been wired via @Resource.", "Foo", this.foo);
138166
}
139167

140168
@Test
141169
@Transactional(propagation = Propagation.NOT_SUPPORTED)
142-
public final void verifyResourceAnnotationWiredMethods() {
170+
public void verifyResourceAnnotationWiredMethods() {
143171
assertInTransaction(false);
144172
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
145173
}
146174

147-
@BeforeTransaction
148-
public void beforeTransaction() {
149-
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
150-
countRowsInPersonTable());
151-
assertEquals("Adding yoda", 1, addPerson(YODA));
152-
}
153-
154-
@Before
155-
public void setUp() throws Exception {
156-
assertEquals("Verifying the number of rows in the person table before a test method.",
157-
(inTransaction() ? 2 : 1), countRowsInPersonTable());
158-
}
159-
160175
@Test
161176
public void modifyTestDataWithinTransaction() {
162177
assertInTransaction(true);
163178
assertEquals("Adding jane", 1, addPerson(JANE));
164179
assertEquals("Adding sue", 1, addPerson(SUE));
165-
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().", 4,
166-
countRowsInPersonTable());
167-
}
168-
169-
@After
170-
public void tearDown() throws Exception {
171-
assertEquals("Verifying the number of rows in the person table after a test method.",
172-
(inTransaction() ? 4 : 1), countRowsInPersonTable());
180+
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().",
181+
4, countRowsInPersonTable());
173182
}
174183

175-
@AfterTransaction
176-
public void afterTransaction() {
177-
assertEquals("Deleting yoda", 1, deletePerson(YODA));
178-
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 1,
179-
countRowsInPersonTable());
180-
}
181184

182-
private int addPerson(final String name) {
185+
private int addPerson(String name) {
183186
return super.jdbcTemplate.update("INSERT INTO person VALUES(?)", name);
184187
}
185188

186-
private int deletePerson(final String name) {
189+
private int deletePerson(String name) {
187190
return super.jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
188191
}
189192

0 commit comments

Comments
 (0)