Skip to content

Commit da9c24c

Browse files
committed
Polishing
1 parent 102dc8a commit da9c24c

File tree

6 files changed

+53
-61
lines changed

6 files changed

+53
-61
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ public Object resolveDependency(DependencyDescriptor descriptor, String beanName
992992
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
993993

994994
descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
995-
if (descriptor.getDependencyType() == Optional.class) {
995+
if (Optional.class == descriptor.getDependencyType()) {
996996
return createOptionalDependency(descriptor, beanName);
997997
}
998998
else if (ObjectFactory.class == descriptor.getDependencyType() ||

spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ static MergedTestPropertySources buildMergedTestPropertySources(Class<?> testCla
7575
return new MergedTestPropertySources();
7676
}
7777

78-
// else...
7978
List<TestPropertySourceAttributes> attributesList = resolveTestPropertySourceAttributes(testClass);
8079
String[] locations = mergeLocations(attributesList);
8180
String[] properties = mergeProperties(attributesList);
@@ -84,71 +83,60 @@ static MergedTestPropertySources buildMergedTestPropertySources(Class<?> testCla
8483

8584
private static List<TestPropertySourceAttributes> resolveTestPropertySourceAttributes(Class<?> testClass) {
8685
Assert.notNull(testClass, "Class must not be null");
86+
List<TestPropertySourceAttributes> attributesList = new ArrayList<>();
87+
Class<TestPropertySource> annotationType = TestPropertySource.class;
8788

88-
final List<TestPropertySourceAttributes> attributesList = new ArrayList<>();
89-
final Class<TestPropertySource> annotationType = TestPropertySource.class;
9089
AnnotationDescriptor<TestPropertySource> descriptor = findAnnotationDescriptor(testClass, annotationType);
9190
Assert.notNull(descriptor, String.format(
92-
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
93-
annotationType.getName(), testClass.getName()));
91+
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
92+
annotationType.getName(), testClass.getName()));
9493

9594
while (descriptor != null) {
9695
TestPropertySource testPropertySource = descriptor.synthesizeAnnotation();
9796
Class<?> rootDeclaringClass = descriptor.getRootDeclaringClass();
98-
9997
if (logger.isTraceEnabled()) {
10098
logger.trace(String.format("Retrieved @TestPropertySource [%s] for declaring class [%s].",
10199
testPropertySource, rootDeclaringClass.getName()));
102100
}
103-
104-
TestPropertySourceAttributes attributes = new TestPropertySourceAttributes(rootDeclaringClass,
105-
testPropertySource);
101+
TestPropertySourceAttributes attributes =
102+
new TestPropertySourceAttributes(rootDeclaringClass, testPropertySource);
106103
if (logger.isTraceEnabled()) {
107104
logger.trace("Resolved TestPropertySource attributes: " + attributes);
108105
}
109106
attributesList.add(attributes);
110-
111107
descriptor = findAnnotationDescriptor(rootDeclaringClass.getSuperclass(), annotationType);
112108
}
113109

114110
return attributesList;
115111
}
116112

117113
private static String[] mergeLocations(List<TestPropertySourceAttributes> attributesList) {
118-
final List<String> locations = new ArrayList<>();
119-
114+
List<String> locations = new ArrayList<>();
120115
for (TestPropertySourceAttributes attrs : attributesList) {
121116
if (logger.isTraceEnabled()) {
122117
logger.trace(String.format("Processing locations for TestPropertySource attributes %s", attrs));
123118
}
124-
125119
String[] locationsArray = TestContextResourceUtils.convertToClasspathResourcePaths(
126-
attrs.getDeclaringClass(), attrs.getLocations());
120+
attrs.getDeclaringClass(), attrs.getLocations());
127121
locations.addAll(0, Arrays.<String> asList(locationsArray));
128-
129122
if (!attrs.isInheritLocations()) {
130123
break;
131124
}
132125
}
133-
134126
return StringUtils.toStringArray(locations);
135127
}
136128

137129
private static String[] mergeProperties(List<TestPropertySourceAttributes> attributesList) {
138-
final List<String> properties = new ArrayList<>();
139-
130+
List<String> properties = new ArrayList<>();
140131
for (TestPropertySourceAttributes attrs : attributesList) {
141132
if (logger.isTraceEnabled()) {
142133
logger.trace(String.format("Processing inlined properties for TestPropertySource attributes %s", attrs));
143134
}
144-
145-
properties.addAll(0, Arrays.<String> asList(attrs.getProperties()));
146-
135+
properties.addAll(0, Arrays.<String>asList(attrs.getProperties()));
147136
if (!attrs.isInheritProperties()) {
148137
break;
149138
}
150139
}
151-
152140
return StringUtils.toStringArray(properties);
153141
}
154142

@@ -168,8 +156,8 @@ private static String[] mergeProperties(List<TestPropertySourceAttributes> attri
168156
* @throws IllegalStateException if an error occurs while processing a properties file
169157
*/
170158
public static void addPropertiesFilesToEnvironment(ConfigurableApplicationContext context, String... locations) {
171-
Assert.notNull(context, "context must not be null");
172-
Assert.notNull(locations, "locations must not be null");
159+
Assert.notNull(context, "'context' must not be null");
160+
Assert.notNull(locations, "'locations' must not be null");
173161
addPropertiesFilesToEnvironment(context.getEnvironment(), context, locations);
174162
}
175163

@@ -196,9 +184,9 @@ public static void addPropertiesFilesToEnvironment(ConfigurableApplicationContex
196184
public static void addPropertiesFilesToEnvironment(ConfigurableEnvironment environment,
197185
ResourceLoader resourceLoader, String... locations) {
198186

199-
Assert.notNull(environment, "environment must not be null");
200-
Assert.notNull(resourceLoader, "resourceLoader must not be null");
201-
Assert.notNull(locations, "locations must not be null");
187+
Assert.notNull(environment, "'environment' must not be null");
188+
Assert.notNull(resourceLoader, "'resourceLoader' must not be null");
189+
Assert.notNull(locations, "'locations' must not be null");
202190
try {
203191
for (String location : locations) {
204192
String resolvedLocation = environment.resolveRequiredPlaceholders(location);
@@ -225,8 +213,8 @@ public static void addPropertiesFilesToEnvironment(ConfigurableEnvironment envir
225213
* @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
226214
*/
227215
public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties) {
228-
Assert.notNull(context, "context must not be null");
229-
Assert.notNull(inlinedProperties, "inlinedProperties must not be null");
216+
Assert.notNull(context, "'context' must not be null");
217+
Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null");
230218
addInlinedPropertiesToEnvironment(context.getEnvironment(), inlinedProperties);
231219
}
232220

@@ -247,13 +235,15 @@ public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationCont
247235
* @see #convertInlinedPropertiesToMap
248236
*/
249237
public static void addInlinedPropertiesToEnvironment(ConfigurableEnvironment environment, String... inlinedProperties) {
250-
Assert.notNull(environment, "environment must not be null");
251-
Assert.notNull(inlinedProperties, "inlinedProperties must not be null");
238+
Assert.notNull(environment, "'environment' must not be null");
239+
Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null");
252240
if (!ObjectUtils.isEmpty(inlinedProperties)) {
253241
if (logger.isDebugEnabled()) {
254-
logger.debug("Adding inlined properties to environment: " + ObjectUtils.nullSafeToString(inlinedProperties));
242+
logger.debug("Adding inlined properties to environment: " +
243+
ObjectUtils.nullSafeToString(inlinedProperties));
255244
}
256-
MapPropertySource ps = (MapPropertySource) environment.getPropertySources().get(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
245+
MapPropertySource ps = (MapPropertySource)
246+
environment.getPropertySources().get(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
257247
if (ps == null) {
258248
ps = new MapPropertySource(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME, new LinkedHashMap<>());
259249
environment.getPropertySources().addFirst(ps);
@@ -280,7 +270,7 @@ public static void addInlinedPropertiesToEnvironment(ConfigurableEnvironment env
280270
* @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
281271
*/
282272
public static Map<String, Object> convertInlinedPropertiesToMap(String... inlinedProperties) {
283-
Assert.notNull(inlinedProperties, "inlinedProperties must not be null");
273+
Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null");
284274
Map<String, Object> map = new LinkedHashMap<>();
285275
Properties props = new Properties();
286276

spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
import org.springframework.mock.env.MockPropertySource;
3333
import org.springframework.test.context.TestPropertySource;
3434

35-
import static org.hamcrest.CoreMatchers.containsString;
35+
import static org.hamcrest.CoreMatchers.*;
3636
import static org.hamcrest.CoreMatchers.startsWith;
3737
import static org.junit.Assert.*;
38-
import static org.mockito.Matchers.*;
38+
import static org.mockito.Matchers.anyString;
3939
import static org.mockito.Mockito.*;
4040
import static org.springframework.test.context.support.TestPropertySourceUtils.*;
4141

@@ -48,8 +48,11 @@
4848
public class TestPropertySourceUtilsTests {
4949

5050
private static final String[] EMPTY_STRING_ARRAY = new String[0];
51-
private static final String[] KEY_VALUE_PAIR = new String[] { "key = value" };
52-
private static final String[] FOO_LOCATIONS = new String[] { "classpath:/foo.properties" };
51+
52+
private static final String[] KEY_VALUE_PAIR = new String[] {"key = value"};
53+
54+
private static final String[] FOO_LOCATIONS = new String[] {"classpath:/foo.properties"};
55+
5356

5457
@Rule
5558
public ExpectedException expectedException = ExpectedException.none();
@@ -74,7 +77,7 @@ public void extendedEmptyAnnotation() {
7477
@Test
7578
public void value() {
7679
assertMergedTestPropertySources(ValuePropertySources.class, asArray("classpath:/value.xml"),
77-
EMPTY_STRING_ARRAY);
80+
EMPTY_STRING_ARRAY);
7881
}
7982

8083
@Test
@@ -86,67 +89,66 @@ public void locationsAndValueAttributes() {
8689
@Test
8790
public void locationsAndProperties() {
8891
assertMergedTestPropertySources(LocationsAndPropertiesPropertySources.class,
89-
asArray("classpath:/foo1.xml", "classpath:/foo2.xml"), asArray("k1a=v1a", "k1b: v1b"));
92+
asArray("classpath:/foo1.xml", "classpath:/foo2.xml"), asArray("k1a=v1a", "k1b: v1b"));
9093
}
9194

9295
@Test
9396
public void inheritedLocationsAndProperties() {
9497
assertMergedTestPropertySources(InheritedPropertySources.class,
95-
asArray("classpath:/foo1.xml", "classpath:/foo2.xml"), asArray("k1a=v1a", "k1b: v1b"));
98+
asArray("classpath:/foo1.xml", "classpath:/foo2.xml"), asArray("k1a=v1a", "k1b: v1b"));
9699
}
97100

98101
@Test
99102
public void extendedLocationsAndProperties() {
100103
assertMergedTestPropertySources(ExtendedPropertySources.class,
101-
asArray("classpath:/foo1.xml", "classpath:/foo2.xml", "classpath:/bar1.xml", "classpath:/bar2.xml"),
102-
asArray("k1a=v1a", "k1b: v1b", "k2a v2a", "k2b: v2b"));
104+
asArray("classpath:/foo1.xml", "classpath:/foo2.xml", "classpath:/bar1.xml", "classpath:/bar2.xml"),
105+
asArray("k1a=v1a", "k1b: v1b", "k2a v2a", "k2b: v2b"));
103106
}
104107

105108
@Test
106109
public void overriddenLocations() {
107110
assertMergedTestPropertySources(OverriddenLocationsPropertySources.class,
108-
asArray("classpath:/baz.properties"), asArray("k1a=v1a", "k1b: v1b", "key = value"));
111+
asArray("classpath:/baz.properties"), asArray("k1a=v1a", "k1b: v1b", "key = value"));
109112
}
110113

111114
@Test
112115
public void overriddenProperties() {
113116
assertMergedTestPropertySources(OverriddenPropertiesPropertySources.class,
114-
asArray("classpath:/foo1.xml", "classpath:/foo2.xml", "classpath:/baz.properties"), KEY_VALUE_PAIR);
117+
asArray("classpath:/foo1.xml", "classpath:/foo2.xml", "classpath:/baz.properties"), KEY_VALUE_PAIR);
115118
}
116119

117120
@Test
118121
public void overriddenLocationsAndProperties() {
119122
assertMergedTestPropertySources(OverriddenLocationsAndPropertiesPropertySources.class,
120-
asArray("classpath:/baz.properties"), KEY_VALUE_PAIR);
123+
asArray("classpath:/baz.properties"), KEY_VALUE_PAIR);
121124
}
122125

123-
// -------------------------------------------------------------------------
124126

125127
@Test
126128
public void addPropertiesFilesToEnvironmentWithNullContext() {
127129
expectedException.expect(IllegalArgumentException.class);
128-
expectedException.expectMessage("context must not be null");
130+
expectedException.expectMessage("must not be null");
129131
addPropertiesFilesToEnvironment((ConfigurableApplicationContext) null, FOO_LOCATIONS);
130132
}
131133

132134
@Test
133135
public void addPropertiesFilesToEnvironmentWithContextAndNullLocations() {
134136
expectedException.expect(IllegalArgumentException.class);
135-
expectedException.expectMessage("locations must not be null");
137+
expectedException.expectMessage("must not be null");
136138
addPropertiesFilesToEnvironment(mock(ConfigurableApplicationContext.class), (String[]) null);
137139
}
138140

139141
@Test
140142
public void addPropertiesFilesToEnvironmentWithNullEnvironment() {
141143
expectedException.expect(IllegalArgumentException.class);
142-
expectedException.expectMessage("environment must not be null");
144+
expectedException.expectMessage("must not be null");
143145
addPropertiesFilesToEnvironment((ConfigurableEnvironment) null, mock(ResourceLoader.class), FOO_LOCATIONS);
144146
}
145147

146148
@Test
147149
public void addPropertiesFilesToEnvironmentWithEnvironmentAndNullLocations() {
148150
expectedException.expect(IllegalArgumentException.class);
149-
expectedException.expectMessage("locations must not be null");
151+
expectedException.expectMessage("must not be null");
150152
addPropertiesFilesToEnvironment(new MockEnvironment(), mock(ResourceLoader.class), (String[]) null);
151153
}
152154

@@ -168,8 +170,6 @@ public void addPropertiesFilesToEnvironmentWithSinglePropertyFromVirtualFile() {
168170
assertEquals("value", environment.getProperty("key"));
169171
}
170172

171-
// -------------------------------------------------------------------------
172-
173173
@Test
174174
public void addInlinedPropertiesToEnvironmentWithNullContext() {
175175
expectedException.expect(IllegalArgumentException.class);
@@ -231,16 +231,17 @@ public void convertInlinedPropertiesToMapWithNullInlinedProperties() {
231231
convertInlinedPropertiesToMap((String[]) null);
232232
}
233233

234-
// -------------------------------------------------------------------
235234

236235
private static void assertMergedTestPropertySources(Class<?> testClass, String[] expectedLocations,
237236
String[] expectedProperties) {
237+
238238
MergedTestPropertySources mergedPropertySources = buildMergedTestPropertySources(testClass);
239239
assertNotNull(mergedPropertySources);
240240
assertArrayEquals(expectedLocations, mergedPropertySources.getLocations());
241241
assertArrayEquals(expectedProperties, mergedPropertySources.getProperties());
242242
}
243243

244+
244245
@SafeVarargs
245246
private static <T> T[] asArray(T... arr) {
246247
return arr;

spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,9 @@ public Jackson2ObjectMapperBuilder applicationContext(ApplicationContext applica
580580
public <T extends ObjectMapper> T build() {
581581
ObjectMapper mapper;
582582
if (this.createXmlMapper) {
583-
mapper = (this.defaultUseWrapper == null ? new XmlObjectMapperInitializer().create()
584-
: new XmlObjectMapperInitializer().create(this.defaultUseWrapper));
583+
mapper = (this.defaultUseWrapper != null ?
584+
new XmlObjectMapperInitializer().create(this.defaultUseWrapper) :
585+
new XmlObjectMapperInitializer().create());
585586
}
586587
else {
587588
mapper = new ObjectMapper();

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@
4949
*/
5050
public class CssLinkResourceTransformer extends ResourceTransformerSupport {
5151

52-
private static final Log logger = LogFactory.getLog(CssLinkResourceTransformer.class);
53-
5452
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
5553

54+
private static final Log logger = LogFactory.getLog(CssLinkResourceTransformer.class);
5655

57-
private final List<CssLinkParser> linkParsers = new ArrayList<>();
56+
private final List<CssLinkParser> linkParsers = new ArrayList<>(2);
5857

5958

6059
public CssLinkResourceTransformer() {
@@ -81,7 +80,7 @@ public Resource transform(HttpServletRequest request, Resource resource, Resourc
8180
byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
8281
String content = new String(bytes, DEFAULT_CHARSET);
8382

84-
Set<CssLinkInfo> infos = new HashSet<>(5);
83+
Set<CssLinkInfo> infos = new HashSet<>(8);
8584
for (CssLinkParser parser : this.linkParsers) {
8685
parser.parseLink(content, infos);
8786
}

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractXhrTransport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public String executeInfoRequest(URI infoUrl, HttpHeaders headers) {
143143

144144
protected abstract ResponseEntity<String> executeInfoRequestInternal(URI infoUrl, HttpHeaders headers);
145145

146+
146147
// XhrTransport methods
147148

148149
@Override

0 commit comments

Comments
 (0)