Skip to content

Commit 98eb0f7

Browse files
committed
Polishing
1 parent cfd01ab commit 98eb0f7

File tree

6 files changed

+56
-54
lines changed

6 files changed

+56
-54
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -25,7 +25,7 @@
2525
* TargetSourceCreator that enforces a LazyInitTargetSource for each bean
2626
* that is defined as "lazy-init". This will lead to a proxy created for
2727
* each of those beans, allowing to fetch a reference to such a bean
28-
* without actually initialized the target bean instance.
28+
* without actually initializing the target bean instance.
2929
*
3030
* <p>To be registered as custom TargetSourceCreator for an auto-proxy creator,
3131
* in combination with custom interceptors for specific beans or for the

spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -24,7 +24,6 @@
2424
import org.springframework.aop.TargetSource;
2525
import org.springframework.beans.factory.BeanFactory;
2626
import org.springframework.beans.factory.BeanFactoryAware;
27-
import org.springframework.util.ClassUtils;
2827
import org.springframework.util.ObjectUtils;
2928

3029
/**
@@ -48,8 +47,7 @@
4847
* @see ThreadLocalTargetSource
4948
* @see CommonsPoolTargetSource
5049
*/
51-
public abstract class AbstractBeanFactoryBasedTargetSource
52-
implements TargetSource, BeanFactoryAware, Serializable {
50+
public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSource, BeanFactoryAware, Serializable {
5351

5452
/** use serialVersionUID from Spring 1.2.7 for interoperability */
5553
private static final long serialVersionUID = -4721607536018568393L;
@@ -108,7 +106,7 @@ public void setTargetClass(Class<?> targetClass) {
108106
@Override
109107
public void setBeanFactory(BeanFactory beanFactory) {
110108
if (this.targetBeanName == null) {
111-
throw new IllegalStateException("Property'targetBeanName' is required");
109+
throw new IllegalStateException("Property 'targetBeanName' is required");
112110
}
113111
this.beanFactory = beanFactory;
114112
}
@@ -185,8 +183,7 @@ public int hashCode() {
185183

186184
@Override
187185
public String toString() {
188-
StringBuilder sb = new StringBuilder();
189-
sb.append(ClassUtils.getShortName(getClass()));
186+
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
190187
sb.append(" for target bean '").append(this.targetBeanName).append("'");
191188
if (this.targetClass != null) {
192189
sb.append(" of type [").append(this.targetClass.getName()).append("]");
+16-11
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616

1717
package org.springframework.cache.interceptor;
1818

19-
import static org.junit.Assert.*;
20-
import static org.springframework.cache.CacheTestUtils.*;
21-
2219
import java.lang.reflect.Method;
2320
import java.util.Collection;
2421
import java.util.Collections;
2522
import java.util.concurrent.atomic.AtomicLong;
2623

2724
import org.junit.Before;
2825
import org.junit.Test;
26+
2927
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3028
import org.springframework.cache.Cache;
3129
import org.springframework.cache.CacheManager;
@@ -40,12 +38,16 @@
4038
import org.springframework.context.annotation.Configuration;
4139
import org.springframework.util.ReflectionUtils;
4240

41+
import static org.junit.Assert.*;
42+
import static org.springframework.cache.CacheTestUtils.*;
43+
4344
/**
4445
* Provides various {@link CacheResolver} customisations scenario
4546
*
4647
* @author Stephane Nicoll
48+
* @since 4.1
4749
*/
48-
public class CacheResolverCustomisationTests {
50+
public class CacheResolverCustomizationTests {
4951

5052
private CacheManager cacheManager;
5153

@@ -127,13 +129,13 @@ public void namedResolution() {
127129

128130
@Test
129131
public void noCacheResolved() {
130-
Method m = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
132+
Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
131133
try {
132134
simpleService.noCacheResolved(new Object());
133135
fail("Should have failed, no cache resolved");
134-
} catch (IllegalStateException e) {
135-
String msg = e.getMessage();
136-
assertTrue("Reference to the method must be contained in the message", msg.contains(m.toString()));
136+
}
137+
catch (IllegalStateException ex) {
138+
assertTrue("Reference to the method must be contained in the message", ex.getMessage().contains(method.toString()));
137139
}
138140
}
139141

@@ -142,13 +144,13 @@ public void unknownCacheResolver() {
142144
try {
143145
simpleService.unknownCacheResolver(new Object());
144146
fail("Should have failed, no cache resolver with that name");
145-
} catch (NoSuchBeanDefinitionException e) {
146-
assertEquals("Wrong bean name in exception", "unknownCacheResolver", e.getBeanName());
147+
}
148+
catch (NoSuchBeanDefinitionException ex) {
149+
assertEquals("Wrong bean name in exception", "unknownCacheResolver", ex.getBeanName());
147150
}
148151
}
149152

150153

151-
152154
@Configuration
153155
@EnableCaching
154156
static class Config extends CachingConfigurerSupport {
@@ -204,6 +206,7 @@ public SimpleService simpleService() {
204206
}
205207
}
206208

209+
207210
@CacheConfig(cacheNames = "default")
208211
static class SimpleService {
209212

@@ -245,6 +248,7 @@ public Object unknownCacheResolver(Object key) {
245248
}
246249
}
247250

251+
248252
/**
249253
* Example of {@link CacheResolver} that resolve the caches at
250254
* runtime (i.e. based on method invocation parameters).
@@ -263,6 +267,7 @@ protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> co
263267
}
264268
}
265269

270+
266271
private static class NullCacheResolver extends AbstractCacheResolver {
267272

268273
private NullCacheResolver(CacheManager cacheManager) {

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostConstructAndAutowiringTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -101,6 +101,7 @@ public TestBean beanMethod() {
101101

102102
@Configuration
103103
static class Config2 {
104+
104105
TestBean testBean;
105106

106107
@Autowired

spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,10 @@ private String getEndpointId(JmsListener jmsListener) {
258258

259259
/**
260260
* Resolve the specified value if possible.
261-
*
262261
* @see ConfigurableBeanFactory#resolveEmbeddedValue
263262
*/
264263
private String resolve(String value) {
265-
if (this.beanFactory != null && this.beanFactory instanceof ConfigurableBeanFactory) {
264+
if (this.beanFactory instanceof ConfigurableBeanFactory) {
266265
return ((ConfigurableBeanFactory) this.beanFactory).resolveEmbeddedValue(value);
267266
}
268267
return value;

src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java

+31-31
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,11 @@
8787
public class EnvironmentIntegrationTests {
8888

8989
private ConfigurableEnvironment prodEnv;
90-
private ConfigurableEnvironment devEnv;
91-
private ConfigurableEnvironment prodWebEnv;
9290

93-
/**
94-
* Constants used both locally and in scan* sub-packages
95-
*/
96-
public static class Constants {
97-
public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml";
98-
99-
public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean";
91+
private ConfigurableEnvironment devEnv;
10092

101-
public static final String PROD_BEAN_NAME = "prodBean";
102-
public static final String DEV_BEAN_NAME = "devBean";
103-
public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean";
104-
public static final String TRANSITIVE_BEAN_NAME = "transitiveBean";
93+
private ConfigurableEnvironment prodWebEnv;
10594

106-
public static final String PROD_ENV_NAME = "prod";
107-
public static final String DEV_ENV_NAME = "dev";
108-
public static final String DERIVED_DEV_ENV_NAME = "derivedDev";
109-
}
11095

11196
@Before
11297
public void setUp() {
@@ -122,9 +107,7 @@ public void setUp() {
122107

123108
@Test
124109
public void genericApplicationContext_standardEnv() {
125-
ConfigurableApplicationContext ctx =
126-
new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
127-
110+
ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
128111
ctx.refresh();
129112

130113
assertHasStandardEnvironment(ctx);
@@ -134,8 +117,7 @@ public void genericApplicationContext_standardEnv() {
134117

135118
@Test
136119
public void genericApplicationContext_customEnv() {
137-
GenericApplicationContext ctx =
138-
new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
120+
GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
139121
ctx.setEnvironment(prodEnv);
140122
ctx.refresh();
141123

@@ -191,11 +173,8 @@ public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCap
191173
@Test
192174
public void genericXmlApplicationContext() {
193175
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
194-
195176
assertHasStandardEnvironment(ctx);
196-
197177
ctx.setEnvironment(prodEnv);
198-
199178
ctx.load(XML_PATH);
200179
ctx.refresh();
201180

@@ -208,8 +187,7 @@ public void genericXmlApplicationContext() {
208187

209188
@Test
210189
public void classPathXmlApplicationContext() {
211-
ConfigurableApplicationContext ctx =
212-
new ClassPathXmlApplicationContext(new String[] { XML_PATH });
190+
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH);
213191
ctx.setEnvironment(prodEnv);
214192
ctx.refresh();
215193

@@ -228,7 +206,7 @@ public void fileSystemXmlApplicationContext() throws IOException {
228206

229207
// strange - FSXAC strips leading '/' unless prefixed with 'file:'
230208
ConfigurableApplicationContext ctx =
231-
new FileSystemXmlApplicationContext(new String[] { "file:"+tmpFile.getPath() }, false);
209+
new FileSystemXmlApplicationContext(new String[] {"file:" + tmpFile.getPath()}, false);
232210
ctx.setEnvironment(prodEnv);
233211
ctx.refresh();
234212
assertEnvironmentBeanRegistered(ctx);
@@ -588,7 +566,8 @@ public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
588566
try {
589567
ctx.refresh();
590568
fail("expected missing property exception");
591-
} catch (MissingRequiredPropertiesException ex) {
569+
}
570+
catch (MissingRequiredPropertiesException ex) {
592571
}
593572
}
594573

@@ -598,7 +577,6 @@ public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
598577
ctx.setEnvironment(new MockEnvironment().withProperty("foo", "fooValue"));
599578
ctx.refresh(); // should succeed
600579
}
601-
602580
}
603581

604582

@@ -652,6 +630,7 @@ private void assertEnvironmentAwareInvoked(ConfigurableApplicationContext ctx, E
652630
assertThat(ctx.getBean(EnvironmentAwareBean.class).environment, is(expectedEnv));
653631
}
654632

633+
655634
private static class EnvironmentAwareBean implements EnvironmentAware {
656635

657636
public Environment environment;
@@ -660,9 +639,9 @@ private static class EnvironmentAwareBean implements EnvironmentAware {
660639
public void setEnvironment(Environment environment) {
661640
this.environment = environment;
662641
}
663-
664642
}
665643

644+
666645
/**
667646
* Mirrors the structure of beans and environment-specific config files
668647
* in EnvironmentIntegrationTests-context.xml
@@ -711,4 +690,25 @@ public Object derivedDevBean() {
711690
return new Object();
712691
}
713692
}
693+
694+
695+
/**
696+
* Constants used both locally and in scan* sub-packages
697+
*/
698+
public static class Constants {
699+
700+
public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml";
701+
702+
public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean";
703+
704+
public static final String PROD_BEAN_NAME = "prodBean";
705+
public static final String DEV_BEAN_NAME = "devBean";
706+
public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean";
707+
public static final String TRANSITIVE_BEAN_NAME = "transitiveBean";
708+
709+
public static final String PROD_ENV_NAME = "prod";
710+
public static final String DEV_ENV_NAME = "dev";
711+
public static final String DERIVED_DEV_ENV_NAME = "derivedDev";
712+
}
713+
714714
}

0 commit comments

Comments
 (0)