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 2002-2015 the original author or authors.
* Copyright 2002-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,17 +16,12 @@
package org.springframework.integration.event.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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.Date;
import java.util.Properties;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -75,73 +70,74 @@ public class EventInboundChannelAdapterParserTests {
@Test
public void validateEventParser() {
Object adapter = context.getBean("eventAdapterSimple");
Assert.assertNotNull(adapter);
Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
Assert.assertEquals(context.getBean("input"), adapterAccessor.getPropertyValue("outputChannel"));
Assert.assertSame(errorChannel, adapterAccessor.getPropertyValue("errorChannel"));
assertThat(adapterAccessor.getPropertyValue("outputChannel")).isEqualTo(context.getBean("input"));
assertThat(adapterAccessor.getPropertyValue("errorChannel")).isSameAs(errorChannel);
}
@Test
@SuppressWarnings("unchecked")
public void validateEventParserWithEventTypes() {
Object adapter = context.getBean("eventAdapterFiltered");
Assert.assertNotNull(adapter);
Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
Assert.assertEquals(context.getBean("inputFiltered"), adapterAccessor.getPropertyValue("outputChannel"));
assertThat(adapterAccessor.getPropertyValue("outputChannel")).isEqualTo(context.getBean("inputFiltered"));
Set<ResolvableType> eventTypes = (Set<ResolvableType>) adapterAccessor.getPropertyValue("eventTypes");
assertNotNull(eventTypes);
assertTrue(eventTypes.size() == 3);
assertTrue(eventTypes.contains(ResolvableType.forClass(SampleEvent.class)));
assertTrue(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class)));
assertTrue(eventTypes.contains(ResolvableType.forClass(Date.class)));
assertNull(adapterAccessor.getPropertyValue("errorChannel"));
assertThat(eventTypes).isNotNull();
assertThat(eventTypes.size() == 3).isTrue();
assertThat(eventTypes.contains(ResolvableType.forClass(SampleEvent.class))).isTrue();
assertThat(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class))).isTrue();
assertThat(eventTypes.contains(ResolvableType.forClass(Date.class))).isTrue();
assertThat(adapterAccessor.getPropertyValue("errorChannel")).isNull();
}
@Test
@SuppressWarnings("unchecked")
public void validateEventParserWithEventTypesAndPlaceholder() {
Object adapter = context.getBean("eventAdapterFilteredPlaceHolder");
Assert.assertNotNull(adapter);
Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
Assert.assertEquals(context.getBean("inputFilteredPlaceHolder"), adapterAccessor.getPropertyValue("outputChannel"));
assertThat(adapterAccessor.getPropertyValue("outputChannel"))
.isEqualTo(context.getBean("inputFilteredPlaceHolder"));
Set<ResolvableType> eventTypes = (Set<ResolvableType>) adapterAccessor.getPropertyValue("eventTypes");
assertNotNull(eventTypes);
assertTrue(eventTypes.size() == 2);
assertTrue(eventTypes.contains(ResolvableType.forClass(SampleEvent.class)));
assertTrue(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class)));
assertThat(eventTypes).isNotNull();
assertThat(eventTypes.size() == 2).isTrue();
assertThat(eventTypes.contains(ResolvableType.forClass(SampleEvent.class))).isTrue();
assertThat(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class))).isTrue();
}
@Test
public void validateUsageWithHistory() {
PollableChannel channel = context.getBean("input", PollableChannel.class);
assertEquals(ContextRefreshedEvent.class, channel.receive(0).getPayload().getClass());
assertThat(channel.receive(0).getPayload().getClass()).isEqualTo(ContextRefreshedEvent.class);
context.publishEvent(new SampleEvent("hello"));
Message<?> message = channel.receive(0);
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
assertThat(history).isNotNull();
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "eventAdapterSimple", 0);
assertNotNull(componentHistoryRecord);
assertEquals("event:inbound-channel-adapter", componentHistoryRecord.get("type"));
assertNotNull(message);
assertEquals(SampleEvent.class, message.getPayload().getClass());
assertThat(componentHistoryRecord).isNotNull();
assertThat(componentHistoryRecord.get("type")).isEqualTo("event:inbound-channel-adapter");
assertThat(message).isNotNull();
assertThat(message.getPayload().getClass()).isEqualTo(SampleEvent.class);
}
@Test
public void validatePayloadExpression() {
Object adapter = context.getBean("eventAdapterSpel");
Assert.assertNotNull(adapter);
Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue();
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
Expression expression = (Expression) adapterAccessor.getPropertyValue("payloadExpression");
Assert.assertEquals("source + '-test'", expression.getExpressionString());
assertThat(expression.getExpressionString()).isEqualTo("source + '-test'");
}
@Test
public void testAutoCreateChannel() {
assertSame(autoChannel, TestUtils.getPropertyValue(eventListener, "outputChannel"));
assertThat(TestUtils.getPropertyValue(eventListener, "outputChannel")).isSameAs(autoChannel);
}
@SuppressWarnings("serial")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-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,10 +16,11 @@
package org.springframework.integration.event.config;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -62,12 +63,12 @@ public class EventOutboundChannelAdapterParserTests {
@Test
public void validateEventParser() {
EventDrivenConsumer adapter = this.context.getBean("eventAdapter", EventDrivenConsumer.class);
Assert.assertNotNull(adapter);
assertThat(adapter).isNotNull();
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
MessageHandler handler = (MessageHandler) adapterAccessor.getPropertyValue("handler");
Assert.assertTrue(handler instanceof ApplicationEventPublishingMessageHandler);
Assert.assertEquals(this.context.getBean("input"), adapterAccessor.getPropertyValue("inputChannel"));
Assert.assertTrue(TestUtils.getPropertyValue(handler, "publishPayload", Boolean.class));
assertThat(handler instanceof ApplicationEventPublishingMessageHandler).isTrue();
assertThat(adapterAccessor.getPropertyValue("inputChannel")).isEqualTo(this.context.getBean("input"));
assertThat(TestUtils.getPropertyValue(handler, "publishPayload", Boolean.class)).isTrue();
}
@Test
@@ -83,7 +84,7 @@ public class EventOutboundChannelAdapterParserTests {
this.context.addApplicationListener(listener);
DirectChannel channel = context.getBean("input", DirectChannel.class);
channel.send(new GenericMessage<String>("hello"));
Assert.assertTrue(this.receivedEvent);
assertThat(this.receivedEvent).isTrue();
}
@Test
@@ -101,8 +102,8 @@ public class EventOutboundChannelAdapterParserTests {
context.addApplicationListener(listener);
DirectChannel channel = context.getBean("inputAdvice", DirectChannel.class);
channel.send(new GenericMessage<String>("hello"));
Assert.assertTrue(this.receivedEvent);
Assert.assertEquals(1, adviceCalled);
assertThat(this.receivedEvent).isTrue();
assertThat(adviceCalled).isEqualTo(1);
}
@Test //INT-2275
@@ -120,7 +121,7 @@ public class EventOutboundChannelAdapterParserTests {
this.context.addApplicationListener(listener);
DirectChannel channel = context.getBean("inputChain", DirectChannel.class);
channel.send(new GenericMessage<String>("foo"));
Assert.assertTrue(this.receivedEvent);
assertThat(this.receivedEvent).isTrue();
}
@Test(timeout = 10000)
@@ -153,7 +154,7 @@ public class EventOutboundChannelAdapterParserTests {
QueueChannel channel = context.getBean("input", QueueChannel.class);
channel.send(new GenericMessage<String>("hello"));
barrier.await();
Assert.assertTrue(this.receivedEvent);
assertThat(this.receivedEvent).isTrue();
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 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,11 +16,7 @@
package org.springframework.integration.event.dsl;
import static org.hamcrest.Matchers.instanceOf;
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.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.atomic.AtomicReference;
@@ -91,32 +87,32 @@ public class IntegrationFlowEventsTests {
@Test
public void testEventsFlow() {
assertNull(this.eventHolder.get());
assertThat(this.eventHolder.get()).isNull();
this.flow3Input.send(new GenericMessage<>("2"));
assertNotNull(this.eventHolder.get());
assertEquals(4, this.eventHolder.get());
assertThat(this.eventHolder.get()).isNotNull();
assertThat(this.eventHolder.get()).isEqualTo(4);
}
@Test
public void testRawApplicationEventListeningMessageProducer() {
this.applicationContext.publishEvent(new TestApplicationEvent1());
Message<?> receive = this.resultsChannel.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(TestApplicationEvent1.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(TestApplicationEvent1.class);
this.applicationContext.publishEvent(new TestApplicationEvent2());
receive = this.resultsChannel.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(TestApplicationEvent2.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(TestApplicationEvent2.class);
}
@Test
public void testDelayRescheduling() {
Message<?> receive = this.delayedResults.receive(10000);
assertNotNull(receive);
assertEquals("foo", receive.getPayload());
assertEquals(1, messageGroupStore.getMessageGroupCount());
assertEquals(0, messageGroupStore.getMessageCountForAllMessageGroups());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("foo");
assertThat(messageGroupStore.getMessageGroupCount()).isEqualTo(1);
assertThat(messageGroupStore.getMessageCountForAllMessageGroups()).isEqualTo(0);
}

View File

@@ -16,21 +16,12 @@
package org.springframework.integration.event.inbound;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isOneOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -73,17 +64,17 @@ public class ApplicationEventListeningMessageProducerTests {
adapter.setOutputChannel(channel);
adapter.start();
Message<?> message1 = channel.receive(0);
assertNull(message1);
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class)));
assertThat(message1).isNull();
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class))).isTrue();
adapter.onApplicationEvent(new TestApplicationEvent1());
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class)));
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class))).isTrue();
adapter.onApplicationEvent(new TestApplicationEvent2());
Message<?> message2 = channel.receive(20);
assertNotNull(message2);
assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource());
assertThat(message2).isNotNull();
assertThat(((ApplicationEvent) message2.getPayload()).getSource()).isEqualTo("event1");
Message<?> message3 = channel.receive(20);
assertNotNull(message3);
assertEquals("event2", ((ApplicationEvent) message3.getPayload()).getSource());
assertThat(message3).isNotNull();
assertThat(((ApplicationEvent) message3.getPayload()).getSource()).isEqualTo("event2");
}
@Test
@@ -94,26 +85,26 @@ public class ApplicationEventListeningMessageProducerTests {
adapter.setEventTypes(TestApplicationEvent1.class);
adapter.start();
Message<?> message1 = channel.receive(0);
assertNull(message1);
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class)));
assertThat(message1).isNull();
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class))).isTrue();
adapter.onApplicationEvent(new TestApplicationEvent1());
assertFalse(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class)));
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class))).isFalse();
Message<?> message2 = channel.receive(20);
assertNotNull(message2);
assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource());
assertNull(channel.receive(0));
assertThat(message2).isNotNull();
assertThat(((ApplicationEvent) message2.getPayload()).getSource()).isEqualTo("event1");
assertThat(channel.receive(0)).isNull();
adapter.setEventTypes((Class<? extends ApplicationEvent>) null);
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class)));
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class)));
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class))).isTrue();
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class))).isTrue();
adapter.setEventTypes(null, TestApplicationEvent2.class, null);
assertFalse(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class)));
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class)));
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class))).isFalse();
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class))).isTrue();
adapter.setEventTypes(null, null);
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class)));
assertTrue(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class)));
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class))).isTrue();
assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class))).isTrue();
}
@Test
@@ -122,20 +113,20 @@ public class ApplicationEventListeningMessageProducerTests {
"applicationEventInboundChannelAdapterTests.xml", this.getClass());
PollableChannel channel = (PollableChannel) context.getBean("channel");
Message<?> contextRefreshedEventMessage = channel.receive(0);
assertNotNull(contextRefreshedEventMessage);
assertEquals(ContextRefreshedEvent.class, contextRefreshedEventMessage.getPayload().getClass());
assertThat(contextRefreshedEventMessage).isNotNull();
assertThat(contextRefreshedEventMessage.getPayload().getClass()).isEqualTo(ContextRefreshedEvent.class);
context.start();
Message<?> startedEventMessage = channel.receive(0);
assertNotNull(startedEventMessage);
assertEquals(ContextStartedEvent.class, startedEventMessage.getPayload().getClass());
assertThat(startedEventMessage).isNotNull();
assertThat(startedEventMessage.getPayload().getClass()).isEqualTo(ContextStartedEvent.class);
context.stop();
Message<?> contextStoppedEventMessage = channel.receive(0);
assertNotNull(contextStoppedEventMessage);
assertEquals(ContextStoppedEvent.class, contextStoppedEventMessage.getPayload().getClass());
assertThat(contextStoppedEventMessage).isNotNull();
assertThat(contextStoppedEventMessage.getPayload().getClass()).isEqualTo(ContextStoppedEvent.class);
context.close();
Message<?> closedEventMessage = channel.receive(0);
assertNotNull(closedEventMessage);
assertEquals(ContextClosedEvent.class, closedEventMessage.getPayload().getClass());
assertThat(closedEventMessage).isNotNull();
assertThat(closedEventMessage.getPayload().getClass()).isEqualTo(ContextClosedEvent.class);
}
@Test
@@ -158,18 +149,18 @@ public class ApplicationEventListeningMessageProducerTests {
Message<?> message1 = channel.receive(0);
// ContextRefreshedEvent
assertNotNull(message1);
assertTrue(message1.getPayload().toString()
.contains("org.springframework.integration.test.util.TestUtils$TestApplicationContext"));
assertThat(message1).isNotNull();
assertThat(message1.getPayload().toString()
.contains("org.springframework.integration.test.util.TestUtils$TestApplicationContext")).isTrue();
adapter.onApplicationEvent(new TestApplicationEvent1());
adapter.onApplicationEvent(new TestApplicationEvent2());
Message<?> message2 = channel.receive(20);
assertNotNull(message2);
assertEquals("received: event1", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("received: event1");
Message<?> message3 = channel.receive(20);
assertNotNull(message3);
assertEquals("received: event2", message3.getPayload());
assertThat(message3).isNotNull();
assertThat(message3.getPayload()).isEqualTo("received: event2");
ctx.close();
}
@@ -181,11 +172,11 @@ public class ApplicationEventListeningMessageProducerTests {
adapter.setOutputChannel(channel);
adapter.start();
Message<?> message1 = channel.receive(0);
assertNull(message1);
assertThat(message1).isNull();
adapter.onApplicationEvent(new MessagingEvent(new GenericMessage<>("test")));
Message<?> message2 = channel.receive(20);
assertNotNull(message2);
assertEquals("test", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("test");
}
@Test
@@ -195,11 +186,11 @@ public class ApplicationEventListeningMessageProducerTests {
adapter.setOutputChannel(channel);
adapter.start();
Message<?> message1 = channel.receive(0);
assertNull(message1);
assertThat(message1).isNull();
adapter.onApplicationEvent(new TestMessagingEvent(new GenericMessage<>("test")));
Message<?> message2 = channel.receive(20);
assertNotNull(message2);
assertEquals("test", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("test");
}
@Test(expected = MessageHandlingException.class)
@@ -219,8 +210,8 @@ public class ApplicationEventListeningMessageProducerTests {
adapter.start();
adapter.onApplicationEvent(new TestApplicationEvent1());
Message<?> message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
assertThat(message).isNotNull();
assertThat(((Exception) message.getPayload()).getCause().getMessage()).isEqualTo("Failed");
adapter.setErrorChannel(null);
adapter.onApplicationEvent(new TestApplicationEvent1());
}
@@ -254,27 +245,27 @@ public class ApplicationEventListeningMessageProducerTests {
* Previously, the retrieverCache grew unnecessarily; the adapter was added to the cache for each event type,
* event if not supported.
*/
assertEquals(2, retrieverCache.size());
assertThat(retrieverCache.size()).isEqualTo(2);
for (Map.Entry<?, ?> entry : retrieverCache.entrySet()) {
Class<? extends ApplicationEvent> event = TestUtils.getPropertyValue(entry.getKey(), "eventType.resolved",
Class.class);
assertThat(event, Matchers.is(Matchers.isOneOf(ContextRefreshedEvent.class, TestApplicationEvent1.class)));
assertThat(event).isIn(ContextRefreshedEvent.class, TestApplicationEvent1.class);
Set<?> listeners = TestUtils.getPropertyValue(entry.getValue(), "applicationListeners", Set.class);
assertEquals(1, listeners.size());
assertSame(ctx.getBean("testListener"), listeners.iterator().next());
assertThat(listeners.size()).isEqualTo(1);
assertThat(listeners.iterator().next()).isSameAs(ctx.getBean("testListener"));
}
TestApplicationEvent2 event2 = new TestApplicationEvent2();
ctx.publishEvent(event2);
assertEquals(3, retrieverCache.size());
assertThat(retrieverCache.size()).isEqualTo(3);
for (Map.Entry<?, ?> entry : retrieverCache.entrySet()) {
Class<?> event = TestUtils.getPropertyValue(entry.getKey(), "eventType.resolved", Class.class);
if (TestApplicationEvent2.class.isAssignableFrom(event)) {
Set<?> listeners = TestUtils.getPropertyValue(entry.getValue(), "applicationListeners", Set.class);
assertEquals(2, listeners.size());
assertThat(listeners.size()).isEqualTo(2);
for (Object listener : listeners) {
assertThat(listener,
is(isOneOf(ctx.getBean("testListenerMessageProducer"), ctx.getBean("testListener"))));
assertThat(listener)
.isIn(ctx.getBean("testListenerMessageProducer"), ctx.getBean("testListener"));
}
break;
}
@@ -284,12 +275,12 @@ public class ApplicationEventListeningMessageProducerTests {
});
assertEquals(4, listenerCounter.get());
assertThat(listenerCounter.get()).isEqualTo(4);
final Message<?> receive = channel.receive(10);
assertNotNull(receive);
assertSame(event2, receive.getPayload());
assertNull(channel.receive(1));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isSameAs(event2);
assertThat(channel.receive(1)).isNull();
ctx.close();
}
@@ -310,8 +301,8 @@ public class ApplicationEventListeningMessageProducerTests {
ctx.publishEvent("foo");
Message<?> receive = channel.receive(10000);
assertNotNull(receive);
assertEquals("foo", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("foo");
ctx.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-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,8 +16,7 @@
package org.springframework.integration.event.outbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -37,12 +36,12 @@ public class ApplicationEventPublishingMessageHandlerTests {
TestApplicationEventPublisher publisher = new TestApplicationEventPublisher();
ApplicationEventPublishingMessageHandler handler = new ApplicationEventPublishingMessageHandler();
handler.setApplicationEventPublisher(publisher);
assertNull(publisher.getLastEvent());
assertThat(publisher.getLastEvent()).isNull();
Message<?> message = new GenericMessage<String>("testing");
handler.handleMessage(message);
ApplicationEvent event = publisher.getLastEvent();
assertEquals(MessagingEvent.class, event.getClass());
assertEquals(message, ((MessagingEvent) event).getMessage());
assertThat(event.getClass()).isEqualTo(MessagingEvent.class);
assertThat(((MessagingEvent) event).getMessage()).isEqualTo(message);
}
@Test
@@ -50,12 +49,12 @@ public class ApplicationEventPublishingMessageHandlerTests {
TestApplicationEventPublisher publisher = new TestApplicationEventPublisher();
ApplicationEventPublishingMessageHandler handler = new ApplicationEventPublishingMessageHandler();
handler.setApplicationEventPublisher(publisher);
assertNull(publisher.getLastEvent());
assertThat(publisher.getLastEvent()).isNull();
Message<?> message = new GenericMessage<TestEvent>(new TestEvent("foo"));
handler.handleMessage(message);
ApplicationEvent event = publisher.getLastEvent();
assertEquals(TestEvent.class, event.getClass());
assertEquals("foo", ((TestEvent) event).getSource());
assertThat(event.getClass()).isEqualTo(TestEvent.class);
assertThat(((TestEvent) event).getSource()).isEqualTo("foo");
}