Fix deprecation warnings

* Use `MatcherAssert.assertThat()`
instead of deprecated `Assert.assertThat()`
* Use `IntegrationFlows.fromSupplier(Supplier)`
instead of removed `IntegrationFlows.from(Supplier)`
* Use `org.springframework.integration:spring-integration-test`
throughout the project for more testing utilities
This commit is contained in:
Artem Bilan
2020-06-29 11:00:32 -04:00
parent cb9f6eb0a5
commit 21e44479ee
87 changed files with 438 additions and 564 deletions

View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>testing-examples</artifactId>
<version>5.3.0.RELEASE</version>
<version>5.4.0</version>
<name>Testing Examples</name>
<description>Testing Examples</description>
<url>https://projects.spring.io/spring-integration</url>
@@ -155,17 +155,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>jackson-module-kotlin</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
@@ -202,14 +191,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>5.2.7.RELEASE</version>
<version>5.3.0-M1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>5.3.1.RELEASE</version>
<version>5.4.0-M1</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.integration.samples.testing.aggregator;
import static org.hamcrest.MatcherAssert.assertThat;
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.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
import java.util.List;
@@ -36,15 +36,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
*
* Shows how to test a custom aggregator. Unit test for the class and
* tests for the integration subflow.
* The subflow has direct input and output channels. The flow would
* be a fragment of a larger flow. Since the output channel is direct,
* it has no subscribers outside the context of a larger flow. So,
* it has no subscribers outside the context of a larger flow. So,
* in this test case, we bridge it to a {@link QueueChannel} to
* facilitate easy testing.
*
*
* @author Gary Russell
* @since 2.0.2
*
@@ -52,10 +52,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration // default context name is <ClassName>-context.xml
@RunWith(SpringJUnit4ClassRunner.class)
public class CommaDelimitedAggregatorTests {
@Autowired
MessageChannel inputChannel;
@Autowired
QueueChannel testChannel;
@@ -65,7 +65,7 @@ public class CommaDelimitedAggregatorTests {
String out = new CommaDelimitedAggregator().aggregate(splits);
assertEquals("a,b,c", out);
}
@Test
public void unitTestClass2() {
List<String> splits = new CommaDelimitedSplitter().split(" a ,, c ");

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.integration.samples.testing.filter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
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.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
@@ -34,30 +34,30 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
* Shows how to test a filter.
*
* Shows how to test a filter.
* The filter has direct input and output channels. The filter configuration would
* be a fragment of a larger flow. Since the output channel is direct,
* it has no subscribers outside the context of a larger flow. So,
* it has no subscribers outside the context of a larger flow. So,
* in this test case, we bridge it to a {@link QueueChannel} to
* facilitate easy testing.
*
*
* Similarly, we bridge the discard channel which is configured on the second
* filter instance.
*
*
* @author Gary Russell
* @since 2.0.2
*/
@ContextConfiguration // default context name is <ClassName>-context.xml
@RunWith(SpringJUnit4ClassRunner.class)
public class PetFilterTests {
@Autowired
MessageChannel inputChannel;
@Autowired
MessageChannel inputChannel2;
@Autowired
QueueChannel testChannel;
@@ -72,19 +72,19 @@ public class PetFilterTests {
String payload = "CAT:Fluffy";
assertFalse(new PetFilter().dogsOnly(payload));
}
@Test
public void unitTestClassDog() {
String payload = "DOG:Fido";
assertTrue(new PetFilter().dogsOnly(payload));
}
@Test
public void unitTestClassLizard() {
String payload = "LIZARD:Scaly";
assertFalse(new PetFilter().dogsOnly(payload));
}
@Test
public void testCat() {
String payload = "CAT:Fluffy";
@@ -112,7 +112,7 @@ public class PetFilterTests {
Message<?> outMessage = testChannel.receive(0);
assertNull("Expected no output message", outMessage);
}
@Test
public void testCatDiscard() {
String payload = "CAT:Fluffy";

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.integration.samples.testing.gateway;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeader;
import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
@@ -31,15 +31,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
*
* Shows how to test a gateway to ensure the message injected
* into the Spring Integration flow is what we expected.
* The gateway uses a direct input channel. The configuration would
* be a fragment of a larger flow. Since the input channel is direct,
* it has no subscribers outside the context of a larger flow. So,
* it has no subscribers outside the context of a larger flow. So,
* in this test case, we bridge it to a {@link QueueChannel} to
* facilitate easy testing.
*
*
* @author Gary Russell
* @since 2.0.2
*
@@ -47,13 +47,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration // default context name is <ClassName>-context.xml
@RunWith(SpringJUnit4ClassRunner.class)
public class GatewayTests {
@Autowired
QueueChannel testChannel;
@Autowired
VoidGateway gateway;
@Test
public void testTrueHeader() {
String payload = "XXXABCXXX";

View File

@@ -15,9 +15,9 @@
*/
package org.springframework.integration.samples.testing.router;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
import org.junit.Test;
@@ -32,51 +32,51 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
*
* Shows how to test a router; the router is configured to route to direct
* channel names. The configuration would
* be a fragment of a larger flow. Since the output channels are direct,
* they have no subscribers outside the context of a larger flow. So,
* they have no subscribers outside the context of a larger flow. So,
* in this test case, we bridge them to {@link QueueChannel}s to
* facilitate easy testing.
*
*
* @author Gary Russell
* @since 2.0.2
*/
@ContextConfiguration // default context name is <ClassName>-context.xml
@RunWith(SpringJUnit4ClassRunner.class)
public class PetRouterTests {
@Autowired
MessageChannel inputChannel;
@Autowired
QueueChannel testFelineChannel;
@Autowired
QueueChannel testCanineChannel;
@Autowired
QueueChannel testUnknownPetTypeChannel;
@Test
public void unitTestClassCat() {
String payload = "CAT:Fluffy";
assertEquals("felineChannel", new PetRouter().route(payload));
}
@Test
public void unitTestClassDog() {
String payload = "DOG:Fido";
assertEquals("canineChannel", new PetRouter().route(payload));
}
@Test
public void unitTestClassLizard() {
String payload = "LIZARD:Scaly";
assertEquals("unknownPetTypeChannel", new PetRouter().route(payload));
}
@Test
public void testCat() {
String payload = "CAT:Fluffy";

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.integration.samples.testing.splitter;
import static org.hamcrest.MatcherAssert.assertThat;
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.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
import java.util.List;
@@ -35,15 +35,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
*
* Shows how to test a custom splitter. Unit test for the class and
* tests for the integration subflow.
* The splitter has direct input and output channels. The splitter would
* be a fragment of a larger flow. Since the output channel is direct,
* it has no subscribers outside the context of a larger flow. So,
* it has no subscribers outside the context of a larger flow. So,
* in this test case, we bridge it to a {@link QueueChannel} to
* facilitate easy testing.
*
*
* @author Gary Russell
* @since 2.0.2
*
@@ -51,10 +51,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration // default context name is <ClassName>-context.xml
@RunWith(SpringJUnit4ClassRunner.class)
public class CommaDelimitedSplitterTests {
@Autowired
MessageChannel inputChannel;
@Autowired
QueueChannel testChannel;
@@ -66,7 +66,7 @@ public class CommaDelimitedSplitterTests {
assertEquals("b", splits.get(1));
assertEquals("c", splits.get(2));
}
@Test
public void unitTestClass2() {
List<String> splits = new CommaDelimitedSplitter().split(" a ,, c ");