Migrate tests to AssertJ

Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj
There is still a lot of work to do when complex and composite matchers are used.

* Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor
of `awaitility`
* Remove Hamcrest from dependencies and disable JUnit & Hamcrest
static imports to encourage to use only AssertJ
* Migrate JUnit assumptions in rules to AssertJ's assumptions
* Deprecate some custom matchers in favor of existing in Hamcrest
after upgrading the last to version `2.1`
* Replace `ExpectedException` rules with `assertThatThrownBy()`
* Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
Artem Bilan
2019-02-20 12:28:44 -05:00
parent b62c2a8fb3
commit 622d42c71a
916 changed files with 19714 additions and 21769 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2019 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.
@@ -16,7 +16,7 @@
package org.springframework.integration.stomp;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.concurrent.TimeUnit;
@@ -75,7 +75,7 @@ public class StompSessionManagerTests {
});
assertNotNull(stompSessionFuture.get(10, TimeUnit.SECONDS));
assertThat(stompSessionFuture.get(10, TimeUnit.SECONDS)).isNotNull();
sessionManager.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 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.
@@ -16,14 +16,8 @@
package org.springframework.integration.stomp.client;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.apache.activemq.broker.BrokerService;
import org.junit.AfterClass;
@@ -128,55 +122,55 @@ public class StompServerIntegrationTests {
}
while (eventMessage != null && !(eventMessage.getPayload() instanceof StompSessionConnectedEvent));
assertNotNull(eventMessage);
assertThat(eventMessage).isNotNull();
eventMessage = stompEvents1.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage.getPayload(), instanceOf(StompReceiptEvent.class));
assertThat(eventMessage).isNotNull();
assertThat(eventMessage.getPayload()).isInstanceOf(StompReceiptEvent.class);
StompReceiptEvent stompReceiptEvent = (StompReceiptEvent) eventMessage.getPayload();
assertEquals(StompCommand.SUBSCRIBE, stompReceiptEvent.getStompCommand());
assertEquals("/topic/myTopic", stompReceiptEvent.getDestination());
assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SUBSCRIBE);
assertThat(stompReceiptEvent.getDestination()).isEqualTo("/topic/myTopic");
eventMessage = stompEvents2.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage.getPayload(), instanceOf(StompSessionConnectedEvent.class));
assertThat(eventMessage).isNotNull();
assertThat(eventMessage.getPayload()).isInstanceOf(StompSessionConnectedEvent.class);
eventMessage = stompEvents2.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage.getPayload(), instanceOf(StompReceiptEvent.class));
assertThat(eventMessage).isNotNull();
assertThat(eventMessage.getPayload()).isInstanceOf(StompReceiptEvent.class);
stompReceiptEvent = (StompReceiptEvent) eventMessage.getPayload();
assertEquals(StompCommand.SUBSCRIBE, stompReceiptEvent.getStompCommand());
assertEquals("/topic/myTopic", stompReceiptEvent.getDestination());
assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SUBSCRIBE);
assertThat(stompReceiptEvent.getDestination()).isEqualTo("/topic/myTopic");
stompOutputChannel1.send(new GenericMessage<byte[]>("Hello, Client#2!".getBytes()));
Message<?> receive11 = stompInputChannel1.receive(10000);
Message<?> receive21 = stompInputChannel2.receive(10000);
assertNotNull(receive11);
assertNotNull(receive21);
assertThat(receive11).isNotNull();
assertThat(receive21).isNotNull();
assertArrayEquals("Hello, Client#2!".getBytes(), (byte[]) receive11.getPayload());
assertArrayEquals("Hello, Client#2!".getBytes(), (byte[]) receive21.getPayload());
assertThat((byte[]) receive11.getPayload()).isEqualTo("Hello, Client#2!".getBytes());
assertThat((byte[]) receive21.getPayload()).isEqualTo("Hello, Client#2!".getBytes());
stompOutputChannel2.send(new GenericMessage<byte[]>("Hello, Client#1!".getBytes()));
Message<?> receive12 = stompInputChannel1.receive(10000);
Message<?> receive22 = stompInputChannel2.receive(10000);
assertNotNull(receive12);
assertNotNull(receive22);
assertThat(receive12).isNotNull();
assertThat(receive22).isNotNull();
assertArrayEquals("Hello, Client#1!".getBytes(), (byte[]) receive12.getPayload());
assertArrayEquals("Hello, Client#1!".getBytes(), (byte[]) receive22.getPayload());
assertThat((byte[]) receive12.getPayload()).isEqualTo("Hello, Client#1!".getBytes());
assertThat((byte[]) receive22.getPayload()).isEqualTo("Hello, Client#1!".getBytes());
eventMessage = stompEvents2.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage.getPayload(), instanceOf(StompReceiptEvent.class));
assertThat(eventMessage).isNotNull();
assertThat(eventMessage.getPayload()).isInstanceOf(StompReceiptEvent.class);
stompReceiptEvent = (StompReceiptEvent) eventMessage.getPayload();
assertEquals(StompCommand.SEND, stompReceiptEvent.getStompCommand());
assertEquals("/topic/myTopic", stompReceiptEvent.getDestination());
assertArrayEquals("Hello, Client#1!".getBytes(), (byte[]) stompReceiptEvent.getMessage().getPayload());
assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SEND);
assertThat(stompReceiptEvent.getDestination()).isEqualTo("/topic/myTopic");
assertThat((byte[]) stompReceiptEvent.getMessage().getPayload()).isEqualTo("Hello, Client#1!".getBytes());
Lifecycle stompInboundChannelAdapter2 = context2.getBean("stompInboundChannelAdapter", Lifecycle.class);
stompInboundChannelAdapter2.stop();
@@ -184,31 +178,31 @@ public class StompServerIntegrationTests {
stompOutputChannel1.send(new GenericMessage<byte[]>("How do you do?".getBytes()));
Message<?> receive13 = stompInputChannel1.receive(10000);
assertNotNull(receive13);
assertThat(receive13).isNotNull();
Message<?> receive23 = stompInputChannel2.receive(100);
assertNull(receive23);
assertThat(receive23).isNull();
stompInboundChannelAdapter2.start();
eventMessage = stompEvents2.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage.getPayload(), instanceOf(StompReceiptEvent.class));
assertThat(eventMessage).isNotNull();
assertThat(eventMessage.getPayload()).isInstanceOf(StompReceiptEvent.class);
stompReceiptEvent = (StompReceiptEvent) eventMessage.getPayload();
assertEquals(StompCommand.SUBSCRIBE, stompReceiptEvent.getStompCommand());
assertEquals("/topic/myTopic", stompReceiptEvent.getDestination());
assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SUBSCRIBE);
assertThat(stompReceiptEvent.getDestination()).isEqualTo("/topic/myTopic");
stompOutputChannel1.send(new GenericMessage<byte[]>("???".getBytes()));
Message<?> receive24 = stompInputChannel2.receive(10000);
assertNotNull(receive24);
assertArrayEquals("???".getBytes(), (byte[]) receive24.getPayload());
assertThat(receive24).isNotNull();
assertThat((byte[]) receive24.getPayload()).isEqualTo("???".getBytes());
activeMQBroker.stop();
do {
eventMessage = stompEvents1.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage).isNotNull();
}
while (!(eventMessage.getPayload() instanceof StompConnectionFailedEvent));
@@ -217,28 +211,28 @@ public class StompServerIntegrationTests {
fail("MessageDeliveryException is expected");
}
catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getMessage(), containsString("could not deliver message"));
assertThat(e).isInstanceOf(MessageDeliveryException.class);
assertThat(e.getMessage()).contains("could not deliver message");
}
activeMQBroker.start(false);
do {
eventMessage = stompEvents1.receive(20000);
assertNotNull(eventMessage);
assertThat(eventMessage).isNotNull();
}
while (!(eventMessage.getPayload() instanceof StompReceiptEvent));
do {
eventMessage = stompEvents2.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage).isNotNull();
}
while (!(eventMessage.getPayload() instanceof StompReceiptEvent));
stompOutputChannel1.send(new GenericMessage<byte[]>("foo".getBytes()));
Message<?> receive25 = stompInputChannel2.receive(10000);
assertNotNull(receive25);
assertArrayEquals("foo".getBytes(), (byte[]) receive25.getPayload());
assertThat(receive25).isNotNull();
assertThat((byte[]) receive25.getPayload()).isEqualTo("foo".getBytes());
context1.close();
context2.close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2019 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.
@@ -16,14 +16,7 @@
package org.springframework.integration.stomp.config;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.List;
@@ -106,64 +99,69 @@ public class StompAdaptersParserTests {
@Test
public void testParsers() {
assertSame(this.defaultInboundAdapterChannel,
TestUtils.getPropertyValue(this.defaultInboundAdapter, "outputChannel"));
assertSame(this.stompSessionManager,
TestUtils.getPropertyValue(this.defaultInboundAdapter, "stompSessionManager"));
assertNull(TestUtils.getPropertyValue(this.defaultInboundAdapter, "errorChannel"));
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "outputChannel"))
.isSameAs(this.defaultInboundAdapterChannel);
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "stompSessionManager"))
.isSameAs(this.stompSessionManager);
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "errorChannel")).isNull();
Object headerMapper = TestUtils.getPropertyValue(this.defaultInboundAdapter, "headerMapper");
assertNotNull(headerMapper);
assertNotSame(this.headerMapper, headerMapper);
assertEquals(String.class, TestUtils.getPropertyValue(this.defaultInboundAdapter, "payloadType", Class.class));
assertTrue(TestUtils.getPropertyValue(this.defaultInboundAdapter, "autoStartup", Boolean.class));
assertThat(headerMapper).isNotNull();
assertThat(headerMapper).isNotSameAs(this.headerMapper);
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "payloadType", Class.class))
.isEqualTo(String.class);
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "autoStartup", Boolean.class)).isTrue();
assertSame(this.inboundChannel,
TestUtils.getPropertyValue(this.customInboundAdapter, "outputChannel"));
assertSame(this.stompSessionManager,
TestUtils.getPropertyValue(this.customInboundAdapter, "stompSessionManager"));
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.customInboundAdapter, "errorChannel"));
assertEquals(Collections.singleton("foo"),
TestUtils.getPropertyValue(this.customInboundAdapter, "destinations"));
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "outputChannel"))
.isSameAs(this.inboundChannel);
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "stompSessionManager"))
.isSameAs(this.stompSessionManager);
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "errorChannel")).isSameAs(this.errorChannel);
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "destinations"))
.isEqualTo(Collections.singleton("foo"));
headerMapper = TestUtils.getPropertyValue(this.customInboundAdapter, "headerMapper");
assertNotNull(headerMapper);
assertNotSame(this.headerMapper, headerMapper);
assertArrayEquals(new String[] {"bar", "foo"},
TestUtils.getPropertyValue(headerMapper, "inboundHeaderNames", String[].class));
assertEquals(Integer.class, TestUtils.getPropertyValue(this.customInboundAdapter, "payloadType", Class.class));
assertFalse(TestUtils.getPropertyValue(this.customInboundAdapter, "autoStartup", Boolean.class));
assertEquals(200, TestUtils.getPropertyValue(this.customInboundAdapter, "phase"));
assertEquals(2000L, TestUtils.getPropertyValue(this.customInboundAdapter, "messagingTemplate.sendTimeout"));
assertThat(headerMapper).isNotNull();
assertThat(headerMapper).isNotSameAs(this.headerMapper);
assertThat(TestUtils.getPropertyValue(headerMapper, "inboundHeaderNames", String[].class))
.isEqualTo(new String[] { "bar", "foo" });
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "payloadType", Class.class))
.isEqualTo(Integer.class);
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "autoStartup", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "phase")).isEqualTo(200);
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "messagingTemplate.sendTimeout"))
.isEqualTo(2000L);
assertSame(this.stompSessionManager,
TestUtils.getPropertyValue(this.defaultOutboundAdapterHandler, "stompSessionManager"));
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapterHandler, "stompSessionManager"))
.isSameAs(this.stompSessionManager);
headerMapper = TestUtils.getPropertyValue(this.defaultOutboundAdapterHandler, "headerMapper");
assertNotNull(headerMapper);
assertNotSame(this.headerMapper, headerMapper);
assertNull(TestUtils.getPropertyValue(this.defaultOutboundAdapterHandler, "destinationExpression"));
assertSame(this.defaultOutboundAdapterHandler,
TestUtils.getPropertyValue(this.defaultOutboundAdapter, "handler"));
assertSame(this.defaultOutboundAdapterChannel,
TestUtils.getPropertyValue(this.defaultOutboundAdapter, "inputChannel"));
assertTrue(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "autoStartup", Boolean.class));
assertThat(headerMapper).isNotNull();
assertThat(headerMapper).isNotSameAs(this.headerMapper);
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapterHandler, "destinationExpression")).isNull();
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "handler"))
.isSameAs(this.defaultOutboundAdapterHandler);
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "inputChannel"))
.isSameAs(this.defaultOutboundAdapterChannel);
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "autoStartup", Boolean.class)).isTrue();
assertSame(this.stompSessionManager,
TestUtils.getPropertyValue(this.customOutboundAdapterHandler, "stompSessionManager"));
assertSame(this.headerMapper, TestUtils.getPropertyValue(this.customOutboundAdapterHandler, "headerMapper"));
assertEquals("baz",
TestUtils.getPropertyValue(this.customOutboundAdapterHandler, "destinationExpression.literalValue"));
assertSame(this.customOutboundAdapterHandler,
TestUtils.getPropertyValue(this.customOutboundAdapter, "handler"));
assertSame(this.outboundChannel, TestUtils.getPropertyValue(this.customOutboundAdapter, "inputChannel"));
assertFalse(TestUtils.getPropertyValue(this.customOutboundAdapter, "autoStartup", Boolean.class));
assertEquals(100, TestUtils.getPropertyValue(this.customOutboundAdapter, "phase"));
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapterHandler, "stompSessionManager"))
.isSameAs(this.stompSessionManager);
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapterHandler, "headerMapper"))
.isSameAs(this.headerMapper);
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapterHandler, "destinationExpression.literalValue"))
.isEqualTo("baz");
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapter, "handler"))
.isSameAs(this.customOutboundAdapterHandler);
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapter, "inputChannel"))
.isSameAs(this.outboundChannel);
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapter, "autoStartup", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapter, "phase")).isEqualTo(100);
@SuppressWarnings("unchecked")
MultiValueMap<String, SmartLifecycle> lifecycles = (MultiValueMap<String, SmartLifecycle>)
TestUtils.getPropertyValue(this.roleController, "lifecycles", MultiValueMap.class);
assertTrue(lifecycles.containsKey("bar"));
assertThat(lifecycles.containsKey("bar")).isTrue();
List<SmartLifecycle> bars = lifecycles.get("bar");
bars.contains(this.customInboundAdapter);
assertTrue(lifecycles.containsKey("foo"));
assertThat(lifecycles.containsKey("foo")).isTrue();
bars.contains(this.customOutboundAdapter);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 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.
@@ -16,13 +16,7 @@
package org.springframework.integration.stomp.inbound;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.Map;
@@ -126,15 +120,15 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
@Test
public void testWebSocketStompClient() throws Exception {
Message<?> eventMessage = this.stompEvents.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage.getPayload(), instanceOf(StompSessionConnectedEvent.class));
assertThat(eventMessage).isNotNull();
assertThat(eventMessage.getPayload()).isInstanceOf(StompSessionConnectedEvent.class);
Message<?> receive = this.stompEvents.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(StompReceiptEvent.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(StompReceiptEvent.class);
StompReceiptEvent stompReceiptEvent = (StompReceiptEvent) receive.getPayload();
assertEquals(StompCommand.SUBSCRIBE, stompReceiptEvent.getStompCommand());
assertEquals("/topic/myTopic", stompReceiptEvent.getDestination());
assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SUBSCRIBE);
assertThat(stompReceiptEvent.getDestination()).isEqualTo("/topic/myTopic");
waitForSubscribe("/topic/myTopic");
@@ -150,13 +144,13 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
MessageBuilder.createMessage("{\"foo\": \"bar\"}".getBytes(), stompHeaderAccessor.getMessageHeaders()));
receive = this.stompInputChannel.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(Map.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(Map.class);
@SuppressWarnings("unchecked")
Map<String, String> payload = (Map<String, String>) receive.getPayload();
String foo = payload.get("foo");
assertNotNull(foo);
assertEquals("bar", foo);
assertThat(foo).isNotNull();
assertThat(foo).isEqualTo("bar");
this.stompInboundChannelAdapter.removeDestination("/topic/myTopic");
@@ -164,36 +158,35 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
messagingTemplate.convertAndSend("/topic/myTopic", "foo");
receive = this.errorChannel.receive(100);
assertNull(receive);
assertThat(receive).isNull();
this.stompInboundChannelAdapter.addDestination("/topic/myTopic");
receive = this.stompEvents.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
waitForSubscribe("/topic/myTopic");
messagingTemplate.convertAndSend("/topic/myTopic", "foo");
receive = this.errorChannel.receive(10000);
assertNotNull(receive);
assertThat(receive, instanceOf(ErrorMessage.class));
assertThat(receive).isNotNull();
assertThat(receive).isInstanceOf(ErrorMessage.class);
ErrorMessage errorMessage = (ErrorMessage) receive;
Throwable throwable = errorMessage.getPayload();
assertThat(throwable, instanceOf(MessageHandlingException.class));
assertThat(throwable.getCause(), instanceOf(MessageConversionException.class));
assertThat(throwable.getMessage(),
containsString("No suitable converter for payload type [interface java.util.Map]"));
assertThat(throwable).isInstanceOf(MessageHandlingException.class);
assertThat(throwable.getCause()).isInstanceOf(MessageConversionException.class);
assertThat(throwable.getMessage()).contains("No suitable converter for payload type [interface java.util.Map]");
this.serverContext.close();
eventMessage = this.stompEvents.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage.getPayload(), instanceOf(StompConnectionFailedEvent.class));
assertThat(eventMessage).isNotNull();
assertThat(eventMessage.getPayload()).isInstanceOf(StompConnectionFailedEvent.class);
this.serverContext.refresh();
do {
eventMessage = this.stompEvents.receive(10000);
assertNotNull(eventMessage);
assertThat(eventMessage).isNotNull();
}
while (!(eventMessage.getPayload() instanceof StompSessionConnectedEvent));
@@ -202,8 +195,8 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
messagingTemplate = this.serverContext.getBean("brokerMessagingTemplate", SimpMessagingTemplate.class);
messagingTemplate.convertAndSend("/topic/myTopic", "foo");
receive = this.errorChannel.receive(10000);
assertNotNull(receive);
assertEquals(0, ((QueueChannel) this.errorChannel).getQueueSize());
assertThat(receive).isNotNull();
assertThat(((QueueChannel) this.errorChannel).getQueueSize()).isEqualTo(0);
}
private void waitForSubscribe(String destination) throws InterruptedException {
@@ -217,7 +210,8 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
Thread.sleep(100);
}
assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
assertThat(n < 100).as("The subscription for the '" + destination + "' destination hasn't been registered")
.isTrue();
}
private void waitForUnsubscribe(String destination) throws InterruptedException {
@@ -231,7 +225,8 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
Thread.sleep(100);
}
assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
assertThat(n < 100).as("The subscription for the '" + destination + "' destination hasn't been registered")
.isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2019 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.
@@ -16,12 +16,7 @@
package org.springframework.integration.stomp.outbound;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -114,21 +109,21 @@ public class StompMessageHandlerWebSocketIntegrationTests {
this.webSocketOutputChannel.send(message);
SimpleController controller = this.serverContext.getBean(SimpleController.class);
assertTrue(controller.latch.await(10, TimeUnit.SECONDS));
assertThat(controller.latch.await(10, TimeUnit.SECONDS)).isTrue();
Message<?> receive = this.stompEvents.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(StompSessionConnectedEvent.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(StompSessionConnectedEvent.class);
// Simple Broker Relay doesn't support RECEIPT Frame, so we check here the 'lost' StompReceiptEvent
receive = this.stompEvents.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(StompReceiptEvent.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(StompReceiptEvent.class);
StompReceiptEvent stompReceiptEvent = (StompReceiptEvent) receive.getPayload();
assertEquals(StompCommand.SEND, stompReceiptEvent.getStompCommand());
assertEquals("/app/simple", stompReceiptEvent.getDestination());
assertTrue(stompReceiptEvent.isLost());
assertNotNull(stompReceiptEvent.getMessage());
assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SEND);
assertThat(stompReceiptEvent.getDestination()).isEqualTo("/app/simple");
assertThat(stompReceiptEvent.isLost()).isTrue();
assertThat(stompReceiptEvent.getMessage()).isNotNull();
headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setDestination("/foo");
@@ -136,22 +131,22 @@ public class StompMessageHandlerWebSocketIntegrationTests {
this.webSocketOutputChannel.send(message);
receive = this.stompEvents.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(StompExceptionEvent.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(StompExceptionEvent.class);
StompExceptionEvent stompExceptionEvent = (StompExceptionEvent) receive.getPayload();
Throwable cause = stompExceptionEvent.getCause();
assertThat(cause, instanceOf(MessageDeliveryException.class));
assertThat(cause).isInstanceOf(MessageDeliveryException.class);
MessageDeliveryException messageDeliveryException = (MessageDeliveryException) cause;
Message<?> failedMessage = messageDeliveryException.getFailedMessage();
assertThat((String) failedMessage.getPayload(), containsString("preSend intentional Exception"));
assertThat((String) failedMessage.getPayload()).contains("preSend intentional Exception");
receive = this.stompEvents.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(StompReceiptEvent.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(StompReceiptEvent.class);
stompReceiptEvent = (StompReceiptEvent) receive.getPayload();
assertEquals(StompCommand.SEND, stompReceiptEvent.getStompCommand());
assertEquals("/foo", stompReceiptEvent.getDestination());
assertTrue(stompReceiptEvent.isLost());
assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SEND);
assertThat(stompReceiptEvent.getDestination()).isEqualTo("/foo");
assertThat(stompReceiptEvent.isLost()).isTrue();
}
// STOMP Client