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:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.feed.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -74,10 +70,10 @@ public class FeedInboundChannelAdapterParserTests {
|
||||
"FeedInboundChannelAdapterParserTests-file-context.xml", this.getClass());
|
||||
SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
|
||||
FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
|
||||
assertSame(context.getBean(MetadataStore.class), TestUtils.getPropertyValue(source, "metadataStore"));
|
||||
assertThat(TestUtils.getPropertyValue(source, "metadataStore")).isSameAs(context.getBean(MetadataStore.class));
|
||||
SyndFeedInput syndFeedInput = TestUtils.getPropertyValue(source, "syndFeedInput", SyndFeedInput.class);
|
||||
assertSame(context.getBean(SyndFeedInput.class), syndFeedInput);
|
||||
assertFalse(syndFeedInput.isPreserveWireFeed());
|
||||
assertThat(syndFeedInput).isSameAs(context.getBean(SyndFeedInput.class));
|
||||
assertThat(syndFeedInput.isPreserveWireFeed()).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -88,7 +84,7 @@ public class FeedInboundChannelAdapterParserTests {
|
||||
"FeedInboundChannelAdapterParserTests-http-context.xml", this.getClass());
|
||||
SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
|
||||
FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
|
||||
assertNotNull(TestUtils.getPropertyValue(source, "metadataStore"));
|
||||
assertThat(TestUtils.getPropertyValue(source, "metadataStore")).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -111,7 +107,8 @@ public class FeedInboundChannelAdapterParserTests {
|
||||
verify(latch, times(0)).countDown();
|
||||
|
||||
SourcePollingChannelAdapter adapter = context.getBean("feedAdapterUsage", SourcePollingChannelAdapter.class);
|
||||
assertTrue(TestUtils.getPropertyValue(adapter, "source.syndFeedInput.preserveWireFeed", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(adapter, "source.syndFeedInput.preserveWireFeed", Boolean.class))
|
||||
.isTrue();
|
||||
|
||||
context.close();
|
||||
}
|
||||
@@ -135,8 +132,9 @@ public class FeedInboundChannelAdapterParserTests {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"FeedInboundChannelAdapterParserTests-autoChannel-context.xml", this.getClass());
|
||||
MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class);
|
||||
SourcePollingChannelAdapter adapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class);
|
||||
assertSame(autoChannel, TestUtils.getPropertyValue(adapter, "outputChannel"));
|
||||
SourcePollingChannelAdapter adapter = context.getBean("autoChannel.adapter",
|
||||
SourcePollingChannelAdapter.class);
|
||||
assertThat(TestUtils.getPropertyValue(adapter, "outputChannel")).isSameAs(autoChannel);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -144,20 +142,24 @@ public class FeedInboundChannelAdapterParserTests {
|
||||
|
||||
public void receiveFeedEntry(Message<?> message) {
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
assertEquals(3, history.size());
|
||||
assertThat(history).hasSize(3);
|
||||
Properties historyItem = history.get(0);
|
||||
assertEquals("feedAdapterUsage", historyItem.get("name"));
|
||||
assertEquals("feed:inbound-channel-adapter", historyItem.get("type"));
|
||||
assertThat(historyItem)
|
||||
.containsEntry("name", "feedAdapterUsage")
|
||||
.containsEntry("type", "feed:inbound-channel-adapter");
|
||||
|
||||
historyItem = history.get(1);
|
||||
assertEquals("feedChannelUsage", historyItem.get("name"));
|
||||
assertEquals("channel", historyItem.get("type"));
|
||||
assertThat(historyItem)
|
||||
.containsEntry("name", "feedChannelUsage")
|
||||
.containsEntry("type", "channel");
|
||||
|
||||
historyItem = history.get(2);
|
||||
assertEquals("sampleActivator", historyItem.get("name"));
|
||||
assertEquals("service-activator", historyItem.get("type"));
|
||||
assertThat(historyItem)
|
||||
.containsEntry("name", "sampleActivator")
|
||||
.containsEntry("type", "service-activator");
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -17,10 +17,6 @@
|
||||
package org.springframework.integration.feed.dsl;
|
||||
|
||||
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.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.util.Properties;
|
||||
@@ -77,9 +73,9 @@ public class FeedDslTests {
|
||||
long time1 = message1.getPayload().getPublishedDate().getTime();
|
||||
long time2 = message2.getPayload().getPublishedDate().getTime();
|
||||
long time3 = message3.getPayload().getPublishedDate().getTime();
|
||||
assertTrue(time1 < time2);
|
||||
assertTrue(time2 < time3);
|
||||
assertNull(this.entries.receive(10));
|
||||
assertThat(time1 < time2).isTrue();
|
||||
assertThat(time2 < time3).isTrue();
|
||||
assertThat(this.entries.receive(10)).isNull();
|
||||
|
||||
this.metadataStore.flush();
|
||||
|
||||
@@ -87,9 +83,9 @@ public class FeedDslTests {
|
||||
new FileReader(tempFolder.getRoot().getAbsolutePath() + "/metadata-store.properties");
|
||||
Properties metadataStoreProperties = new Properties();
|
||||
metadataStoreProperties.load(metadataStoreFile);
|
||||
assertFalse(metadataStoreProperties.isEmpty());
|
||||
assertEquals(1, metadataStoreProperties.size());
|
||||
assertTrue(metadataStoreProperties.containsKey("feedTest"));
|
||||
assertThat(metadataStoreProperties.isEmpty()).isFalse();
|
||||
assertThat(metadataStoreProperties.size()).isEqualTo(1);
|
||||
assertThat(metadataStoreProperties.containsKey("feedTest")).isTrue();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.feed.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.File;
|
||||
@@ -68,7 +66,7 @@ public class FeedEntryMessageSourceTests {
|
||||
feedEntrySource.setBeanName("feedReader");
|
||||
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
|
||||
feedEntrySource.afterPropertiesSet();
|
||||
assertNull(feedEntrySource.receive());
|
||||
assertThat(feedEntrySource.receive()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,9 +82,9 @@ public class FeedEntryMessageSourceTests {
|
||||
long time1 = message1.getPayload().getPublishedDate().getTime();
|
||||
long time2 = message2.getPayload().getPublishedDate().getTime();
|
||||
long time3 = message3.getPayload().getPublishedDate().getTime();
|
||||
assertTrue(time1 < time2);
|
||||
assertTrue(time2 < time3);
|
||||
assertNull(source.receive());
|
||||
assertThat(time1 < time2).isTrue();
|
||||
assertThat(time2 < time3).isTrue();
|
||||
assertThat(source.receive()).isNull();
|
||||
}
|
||||
|
||||
// verifies that when entry has been updated since publish, that is taken into
|
||||
@@ -103,11 +101,11 @@ public class FeedEntryMessageSourceTests {
|
||||
feedEntrySource.afterPropertiesSet();
|
||||
|
||||
SyndEntry entry1 = feedEntrySource.receive().getPayload();
|
||||
assertNull(feedEntrySource.receive()); // only 1 entries in the test feed
|
||||
assertThat(feedEntrySource.receive()).isNull(); // only 1 entries in the test feed
|
||||
|
||||
assertEquals("Atom draft-07 snapshot", entry1.getTitle().trim());
|
||||
assertEquals(1071318569000L, entry1.getPublishedDate().getTime());
|
||||
assertEquals(1122812969000L, entry1.getUpdatedDate().getTime());
|
||||
assertThat(entry1.getTitle().trim()).isEqualTo("Atom draft-07 snapshot");
|
||||
assertThat(entry1.getPublishedDate().getTime()).isEqualTo(1071318569000L);
|
||||
assertThat(entry1.getUpdatedDate().getTime()).isEqualTo(1122812969000L);
|
||||
|
||||
metadataStore.destroy();
|
||||
metadataStore.afterPropertiesSet();
|
||||
@@ -120,7 +118,7 @@ public class FeedEntryMessageSourceTests {
|
||||
feedEntrySource.setMetadataStore(metadataStore);
|
||||
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
|
||||
feedEntrySource.afterPropertiesSet();
|
||||
assertNull(feedEntrySource.receive());
|
||||
assertThat(feedEntrySource.receive()).isNull();
|
||||
}
|
||||
|
||||
// will test that last feed entry is remembered between the sessions
|
||||
@@ -138,16 +136,16 @@ public class FeedEntryMessageSourceTests {
|
||||
SyndEntry entry1 = feedEntrySource.receive().getPayload();
|
||||
SyndEntry entry2 = feedEntrySource.receive().getPayload();
|
||||
SyndEntry entry3 = feedEntrySource.receive().getPayload();
|
||||
assertNull(feedEntrySource.receive()); // only 3 entries in the test feed
|
||||
assertThat(feedEntrySource.receive()).isNull(); // only 3 entries in the test feed
|
||||
|
||||
assertEquals("Spring Integration download", entry1.getTitle().trim());
|
||||
assertEquals(1266088337000L, entry1.getPublishedDate().getTime());
|
||||
assertThat(entry1.getTitle().trim()).isEqualTo("Spring Integration download");
|
||||
assertThat(entry1.getPublishedDate().getTime()).isEqualTo(1266088337000L);
|
||||
|
||||
assertEquals("Check out Spring Integration forums", entry2.getTitle().trim());
|
||||
assertEquals(1268469501000L, entry2.getPublishedDate().getTime());
|
||||
assertThat(entry2.getTitle().trim()).isEqualTo("Check out Spring Integration forums");
|
||||
assertThat(entry2.getPublishedDate().getTime()).isEqualTo(1268469501000L);
|
||||
|
||||
assertEquals("Spring Integration adapters", entry3.getTitle().trim());
|
||||
assertEquals(1272044098000L, entry3.getPublishedDate().getTime());
|
||||
assertThat(entry3.getTitle().trim()).isEqualTo("Spring Integration adapters");
|
||||
assertThat(entry3.getPublishedDate().getTime()).isEqualTo(1272044098000L);
|
||||
|
||||
metadataStore.destroy();
|
||||
metadataStore.afterPropertiesSet();
|
||||
@@ -160,9 +158,9 @@ public class FeedEntryMessageSourceTests {
|
||||
feedEntrySource.setMetadataStore(metadataStore);
|
||||
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
|
||||
feedEntrySource.afterPropertiesSet();
|
||||
assertNull(feedEntrySource.receive());
|
||||
assertNull(feedEntrySource.receive());
|
||||
assertNull(feedEntrySource.receive());
|
||||
assertThat(feedEntrySource.receive()).isNull();
|
||||
assertThat(feedEntrySource.receive()).isNull();
|
||||
assertThat(feedEntrySource.receive()).isNull();
|
||||
}
|
||||
|
||||
// will test that last feed entry is NOT remembered between the sessions, since
|
||||
@@ -177,16 +175,16 @@ public class FeedEntryMessageSourceTests {
|
||||
SyndEntry entry1 = feedEntrySource.receive().getPayload();
|
||||
SyndEntry entry2 = feedEntrySource.receive().getPayload();
|
||||
SyndEntry entry3 = feedEntrySource.receive().getPayload();
|
||||
assertNull(feedEntrySource.receive()); // only 3 entries in the test feed
|
||||
assertThat(feedEntrySource.receive()).isNull(); // only 3 entries in the test feed
|
||||
|
||||
assertEquals("Spring Integration download", entry1.getTitle().trim());
|
||||
assertEquals(1266088337000L, entry1.getPublishedDate().getTime());
|
||||
assertThat(entry1.getTitle().trim()).isEqualTo("Spring Integration download");
|
||||
assertThat(entry1.getPublishedDate().getTime()).isEqualTo(1266088337000L);
|
||||
|
||||
assertEquals("Check out Spring Integration forums", entry2.getTitle().trim());
|
||||
assertEquals(1268469501000L, entry2.getPublishedDate().getTime());
|
||||
assertThat(entry2.getTitle().trim()).isEqualTo("Check out Spring Integration forums");
|
||||
assertThat(entry2.getPublishedDate().getTime()).isEqualTo(1268469501000L);
|
||||
|
||||
assertEquals("Spring Integration adapters", entry3.getTitle().trim());
|
||||
assertEquals(1272044098000L, entry3.getPublishedDate().getTime());
|
||||
assertThat(entry3.getTitle().trim()).isEqualTo("Spring Integration adapters");
|
||||
assertThat(entry3.getPublishedDate().getTime()).isEqualTo(1272044098000L);
|
||||
|
||||
// UNLIKE the previous test
|
||||
// now test that what's been read is read AGAIN
|
||||
@@ -197,16 +195,16 @@ public class FeedEntryMessageSourceTests {
|
||||
entry1 = feedEntrySource.receive().getPayload();
|
||||
entry2 = feedEntrySource.receive().getPayload();
|
||||
entry3 = feedEntrySource.receive().getPayload();
|
||||
assertNull(feedEntrySource.receive()); // only 3 entries in the test feed
|
||||
assertThat(feedEntrySource.receive()).isNull(); // only 3 entries in the test feed
|
||||
|
||||
assertEquals("Spring Integration download", entry1.getTitle().trim());
|
||||
assertEquals(1266088337000L, entry1.getPublishedDate().getTime());
|
||||
assertThat(entry1.getTitle().trim()).isEqualTo("Spring Integration download");
|
||||
assertThat(entry1.getPublishedDate().getTime()).isEqualTo(1266088337000L);
|
||||
|
||||
assertEquals("Check out Spring Integration forums", entry2.getTitle().trim());
|
||||
assertEquals(1268469501000L, entry2.getPublishedDate().getTime());
|
||||
assertThat(entry2.getTitle().trim()).isEqualTo("Check out Spring Integration forums");
|
||||
assertThat(entry2.getPublishedDate().getTime()).isEqualTo(1268469501000L);
|
||||
|
||||
assertEquals("Spring Integration adapters", entry3.getTitle().trim());
|
||||
assertEquals(1272044098000L, entry3.getPublishedDate().getTime());
|
||||
assertThat(entry3.getTitle().trim()).isEqualTo("Spring Integration adapters");
|
||||
assertThat(entry3.getPublishedDate().getTime()).isEqualTo(1272044098000L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user