Skip to content

Commit acbb254

Browse files
committed
Polishing
(cherry picked from commit 4ef428d)
1 parent d8f7347 commit acbb254

File tree

6 files changed

+41
-27
lines changed

6 files changed

+41
-27
lines changed

spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class AnnotationDrivenEventListenerTests {
7777

7878
private EventCollector eventCollector;
7979

80-
private CountDownLatch countDownLatch; // 1 call by default
80+
private CountDownLatch countDownLatch; // 1 call by default
8181

8282

8383
@After
@@ -93,16 +93,23 @@ public void simpleEventJavaConfig() {
9393
load(TestEventListener.class);
9494
TestEvent event = new TestEvent(this, "test");
9595
TestEventListener listener = this.context.getBean(TestEventListener.class);
96+
9697
this.eventCollector.assertNoEventReceived(listener);
9798
this.context.publishEvent(event);
9899
this.eventCollector.assertEvent(listener, event);
99100
this.eventCollector.assertTotalEventsCount(1);
101+
102+
this.eventCollector.clear();
103+
this.context.publishEvent(event);
104+
this.eventCollector.assertEvent(listener, event);
105+
this.eventCollector.assertTotalEventsCount(1);
100106
}
101107

102108
@Test
103109
public void simpleEventXmlConfig() {
104110
this.context = new ClassPathXmlApplicationContext(
105111
"org/springframework/context/event/simple-event-configuration.xml");
112+
106113
TestEvent event = new TestEvent(this, "test");
107114
TestEventListener listener = this.context.getBean(TestEventListener.class);
108115
this.eventCollector = getEventCollector(this.context);
@@ -116,7 +123,6 @@ public void simpleEventXmlConfig() {
116123
@Test
117124
public void metaAnnotationIsDiscovered() {
118125
load(MetaAnnotationListenerTestBean.class);
119-
120126
MetaAnnotationListenerTestBean bean = this.context.getBean(MetaAnnotationListenerTestBean.class);
121127
this.eventCollector.assertNoEventReceived(bean);
122128

spring-context/src/test/java/org/springframework/context/event/test/EventCollector.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* Test utility to collect and assert events.
3131
*
3232
* @author Stephane Nicoll
33+
* @author Juergen Hoeller
3334
*/
3435
@Component
3536
public class EventCollector {
@@ -73,7 +74,7 @@ public void assertNoEventReceived(Identifiable listener) {
7374
*/
7475
public void assertEvent(String listenerId, Object... events) {
7576
List<Object> actual = this.content.getOrDefault(listenerId, Collections.emptyList());
76-
assertEquals("wrong number of events", events.length, actual.size());
77+
assertEquals("Wrong number of events", events.length, actual.size());
7778
for (int i = 0; i < events.length; i++) {
7879
assertEquals("Wrong event at index " + i, events[i], actual.get(i));
7980
}
@@ -97,8 +98,15 @@ public void assertTotalEventsCount(int number) {
9798
for (Map.Entry<String, List<Object>> entry : this.content.entrySet()) {
9899
actual += entry.getValue().size();
99100
}
100-
assertEquals("Wrong number of total events (" + this.content.size() + ") " +
101-
"registered listener(s)", number, actual);
101+
assertEquals("Wrong number of total events (" + this.content.size() +
102+
") registered listener(s)", number, actual);
103+
}
104+
105+
/**
106+
* Clear the collected events, allowing for reuse of the collector.
107+
*/
108+
public void clear() {
109+
this.content.clear();
102110
}
103111

104112
}

spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
import org.springframework.util.ObjectUtils;
3232
import org.springframework.util.StringUtils;
3333

34-
import static java.lang.String.*;
35-
import static org.springframework.util.StringUtils.*;
36-
3734
/**
3835
* Abstract base class for {@link Environment} implementations. Supports the notion of
3936
* reserved default profile names and enables specifying active and default profiles
@@ -124,7 +121,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
124121
public AbstractEnvironment() {
125122
customizePropertySources(this.propertySources);
126123
if (this.logger.isDebugEnabled()) {
127-
this.logger.debug(format(
124+
this.logger.debug(String.format(
128125
"Initialized %s with PropertySources %s", getClass().getSimpleName(), this.propertySources));
129126
}
130127
}
@@ -242,7 +239,8 @@ protected Set<String> doGetActiveProfiles() {
242239
if (this.activeProfiles.isEmpty()) {
243240
String profiles = getProperty(ACTIVE_PROFILES_PROPERTY_NAME);
244241
if (StringUtils.hasText(profiles)) {
245-
setActiveProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles)));
242+
setActiveProfiles(StringUtils.commaDelimitedListToStringArray(
243+
StringUtils.trimAllWhitespace(profiles)));
246244
}
247245
}
248246
return this.activeProfiles;
@@ -264,7 +262,7 @@ public void setActiveProfiles(String... profiles) {
264262
@Override
265263
public void addActiveProfile(String profile) {
266264
if (this.logger.isDebugEnabled()) {
267-
this.logger.debug(format("Activating profile '%s'", profile));
265+
this.logger.debug(String.format("Activating profile '%s'", profile));
268266
}
269267
validateProfile(profile);
270268
doGetActiveProfiles();
@@ -296,7 +294,8 @@ protected Set<String> doGetDefaultProfiles() {
296294
if (this.defaultProfiles.equals(getReservedDefaultProfiles())) {
297295
String profiles = getProperty(DEFAULT_PROFILES_PROPERTY_NAME);
298296
if (StringUtils.hasText(profiles)) {
299-
setDefaultProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles)));
297+
setDefaultProfiles(StringUtils.commaDelimitedListToStringArray(
298+
StringUtils.trimAllWhitespace(profiles)));
300299
}
301300
}
302301
return this.defaultProfiles;
@@ -393,7 +392,7 @@ protected String getSystemAttribute(String attributeName) {
393392
}
394393
catch (AccessControlException ex) {
395394
if (logger.isInfoEnabled()) {
396-
logger.info(format("Caught AccessControlException when accessing system " +
395+
logger.info(String.format("Caught AccessControlException when accessing system " +
397396
"environment variable [%s]; its value will be returned [null]. Reason: %s",
398397
attributeName, ex.getMessage()));
399398
}
@@ -434,7 +433,7 @@ protected String getSystemAttribute(String attributeName) {
434433
}
435434
catch (AccessControlException ex) {
436435
if (logger.isInfoEnabled()) {
437-
logger.info(format("Caught AccessControlException when accessing system " +
436+
logger.info(String.format("Caught AccessControlException when accessing system " +
438437
"property [%s]; its value will be returned [null]. Reason: %s",
439438
attributeName, ex.getMessage()));
440439
}
@@ -575,7 +574,7 @@ public String resolveRequiredPlaceholders(String text) throws IllegalArgumentExc
575574

576575
@Override
577576
public String toString() {
578-
return format("%s {activeProfiles=%s, defaultProfiles=%s, propertySources=%s}",
577+
return String.format("%s {activeProfiles=%s, defaultProfiles=%s, propertySources=%s}",
579578
getClass().getSimpleName(), this.activeProfiles, this.defaultProfiles,
580579
this.propertySources);
581580
}

spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java

Lines changed: 9 additions & 6 deletions
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-2016 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.
@@ -61,13 +61,15 @@ public class HttpPutFormContentFilter extends OncePerRequestFilter {
6161

6262
private final FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();
6363

64+
6465
/**
6566
* The default character set to use for reading form data.
6667
*/
6768
public void setCharset(Charset charset) {
6869
this.formConverter.setCharset(charset);
6970
}
7071

72+
7173
@Override
7274
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
7375
FilterChain filterChain) throws ServletException, IOException {
@@ -104,29 +106,30 @@ private boolean isFormContentType(HttpServletRequest request) {
104106
}
105107
}
106108

109+
107110
private static class HttpPutFormContentRequestWrapper extends HttpServletRequestWrapper {
108111

109112
private MultiValueMap<String, String> formParameters;
110113

111114
public HttpPutFormContentRequestWrapper(HttpServletRequest request, MultiValueMap<String, String> parameters) {
112115
super(request);
113-
this.formParameters = (parameters != null) ? parameters : new LinkedMultiValueMap<String, String>();
116+
this.formParameters = (parameters != null ? parameters : new LinkedMultiValueMap<String, String>());
114117
}
115118

116119
@Override
117120
public String getParameter(String name) {
118121
String queryStringValue = super.getParameter(name);
119122
String formValue = this.formParameters.getFirst(name);
120-
return (queryStringValue != null) ? queryStringValue : formValue;
123+
return (queryStringValue != null ? queryStringValue : formValue);
121124
}
122125

123126
@Override
124127
public Map<String, String[]> getParameterMap() {
125128
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
126-
Enumeration<String> names = this.getParameterNames();
129+
Enumeration<String> names = getParameterNames();
127130
while (names.hasMoreElements()) {
128131
String name = names.nextElement();
129-
result.put(name, this.getParameterValues(name));
132+
result.put(name, getParameterValues(name));
130133
}
131134
return result;
132135
}
@@ -150,7 +153,7 @@ else if (queryStringValues == null) {
150153
return formValues.toArray(new String[formValues.size()]);
151154
}
152155
else {
153-
List<String> result = new ArrayList<String>();
156+
List<String> result = new ArrayList<String>(queryStringValues.length + formValues.size());
154157
result.addAll(Arrays.asList(queryStringValues));
155158
result.addAll(formValues);
156159
return result.toArray(new String[result.size()]);

spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java

Lines changed: 2 additions & 3 deletions
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-2016 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.
@@ -107,8 +107,7 @@ public String getPath() {
107107

108108
@Override
109109
public Class<? extends Endpoint> getEndpointClass() {
110-
return (this.endpoint != null) ?
111-
this.endpoint.getClass() : ((Class<? extends Endpoint>) this.endpointProvider.getHandlerType());
110+
return (this.endpoint != null ? this.endpoint.getClass() : this.endpointProvider.getHandlerType());
112111
}
113112

114113
public Endpoint getEndpoint() {

spring-websocket/src/main/java/org/springframework/web/socket/server/standard/TomcatRequestUpgradeStrategy.java

Lines changed: 2 additions & 3 deletions
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-2016 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.
@@ -17,7 +17,6 @@
1717
package org.springframework.web.socket.server.standard;
1818

1919
import java.io.IOException;
20-
import java.util.Arrays;
2120
import java.util.Collections;
2221
import java.util.List;
2322
import java.util.Map;
@@ -65,7 +64,7 @@ public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse respon
6564
Map<String, String> pathParams = Collections.<String, String> emptyMap();
6665

6766
ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint);
68-
endpointConfig.setSubprotocols(Arrays.asList(selectedProtocol));
67+
endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol));
6968
endpointConfig.setExtensions(selectedExtensions);
7069

7170
try {

0 commit comments

Comments
 (0)