Migrate Hamcrest assertions to AssertJ
Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ and add checkstyle rules to ensure they don't return. See gh-23022
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.web.socket;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Test fixture for {@link TextMessage}.
|
||||
@@ -33,16 +33,16 @@ public class TextMessageTests {
|
||||
public void toStringWithAscii() {
|
||||
String expected = "foo,bar";
|
||||
TextMessage actual = new TextMessage(expected);
|
||||
assertThat(actual.getPayload(), Matchers.is(expected));
|
||||
assertThat(actual.toString(), Matchers.containsString(expected));
|
||||
assertThat(actual.getPayload()).isEqualTo(expected);
|
||||
assertThat(actual.toString()).contains(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWithMultibyteString() {
|
||||
String expected = "\u3042\u3044\u3046\u3048\u304a";
|
||||
TextMessage actual = new TextMessage(expected);
|
||||
assertThat(actual.getPayload(), Matchers.is(expected));
|
||||
assertThat(actual.toString(), Matchers.containsString(expected));
|
||||
assertThat(actual.getPayload()).isEqualTo(expected);
|
||||
assertThat(actual.toString()).contains(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@ package org.springframework.web.socket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
@@ -33,7 +32,7 @@ public class WebSocketExtensionTests {
|
||||
@Test
|
||||
public void parseHeaderSingle() {
|
||||
List<WebSocketExtension> extensions = WebSocketExtension.parseExtensions("x-test-extension ; foo=bar ; bar=baz");
|
||||
assertThat(extensions, Matchers.hasSize(1));
|
||||
assertThat(extensions).hasSize(1);
|
||||
WebSocketExtension extension = extensions.get(0);
|
||||
|
||||
assertEquals("x-test-extension", extension.getName());
|
||||
@@ -45,9 +44,8 @@ public class WebSocketExtensionTests {
|
||||
@Test
|
||||
public void parseHeaderMultiple() {
|
||||
List<WebSocketExtension> extensions = WebSocketExtension.parseExtensions("x-foo-extension, x-bar-extension");
|
||||
assertThat(extensions, Matchers.hasSize(2));
|
||||
assertEquals("x-foo-extension", extensions.get(0).getName());
|
||||
assertEquals("x-bar-extension", extensions.get(1).getName());
|
||||
assertThat(extensions.stream().map(WebSocketExtension::getName))
|
||||
.containsExactly("x-foo-extension", "x-bar-extension");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,11 +38,12 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.socket.ContextLoaderTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test for {@link org.springframework.web.socket.adapter.standard.ConvertingEncoderDecoderSupport}.
|
||||
@@ -81,7 +82,7 @@ public class ConvertingEncoderDecoderSupportTests {
|
||||
|
||||
@Test
|
||||
public void encodeToText() throws Exception {
|
||||
assertThat(new MyTextEncoder().encode(myType), equalTo(CONVERTED_TEXT));
|
||||
assertThat(new MyTextEncoder().encode(myType)).isEqualTo(CONVERTED_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,8 +95,8 @@ public class ConvertingEncoderDecoderSupportTests {
|
||||
|
||||
@Test
|
||||
public void encodeToBinary() throws Exception {
|
||||
assertThat(new MyBinaryEncoder().encode(myType).array(),
|
||||
equalTo(CONVERTED_BYTES.array()));
|
||||
assertThat(new MyBinaryEncoder().encode(myType).array())
|
||||
.isEqualTo(CONVERTED_BYTES.array());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,15 +110,15 @@ public class ConvertingEncoderDecoderSupportTests {
|
||||
@Test
|
||||
public void decodeFromText() throws Exception {
|
||||
Decoder.Text<MyType> decoder = new MyTextDecoder();
|
||||
assertThat(decoder.willDecode(CONVERTED_TEXT), is(true));
|
||||
assertThat(decoder.decode(CONVERTED_TEXT), equalTo(myType));
|
||||
assertThat(decoder.willDecode(CONVERTED_TEXT)).isTrue();
|
||||
assertThat(decoder.decode(CONVERTED_TEXT)).isEqualTo(myType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeFromTextCannotConvert() throws Exception {
|
||||
setup(NoConvertersConfig.class);
|
||||
Decoder.Text<MyType> decoder = new MyTextDecoder();
|
||||
assertThat(decoder.willDecode(CONVERTED_TEXT), is(false));
|
||||
assertThat(decoder.willDecode(CONVERTED_TEXT)).isFalse();
|
||||
assertThatExceptionOfType(DecodeException.class).isThrownBy(() ->
|
||||
decoder.decode(CONVERTED_TEXT))
|
||||
.withCauseInstanceOf(ConverterNotFoundException.class);
|
||||
@@ -126,15 +127,15 @@ public class ConvertingEncoderDecoderSupportTests {
|
||||
@Test
|
||||
public void decodeFromBinary() throws Exception {
|
||||
Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
|
||||
assertThat(decoder.willDecode(CONVERTED_BYTES), is(true));
|
||||
assertThat(decoder.decode(CONVERTED_BYTES), equalTo(myType));
|
||||
assertThat(decoder.willDecode(CONVERTED_BYTES)).isTrue();
|
||||
assertThat(decoder.decode(CONVERTED_BYTES)).isEqualTo(myType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeFromBinaryCannotConvert() throws Exception {
|
||||
setup(NoConvertersConfig.class);
|
||||
Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
|
||||
assertThat(decoder.willDecode(CONVERTED_BYTES), is(false));
|
||||
assertThat(decoder.willDecode(CONVERTED_BYTES)).isFalse();
|
||||
assertThatExceptionOfType(DecodeException.class).isThrownBy(() ->
|
||||
decoder.decode(CONVERTED_BYTES))
|
||||
.withCauseInstanceOf(ConverterNotFoundException.class);
|
||||
@@ -144,21 +145,21 @@ public class ConvertingEncoderDecoderSupportTests {
|
||||
public void encodeAndDecodeText() throws Exception {
|
||||
MyTextEncoderDecoder encoderDecoder = new MyTextEncoderDecoder();
|
||||
String encoded = encoderDecoder.encode(myType);
|
||||
assertThat(encoderDecoder.decode(encoded), equalTo(myType));
|
||||
assertThat(encoderDecoder.decode(encoded)).isEqualTo(myType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeAndDecodeBytes() throws Exception {
|
||||
MyBinaryEncoderDecoder encoderDecoder = new MyBinaryEncoderDecoder();
|
||||
ByteBuffer encoded = encoderDecoder.encode(myType);
|
||||
assertThat(encoderDecoder.decode(encoded), equalTo(myType));
|
||||
assertThat(encoderDecoder.decode(encoded)).isEqualTo(myType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autowiresIntoEncoder() throws Exception {
|
||||
WithAutowire withAutowire = new WithAutowire();
|
||||
withAutowire.init(null);
|
||||
assertThat(withAutowire.config, equalTo(applicationContext.getBean(Config.class)));
|
||||
assertThat(withAutowire.config).isEqualTo(applicationContext.getBean(Config.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -60,11 +60,7 @@ import org.springframework.web.socket.sockjs.transport.handler.XhrPollingTranspo
|
||||
import org.springframework.web.socket.sockjs.transport.handler.XhrReceivingTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.XhrStreamingTransportHandler;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -89,14 +85,14 @@ public class HandlersBeanDefinitionParserTests {
|
||||
|
||||
Map<String, HandlerMapping> handlersMap = this.appContext.getBeansOfType(HandlerMapping.class);
|
||||
assertNotNull(handlersMap);
|
||||
assertThat(handlersMap.values(), hasSize(2));
|
||||
assertThat(handlersMap).hasSize(2);
|
||||
|
||||
for (HandlerMapping hm : handlersMap.values()) {
|
||||
assertTrue(hm instanceof SimpleUrlHandlerMapping);
|
||||
SimpleUrlHandlerMapping shm = (SimpleUrlHandlerMapping) hm;
|
||||
|
||||
if (shm.getUrlMap().keySet().contains("/foo")) {
|
||||
assertThat(shm.getUrlMap().keySet(), contains("/foo", "/bar"));
|
||||
assertThat(shm.getUrlMap()).containsOnlyKeys("/foo", "/bar");
|
||||
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/foo");
|
||||
assertNotNull(handler);
|
||||
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
|
||||
@@ -107,7 +103,7 @@ public class HandlersBeanDefinitionParserTests {
|
||||
assertTrue(handler.getHandshakeInterceptors().get(0) instanceof OriginHandshakeInterceptor);
|
||||
}
|
||||
else {
|
||||
assertThat(shm.getUrlMap().keySet(), contains("/test"));
|
||||
assertThat(shm.getUrlMap()).containsOnlyKeys("/test");
|
||||
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/test");
|
||||
assertNotNull(handler);
|
||||
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
|
||||
@@ -139,8 +135,8 @@ public class HandlersBeanDefinitionParserTests {
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof TestHandshakeHandler);
|
||||
List<HandshakeInterceptor> interceptors = handler.getHandshakeInterceptors();
|
||||
assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
|
||||
instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
|
||||
assertThat(interceptors).extracting("class")
|
||||
.containsExactlyInAnyOrder(FooTestInterceptor.class, BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
|
||||
handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/test");
|
||||
assertNotNull(handler);
|
||||
@@ -149,8 +145,8 @@ public class HandlersBeanDefinitionParserTests {
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof TestHandshakeHandler);
|
||||
interceptors = handler.getHandshakeInterceptors();
|
||||
assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
|
||||
instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
|
||||
assertThat(interceptors).extracting("class")
|
||||
.containsExactlyInAnyOrder(FooTestInterceptor.class, BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,27 +170,27 @@ public class HandlersBeanDefinitionParserTests {
|
||||
|
||||
assertSame(testSockJsService, sockJsService);
|
||||
|
||||
assertThat(sockJsService, instanceOf(DefaultSockJsService.class));
|
||||
assertThat(sockJsService).isInstanceOf(DefaultSockJsService.class);
|
||||
DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService;
|
||||
assertThat(defaultSockJsService.getTaskScheduler(), instanceOf(ThreadPoolTaskScheduler.class));
|
||||
assertThat(defaultSockJsService.getTaskScheduler()).isInstanceOf(ThreadPoolTaskScheduler.class);
|
||||
assertFalse(defaultSockJsService.shouldSuppressCors());
|
||||
|
||||
Map<TransportType, TransportHandler> handlerMap = defaultSockJsService.getTransportHandlers();
|
||||
assertThat(handlerMap.values(),
|
||||
containsInAnyOrder(
|
||||
instanceOf(XhrPollingTransportHandler.class),
|
||||
instanceOf(XhrReceivingTransportHandler.class),
|
||||
instanceOf(XhrStreamingTransportHandler.class),
|
||||
instanceOf(EventSourceTransportHandler.class),
|
||||
instanceOf(HtmlFileTransportHandler.class),
|
||||
instanceOf(WebSocketTransportHandler.class)));
|
||||
assertThat(handlerMap.values()).extracting("class")
|
||||
.containsExactlyInAnyOrder(
|
||||
XhrPollingTransportHandler.class,
|
||||
XhrReceivingTransportHandler.class,
|
||||
XhrStreamingTransportHandler.class,
|
||||
EventSourceTransportHandler.class,
|
||||
HtmlFileTransportHandler.class,
|
||||
WebSocketTransportHandler.class);
|
||||
|
||||
WebSocketTransportHandler handler = (WebSocketTransportHandler) handlerMap.get(TransportType.WEBSOCKET);
|
||||
assertEquals(TestHandshakeHandler.class, handler.getHandshakeHandler().getClass());
|
||||
|
||||
List<HandshakeInterceptor> interceptors = defaultSockJsService.getHandshakeInterceptors();
|
||||
assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
|
||||
instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
|
||||
assertThat(interceptors).extracting("class")
|
||||
.containsExactlyInAnyOrder(FooTestInterceptor.class, BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -211,13 +207,11 @@ public class HandlersBeanDefinitionParserTests {
|
||||
|
||||
SockJsService sockJsService = handler.getSockJsService();
|
||||
assertNotNull(sockJsService);
|
||||
assertThat(sockJsService, instanceOf(TransportHandlingSockJsService.class));
|
||||
assertThat(sockJsService).isInstanceOf(TransportHandlingSockJsService.class);
|
||||
TransportHandlingSockJsService transportService = (TransportHandlingSockJsService) sockJsService;
|
||||
assertThat(transportService.getTaskScheduler(), instanceOf(TestTaskScheduler.class));
|
||||
assertThat(transportService.getTransportHandlers().values(),
|
||||
containsInAnyOrder(
|
||||
instanceOf(XhrPollingTransportHandler.class),
|
||||
instanceOf(XhrStreamingTransportHandler.class)));
|
||||
assertThat(transportService.getTaskScheduler()).isInstanceOf(TestTaskScheduler.class);
|
||||
assertThat(transportService.getTransportHandlers().values()).extracting("class")
|
||||
.containsExactlyInAnyOrder(XhrPollingTransportHandler.class, XhrStreamingTransportHandler.class);
|
||||
|
||||
assertEquals("testSockJsService", transportService.getName());
|
||||
assertFalse(transportService.isWebSocketEnabled());
|
||||
@@ -230,7 +224,7 @@ public class HandlersBeanDefinitionParserTests {
|
||||
assertEquals(TestMessageCodec.class, transportService.getMessageCodec().getClass());
|
||||
|
||||
List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors();
|
||||
assertThat(interceptors, contains(instanceOf(OriginHandshakeInterceptor.class)));
|
||||
assertThat(interceptors).extracting("class").containsExactly(OriginHandshakeInterceptor.class);
|
||||
assertTrue(transportService.shouldSuppressCors());
|
||||
assertTrue(transportService.getAllowedOrigins().contains("https://mydomain1.com"));
|
||||
assertTrue(transportService.getAllowedOrigins().contains("https://mydomain2.com"));
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
@@ -90,10 +89,8 @@ import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -120,35 +117,34 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
loadBeanDefinitions("websocket-config-broker-simple.xml");
|
||||
|
||||
HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
|
||||
assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class));
|
||||
assertThat(hm).isInstanceOf(SimpleUrlHandlerMapping.class);
|
||||
SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
|
||||
assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(4));
|
||||
assertThat(suhm.getUrlMap().values(), Matchers.hasSize(4));
|
||||
assertThat(suhm.getUrlMap()).hasSize(4);
|
||||
|
||||
HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo");
|
||||
assertNotNull(httpRequestHandler);
|
||||
assertThat(httpRequestHandler, Matchers.instanceOf(WebSocketHttpRequestHandler.class));
|
||||
assertThat(httpRequestHandler).isInstanceOf(WebSocketHttpRequestHandler.class);
|
||||
|
||||
WebSocketHttpRequestHandler wsHttpRequestHandler = (WebSocketHttpRequestHandler) httpRequestHandler;
|
||||
HandshakeHandler handshakeHandler = wsHttpRequestHandler.getHandshakeHandler();
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof TestHandshakeHandler);
|
||||
List<HandshakeInterceptor> interceptors = wsHttpRequestHandler.getHandshakeInterceptors();
|
||||
assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
|
||||
instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
|
||||
assertThat(interceptors).extracting("class").containsExactly(FooTestInterceptor.class,
|
||||
BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
|
||||
WebSocketSession session = new TestWebSocketSession("id");
|
||||
wsHttpRequestHandler.getWebSocketHandler().afterConnectionEstablished(session);
|
||||
assertEquals(true, session.getAttributes().get("decorated"));
|
||||
|
||||
WebSocketHandler wsHandler = wsHttpRequestHandler.getWebSocketHandler();
|
||||
assertThat(wsHandler, Matchers.instanceOf(ExceptionWebSocketHandlerDecorator.class));
|
||||
assertThat(wsHandler).isInstanceOf(ExceptionWebSocketHandlerDecorator.class);
|
||||
wsHandler = ((ExceptionWebSocketHandlerDecorator) wsHandler).getDelegate();
|
||||
assertThat(wsHandler, Matchers.instanceOf(LoggingWebSocketHandlerDecorator.class));
|
||||
assertThat(wsHandler).isInstanceOf(LoggingWebSocketHandlerDecorator.class);
|
||||
wsHandler = ((LoggingWebSocketHandlerDecorator) wsHandler).getDelegate();
|
||||
assertThat(wsHandler, Matchers.instanceOf(TestWebSocketHandlerDecorator.class));
|
||||
assertThat(wsHandler).isInstanceOf(TestWebSocketHandlerDecorator.class);
|
||||
wsHandler = ((TestWebSocketHandlerDecorator) wsHandler).getDelegate();
|
||||
assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
|
||||
assertThat(wsHandler).isInstanceOf(SubProtocolWebSocketHandler.class);
|
||||
assertSame(wsHandler, this.appContext.getBean(MessageBrokerBeanDefinitionParser.WEB_SOCKET_HANDLER_BEAN_NAME));
|
||||
|
||||
SubProtocolWebSocketHandler subProtocolWsHandler = (SubProtocolWebSocketHandler) wsHandler;
|
||||
@@ -168,20 +164,20 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
|
||||
httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/test/**");
|
||||
assertNotNull(httpRequestHandler);
|
||||
assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class));
|
||||
assertThat(httpRequestHandler).isInstanceOf(SockJsHttpRequestHandler.class);
|
||||
|
||||
SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
|
||||
wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
|
||||
assertNotNull(wsHandler);
|
||||
assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
|
||||
assertThat(wsHandler).isInstanceOf(SubProtocolWebSocketHandler.class);
|
||||
assertNotNull(sockJsHttpRequestHandler.getSockJsService());
|
||||
assertThat(sockJsHttpRequestHandler.getSockJsService(), Matchers.instanceOf(DefaultSockJsService.class));
|
||||
assertThat(sockJsHttpRequestHandler.getSockJsService()).isInstanceOf(DefaultSockJsService.class);
|
||||
|
||||
DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsHttpRequestHandler.getSockJsService();
|
||||
WebSocketTransportHandler wsTransportHandler = (WebSocketTransportHandler) defaultSockJsService
|
||||
.getTransportHandlers().get(TransportType.WEBSOCKET);
|
||||
assertNotNull(wsTransportHandler.getHandshakeHandler());
|
||||
assertThat(wsTransportHandler.getHandshakeHandler(), Matchers.instanceOf(TestHandshakeHandler.class));
|
||||
assertThat(wsTransportHandler.getHandshakeHandler()).isInstanceOf(TestHandshakeHandler.class);
|
||||
assertFalse(defaultSockJsService.shouldSuppressCors());
|
||||
|
||||
ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) defaultSockJsService.getTaskScheduler();
|
||||
@@ -190,8 +186,8 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
assertTrue(executor.getRemoveOnCancelPolicy());
|
||||
|
||||
interceptors = defaultSockJsService.getHandshakeInterceptors();
|
||||
assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
|
||||
instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
|
||||
assertThat(interceptors).extracting("class").containsExactly(FooTestInterceptor.class,
|
||||
BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
assertTrue(defaultSockJsService.getAllowedOrigins().contains("https://mydomain3.com"));
|
||||
assertTrue(defaultSockJsService.getAllowedOrigins().contains("https://mydomain4.com"));
|
||||
|
||||
@@ -201,7 +197,7 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
|
||||
UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
|
||||
assertNotNull(userDestResolver);
|
||||
assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class));
|
||||
assertThat(userDestResolver).isInstanceOf(DefaultUserDestinationResolver.class);
|
||||
DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
|
||||
assertEquals("/personal/", defaultUserDestResolver.getDestinationPrefix());
|
||||
|
||||
@@ -246,25 +242,24 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
|
||||
HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
|
||||
assertNotNull(hm);
|
||||
assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class));
|
||||
assertThat(hm).isInstanceOf(SimpleUrlHandlerMapping.class);
|
||||
|
||||
SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
|
||||
assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(1));
|
||||
assertThat(suhm.getUrlMap().values(), Matchers.hasSize(1));
|
||||
assertThat(suhm.getUrlMap()).hasSize(1);
|
||||
assertEquals(2, suhm.getOrder());
|
||||
|
||||
HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**");
|
||||
assertNotNull(httpRequestHandler);
|
||||
assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class));
|
||||
assertThat(httpRequestHandler).isInstanceOf(SockJsHttpRequestHandler.class);
|
||||
SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
|
||||
WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
|
||||
assertNotNull(wsHandler);
|
||||
assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
|
||||
assertThat(wsHandler).isInstanceOf(SubProtocolWebSocketHandler.class);
|
||||
assertNotNull(sockJsHttpRequestHandler.getSockJsService());
|
||||
|
||||
UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
|
||||
assertNotNull(userDestResolver);
|
||||
assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class));
|
||||
assertThat(userDestResolver).isInstanceOf(DefaultUserDestinationResolver.class);
|
||||
DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
|
||||
assertEquals("/user/", defaultUserDestResolver.getDestinationPrefix());
|
||||
|
||||
@@ -279,7 +274,7 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
assertEquals("spring.io", messageBroker.getVirtualHost());
|
||||
assertEquals(5000, messageBroker.getSystemHeartbeatReceiveInterval());
|
||||
assertEquals(5000, messageBroker.getSystemHeartbeatSendInterval());
|
||||
assertThat(messageBroker.getDestinationPrefixes(), Matchers.containsInAnyOrder("/topic","/queue"));
|
||||
assertThat(messageBroker.getDestinationPrefixes()).containsExactlyInAnyOrder("/topic","/queue");
|
||||
assertTrue(messageBroker.isPreservePublishOrder());
|
||||
|
||||
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
|
||||
@@ -351,10 +346,10 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
assertEquals("/personal/", simpMessagingTemplate.getUserDestinationPrefix());
|
||||
|
||||
List<MessageConverter> converters = compositeMessageConverter.getConverters();
|
||||
assertThat(converters.size(), Matchers.is(3));
|
||||
assertThat(converters.get(0), Matchers.instanceOf(StringMessageConverter.class));
|
||||
assertThat(converters.get(1), Matchers.instanceOf(ByteArrayMessageConverter.class));
|
||||
assertThat(converters.get(2), Matchers.instanceOf(MappingJackson2MessageConverter.class));
|
||||
assertThat(converters).hasSize(3);
|
||||
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
|
||||
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
|
||||
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
|
||||
|
||||
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
|
||||
assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
|
||||
@@ -375,7 +370,7 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
Validator validator = annotationMethodMessageHandler.getValidator();
|
||||
assertNotNull(validator);
|
||||
assertSame(this.appContext.getBean("myValidator"), validator);
|
||||
assertThat(validator, Matchers.instanceOf(TestValidator.class));
|
||||
assertThat(validator).isInstanceOf(TestValidator.class);
|
||||
|
||||
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
|
||||
UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
|
||||
|
||||
@@ -19,14 +19,14 @@ package org.springframework.web.socket.handler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for WebSocketHttpHeaders.
|
||||
@@ -50,7 +50,7 @@ public class WebSocketHttpHeadersTests {
|
||||
this.headers.put(WebSocketHttpHeaders.SEC_WEBSOCKET_EXTENSIONS, extensions);
|
||||
|
||||
List<WebSocketExtension> parsedExtensions = this.headers.getSecWebSocketExtensions();
|
||||
assertThat(parsedExtensions, Matchers.hasSize(3));
|
||||
assertThat(parsedExtensions).hasSize(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ import org.springframework.web.socket.WebSocketMessage;
|
||||
import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
import org.springframework.web.socket.sockjs.transport.SockJsSession;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -492,7 +491,7 @@ public class StompSubProtocolHandlerTests {
|
||||
@Override
|
||||
public boolean send(Message<?> message) {
|
||||
SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes();
|
||||
assertThat(simpAttributes.getAttribute("name"), is("value"));
|
||||
assertThat(simpAttributes.getAttribute("name")).isEqualTo("value");
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -48,8 +48,7 @@ import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -121,7 +120,7 @@ public class WebSocketStompClientIntegrationTests {
|
||||
this.stompClient.connect(url, testHandler);
|
||||
|
||||
assertTrue(testHandler.awaitForMessageCount(1, 5000));
|
||||
assertThat(testHandler.getReceived(), containsInAnyOrder("payload"));
|
||||
assertThat(testHandler.getReceived()).containsExactly("payload");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,11 +34,8 @@ import org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec;
|
||||
import org.springframework.web.socket.sockjs.frame.SockJsFrame;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -76,11 +73,11 @@ public class ClientSockJsSessionTests {
|
||||
|
||||
@Test
|
||||
public void handleFrameOpen() throws Exception {
|
||||
assertThat(this.session.isOpen(), is(false));
|
||||
assertThat(this.session.isOpen()).isFalse();
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.isOpen(), is(true));
|
||||
assertThat(this.session.isOpen()).isTrue();
|
||||
assertTrue(this.connectFuture.isDone());
|
||||
assertThat(this.connectFuture.get(), sameInstance(this.session));
|
||||
assertThat(this.connectFuture.get()).isSameAs(this.session);
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
}
|
||||
@@ -88,16 +85,16 @@ public class ClientSockJsSessionTests {
|
||||
@Test
|
||||
public void handleFrameOpenWhenStatusNotNew() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.isOpen(), is(true));
|
||||
assertThat(this.session.isOpen()).isTrue();
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.disconnectStatus, equalTo(new CloseStatus(1006, "Server lost session")));
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(1006, "Server lost session"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameOpenWithWebSocketHandlerException() throws Exception {
|
||||
willThrow(new IllegalStateException("Fake error")).given(this.handler).afterConnectionEstablished(this.session);
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.isOpen(), is(true));
|
||||
assertThat(this.session.isOpen()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,8 +120,8 @@ public class ClientSockJsSessionTests {
|
||||
public void handleFrameMessageWithBadData() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.handleFrame("a['bad data");
|
||||
assertThat(this.session.isOpen(), equalTo(false));
|
||||
assertThat(this.session.disconnectStatus, equalTo(CloseStatus.BAD_DATA));
|
||||
assertThat(this.session.isOpen()).isEqualTo(false);
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(CloseStatus.BAD_DATA);
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
}
|
||||
@@ -137,7 +134,7 @@ public class ClientSockJsSessionTests {
|
||||
willThrow(new IllegalStateException("Fake error")).given(this.handler)
|
||||
.handleMessage(this.session, new TextMessage("bar"));
|
||||
this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
|
||||
assertThat(this.session.isOpen(), equalTo(true));
|
||||
assertThat(this.session.isOpen()).isEqualTo(true);
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
verify(this.handler).handleMessage(this.session, new TextMessage("foo"));
|
||||
verify(this.handler).handleMessage(this.session, new TextMessage("bar"));
|
||||
@@ -148,8 +145,8 @@ public class ClientSockJsSessionTests {
|
||||
public void handleFrameClose() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.handleFrame(SockJsFrame.closeFrame(1007, "").getContent());
|
||||
assertThat(this.session.isOpen(), equalTo(false));
|
||||
assertThat(this.session.disconnectStatus, equalTo(new CloseStatus(1007, "")));
|
||||
assertThat(this.session.isOpen()).isEqualTo(false);
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(1007, ""));
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
}
|
||||
@@ -166,7 +163,7 @@ public class ClientSockJsSessionTests {
|
||||
public void afterTransportClosed() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.afterTransportClosed(CloseStatus.SERVER_ERROR);
|
||||
assertThat(this.session.isOpen(), equalTo(false));
|
||||
assertThat(this.session.isOpen()).isEqualTo(false);
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
verify(this.handler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR);
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
@@ -176,8 +173,8 @@ public class ClientSockJsSessionTests {
|
||||
public void close() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.close();
|
||||
assertThat(this.session.isOpen(), equalTo(false));
|
||||
assertThat(this.session.disconnectStatus, equalTo(CloseStatus.NORMAL));
|
||||
assertThat(this.session.isOpen()).isEqualTo(false);
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(CloseStatus.NORMAL);
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
}
|
||||
@@ -186,7 +183,7 @@ public class ClientSockJsSessionTests {
|
||||
public void closeWithStatus() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.close(new CloseStatus(3000, "reason"));
|
||||
assertThat(this.session.disconnectStatus, equalTo(new CloseStatus(3000, "reason")));
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(3000, "reason"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,14 +205,14 @@ public class ClientSockJsSessionTests {
|
||||
@Test
|
||||
public void timeoutTask() {
|
||||
this.session.getTimeoutTask().run();
|
||||
assertThat(this.session.disconnectStatus, equalTo(new CloseStatus(2007, "Transport timed out")));
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(2007, "Transport timed out"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void send() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.sendMessage(new TextMessage("foo"));
|
||||
assertThat(this.session.sentMessage, equalTo(new TextMessage("[\"foo\"]")));
|
||||
assertThat(this.session.sentMessage).isEqualTo(new TextMessage("[\"foo\"]"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,9 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -62,7 +60,7 @@ public class SockJsUrlInfoTests {
|
||||
|
||||
private void testInfoUrl(String scheme, String expectedScheme) throws Exception {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
|
||||
assertThat(info.getInfoUrl(), is(equalTo(new URI(expectedScheme + "://example.com/info"))));
|
||||
assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +81,7 @@ public class SockJsUrlInfoTests {
|
||||
String sessionId = info.getSessionId();
|
||||
String transport = transportType.toString().toLowerCase();
|
||||
URI expected = new URI(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport);
|
||||
assertThat(info.getTransportUrl(transportType), equalTo(expected));
|
||||
assertThat(info.getTransportUrl(transportType)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user