diff --git a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java index 89738660adb09b0b78158d5b0fa25f24ba6d158e..438c126f8adcc3c721d7fe08706183394f307819 100644 --- a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java @@ -77,7 +77,7 @@ public class AnnotationDrivenEventListenerTests { private EventCollector eventCollector; - private CountDownLatch countDownLatch; // 1 call by default + private CountDownLatch countDownLatch; // 1 call by default @After @@ -93,16 +93,23 @@ public class AnnotationDrivenEventListenerTests { load(TestEventListener.class); TestEvent event = new TestEvent(this, "test"); TestEventListener listener = this.context.getBean(TestEventListener.class); + this.eventCollector.assertNoEventReceived(listener); this.context.publishEvent(event); this.eventCollector.assertEvent(listener, event); this.eventCollector.assertTotalEventsCount(1); + + this.eventCollector.clear(); + this.context.publishEvent(event); + this.eventCollector.assertEvent(listener, event); + this.eventCollector.assertTotalEventsCount(1); } @Test public void simpleEventXmlConfig() { this.context = new ClassPathXmlApplicationContext( "org/springframework/context/event/simple-event-configuration.xml"); + TestEvent event = new TestEvent(this, "test"); TestEventListener listener = this.context.getBean(TestEventListener.class); this.eventCollector = getEventCollector(this.context); @@ -116,7 +123,6 @@ public class AnnotationDrivenEventListenerTests { @Test public void metaAnnotationIsDiscovered() { load(MetaAnnotationListenerTestBean.class); - MetaAnnotationListenerTestBean bean = this.context.getBean(MetaAnnotationListenerTestBean.class); this.eventCollector.assertNoEventReceived(bean); diff --git a/spring-context/src/test/java/org/springframework/context/event/test/EventCollector.java b/spring-context/src/test/java/org/springframework/context/event/test/EventCollector.java index 9df254c247c4cc28b563e04f43b206b6e0922f65..cbbee976e92980444042ad191d193c457ea3becc 100644 --- a/spring-context/src/test/java/org/springframework/context/event/test/EventCollector.java +++ b/spring-context/src/test/java/org/springframework/context/event/test/EventCollector.java @@ -30,6 +30,7 @@ import static org.junit.Assert.*; * Test utility to collect and assert events. * * @author Stephane Nicoll + * @author Juergen Hoeller */ @Component public class EventCollector { @@ -73,7 +74,7 @@ public class EventCollector { */ public void assertEvent(String listenerId, Object... events) { List actual = this.content.getOrDefault(listenerId, Collections.emptyList()); - assertEquals("wrong number of events", events.length, actual.size()); + assertEquals("Wrong number of events", events.length, actual.size()); for (int i = 0; i < events.length; i++) { assertEquals("Wrong event at index " + i, events[i], actual.get(i)); } @@ -97,8 +98,15 @@ public class EventCollector { for (Map.Entry> entry : this.content.entrySet()) { actual += entry.getValue().size(); } - assertEquals("Wrong number of total events (" + this.content.size() + ") " + - "registered listener(s)", number, actual); + assertEquals("Wrong number of total events (" + this.content.size() + + ") registered listener(s)", number, actual); + } + + /** + * Clear the collected events, allowing for reuse of the collector. + */ + public void clear() { + this.content.clear(); } } diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index af23835eb8eca2f77f500a80a6c30f9f027eb5ad..f52cd925f68c441e1694da90d0952ac31ef3f5a1 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -31,9 +31,6 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; -import static java.lang.String.*; -import static org.springframework.util.StringUtils.*; - /** * Abstract base class for {@link Environment} implementations. Supports the notion of * reserved default profile names and enables specifying active and default profiles @@ -124,7 +121,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { public AbstractEnvironment() { customizePropertySources(this.propertySources); if (this.logger.isDebugEnabled()) { - this.logger.debug(format( + this.logger.debug(String.format( "Initialized %s with PropertySources %s", getClass().getSimpleName(), this.propertySources)); } } @@ -242,7 +239,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { if (this.activeProfiles.isEmpty()) { String profiles = getProperty(ACTIVE_PROFILES_PROPERTY_NAME); if (StringUtils.hasText(profiles)) { - setActiveProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles))); + setActiveProfiles(StringUtils.commaDelimitedListToStringArray( + StringUtils.trimAllWhitespace(profiles))); } } return this.activeProfiles; @@ -264,7 +262,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { @Override public void addActiveProfile(String profile) { if (this.logger.isDebugEnabled()) { - this.logger.debug(format("Activating profile '%s'", profile)); + this.logger.debug(String.format("Activating profile '%s'", profile)); } validateProfile(profile); doGetActiveProfiles(); @@ -296,7 +294,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { if (this.defaultProfiles.equals(getReservedDefaultProfiles())) { String profiles = getProperty(DEFAULT_PROFILES_PROPERTY_NAME); if (StringUtils.hasText(profiles)) { - setDefaultProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles))); + setDefaultProfiles(StringUtils.commaDelimitedListToStringArray( + StringUtils.trimAllWhitespace(profiles))); } } return this.defaultProfiles; @@ -393,7 +392,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } catch (AccessControlException ex) { if (logger.isInfoEnabled()) { - logger.info(format("Caught AccessControlException when accessing system " + + logger.info(String.format("Caught AccessControlException when accessing system " + "environment variable [%s]; its value will be returned [null]. Reason: %s", attributeName, ex.getMessage())); } @@ -434,7 +433,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } catch (AccessControlException ex) { if (logger.isInfoEnabled()) { - logger.info(format("Caught AccessControlException when accessing system " + + logger.info(String.format("Caught AccessControlException when accessing system " + "property [%s]; its value will be returned [null]. Reason: %s", attributeName, ex.getMessage())); } @@ -569,7 +568,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { @Override public String toString() { - return format("%s {activeProfiles=%s, defaultProfiles=%s, propertySources=%s}", + return String.format("%s {activeProfiles=%s, defaultProfiles=%s, propertySources=%s}", getClass().getSimpleName(), this.activeProfiles, this.defaultProfiles, this.propertySources); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java index a2afa3a4386bf7318df5bbf0eba2ef0ab0b4b5e4..21e8b013623b4d7e863d9e29147c0b745e062e64 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java @@ -107,8 +107,7 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato @Override public Class getEndpointClass() { - return (this.endpoint != null) ? - this.endpoint.getClass() : ((Class) this.endpointProvider.getHandlerType()); + return (this.endpoint != null ? this.endpoint.getClass() : this.endpointProvider.getHandlerType()); } public Endpoint getEndpoint() { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/TomcatRequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/TomcatRequestUpgradeStrategy.java index 9ae54f9924c11655d87c9603d71314ac5f4347cb..0948aec5b73f898e8b4246ea65dd793dfebbfd18 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/TomcatRequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/TomcatRequestUpgradeStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.web.socket.server.standard; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -65,7 +64,7 @@ public class TomcatRequestUpgradeStrategy extends AbstractStandardUpgradeStrateg Map pathParams = Collections. emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); - endpointConfig.setSubprotocols(Arrays.asList(selectedProtocol)); + endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try {