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-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,12 +16,8 @@
|
||||
|
||||
package org.springframework.integration.syslog.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.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
@@ -107,30 +103,30 @@ public class SyslogReceivingChannelAdapterParserTests {
|
||||
socket.send(packet);
|
||||
socket.close();
|
||||
Message<?> message = foo.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
adapter1.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitChannelUdp() throws Exception {
|
||||
assertEquals(1514, TestUtils.getPropertyValue(foobar, "udpAdapter.port"));
|
||||
assertSame(foo, TestUtils.getPropertyValue(foobar, "outputChannel"));
|
||||
assertThat(TestUtils.getPropertyValue(foobar, "udpAdapter.port")).isEqualTo(1514);
|
||||
assertThat(TestUtils.getPropertyValue(foobar, "outputChannel")).isSameAs(foo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitUdp() throws Exception {
|
||||
assertSame(explicitUdp, TestUtils.getPropertyValue(explicitUdpAdapter, "outputChannel"));
|
||||
assertThat(TestUtils.getPropertyValue(explicitUdpAdapter, "outputChannel")).isSameAs(explicitUdp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullBoatUdp() {
|
||||
assertSame(foo, TestUtils.getPropertyValue(fullBoatUdp, "outputChannel"));
|
||||
assertFalse(fullBoatUdp.isAutoStartup());
|
||||
assertEquals(123, fullBoatUdp.getPhase());
|
||||
assertEquals(456L, TestUtils.getPropertyValue(fullBoatUdp, "messagingTemplate.sendTimeout"));
|
||||
assertSame(converter, TestUtils.getPropertyValue(fullBoatUdp, "converter"));
|
||||
assertSame(errors, TestUtils.getPropertyValue(fullBoatUdp, "errorChannel"));
|
||||
assertFalse(TestUtils.getPropertyValue(fullBoatUdp, "udpAdapter.mapper.lookupHost", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatUdp, "outputChannel")).isSameAs(foo);
|
||||
assertThat(fullBoatUdp.isAutoStartup()).isFalse();
|
||||
assertThat(fullBoatUdp.getPhase()).isEqualTo(123);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatUdp, "messagingTemplate.sendTimeout")).isEqualTo(456L);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatUdp, "converter")).isSameAs(converter);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatUdp, "errorChannel")).isSameAs(errors);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatUdp, "udpAdapter.mapper.lookupHost", Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,20 +141,20 @@ public class SyslogReceivingChannelAdapterParserTests {
|
||||
socket.getOutputStream().write(buf);
|
||||
socket.close();
|
||||
Message<?> message = bar.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
adapter2.stop();
|
||||
assertNotNull(TestUtils.getPropertyValue(adapter2, "connectionFactory.applicationEventPublisher"));
|
||||
assertThat(TestUtils.getPropertyValue(adapter2, "connectionFactory.applicationEventPublisher")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullBoatTcp() {
|
||||
assertSame(bar, TestUtils.getPropertyValue(fullBoatTcp, "outputChannel"));
|
||||
assertFalse(fullBoatTcp.isAutoStartup());
|
||||
assertEquals(123, fullBoatTcp.getPhase());
|
||||
assertEquals(456L, TestUtils.getPropertyValue(fullBoatUdp, "messagingTemplate.sendTimeout"));
|
||||
assertSame(rfc5424, TestUtils.getPropertyValue(fullBoatTcp, "converter"));
|
||||
assertSame(errors, TestUtils.getPropertyValue(fullBoatTcp, "errorChannel"));
|
||||
assertSame(cf, TestUtils.getPropertyValue(fullBoatTcp, "connectionFactory"));
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatTcp, "outputChannel")).isSameAs(bar);
|
||||
assertThat(fullBoatTcp.isAutoStartup()).isFalse();
|
||||
assertThat(fullBoatTcp.getPhase()).isEqualTo(123);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatUdp, "messagingTemplate.sendTimeout")).isEqualTo(456L);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatTcp, "converter")).isSameAs(rfc5424);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatTcp, "errorChannel")).isSameAs(errors);
|
||||
assertThat(TestUtils.getPropertyValue(fullBoatTcp, "connectionFactory")).isSameAs(cf);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,8 +165,10 @@ public class SyslogReceivingChannelAdapterParserTests {
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (BeanDefinitionParsingException e) {
|
||||
assertTrue(e.getMessage().startsWith(
|
||||
"Configuration problem: When child element 'udp-attributes' is present, 'port' must be defined there"));
|
||||
assertThat(e.getMessage().startsWith(
|
||||
"Configuration problem: When child element 'udp-attributes' is present, 'port' must be defined " +
|
||||
"there"))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +180,7 @@ public class SyslogReceivingChannelAdapterParserTests {
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
assertEquals("Cannot specify both 'port' and 'connectionFactory'", e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("Cannot specify both 'port' and 'connectionFactory'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +194,8 @@ public class SyslogReceivingChannelAdapterParserTests {
|
||||
catch (BeanCreationException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
assertEquals("Cannot specify 'udp-attributes' when the protocol is 'tcp'", e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage())
|
||||
.isEqualTo("Cannot specify 'udp-attributes' when the protocol is 'tcp'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,8 +207,8 @@ public class SyslogReceivingChannelAdapterParserTests {
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
assertEquals("Cannot specify 'connection-factory' unless the protocol is 'tcp'",
|
||||
e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage())
|
||||
.isEqualTo("Cannot specify 'connection-factory' unless the protocol is 'tcp'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-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.syslog.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.List;
|
||||
@@ -58,15 +58,15 @@ public class SyslogDeserializerTests {
|
||||
|
||||
Map<String, ?> map = deserializer.deserialize(new ByteArrayInputStream(VALID_FRAMED_ENTRY.getBytes()));
|
||||
|
||||
assertEquals(1, map.get(SyslogHeaders.FACILITY));
|
||||
assertEquals(6, map.get(SyslogHeaders.SEVERITY));
|
||||
assertEquals(1, map.get(SyslogHeaders.VERSION));
|
||||
assertEquals("2014-06-20T09:14:07+00:00", map.get(SyslogHeaders.TIMESTAMP));
|
||||
assertEquals("loggregator", map.get(SyslogHeaders.HOST));
|
||||
assertEquals("d0602076-b14a-4c55-852a-981e7afeed38", map.get(SyslogHeaders.APP_NAME));
|
||||
assertEquals("DEA", map.get(SyslogHeaders.PROCID));
|
||||
assertEquals("-", map.get(SyslogHeaders.MSGID));
|
||||
assertEquals("Removing instance", map.get(SyslogHeaders.MESSAGE));
|
||||
assertThat(map.get(SyslogHeaders.FACILITY)).isEqualTo(1);
|
||||
assertThat(map.get(SyslogHeaders.SEVERITY)).isEqualTo(6);
|
||||
assertThat(map.get(SyslogHeaders.VERSION)).isEqualTo(1);
|
||||
assertThat(map.get(SyslogHeaders.TIMESTAMP)).isEqualTo("2014-06-20T09:14:07+00:00");
|
||||
assertThat(map.get(SyslogHeaders.HOST)).isEqualTo("loggregator");
|
||||
assertThat(map.get(SyslogHeaders.APP_NAME)).isEqualTo("d0602076-b14a-4c55-852a-981e7afeed38");
|
||||
assertThat(map.get(SyslogHeaders.PROCID)).isEqualTo("DEA");
|
||||
assertThat(map.get(SyslogHeaders.MSGID)).isEqualTo("-");
|
||||
assertThat(map.get(SyslogHeaders.MESSAGE)).isEqualTo("Removing instance");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,15 +76,15 @@ public class SyslogDeserializerTests {
|
||||
|
||||
Map<String, ?> map = deserializer.deserialize(new ByteArrayInputStream(VALID_UNFRAMED_ENTRY.getBytes()));
|
||||
|
||||
assertEquals(1, map.get(SyslogHeaders.FACILITY));
|
||||
assertEquals(6, map.get(SyslogHeaders.SEVERITY));
|
||||
assertEquals(1, map.get(SyslogHeaders.VERSION));
|
||||
assertEquals("2014-06-20T09:14:07+00:00", map.get(SyslogHeaders.TIMESTAMP));
|
||||
assertEquals("loggregator", map.get(SyslogHeaders.HOST));
|
||||
assertEquals("d0602076-b14a-4c55-852a-981e7afeed38", map.get(SyslogHeaders.APP_NAME));
|
||||
assertEquals("DEA", map.get(SyslogHeaders.PROCID));
|
||||
assertEquals("-", map.get(SyslogHeaders.MSGID));
|
||||
assertEquals("Removing instance", map.get(SyslogHeaders.MESSAGE));
|
||||
assertThat(map.get(SyslogHeaders.FACILITY)).isEqualTo(1);
|
||||
assertThat(map.get(SyslogHeaders.SEVERITY)).isEqualTo(6);
|
||||
assertThat(map.get(SyslogHeaders.VERSION)).isEqualTo(1);
|
||||
assertThat(map.get(SyslogHeaders.TIMESTAMP)).isEqualTo("2014-06-20T09:14:07+00:00");
|
||||
assertThat(map.get(SyslogHeaders.HOST)).isEqualTo("loggregator");
|
||||
assertThat(map.get(SyslogHeaders.APP_NAME)).isEqualTo("d0602076-b14a-4c55-852a-981e7afeed38");
|
||||
assertThat(map.get(SyslogHeaders.PROCID)).isEqualTo("DEA");
|
||||
assertThat(map.get(SyslogHeaders.MSGID)).isEqualTo("-");
|
||||
assertThat(map.get(SyslogHeaders.MESSAGE)).isEqualTo("Removing instance");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,16 +94,16 @@ public class SyslogDeserializerTests {
|
||||
|
||||
Map<String, ?> map = deserializer.deserialize(new ByteArrayInputStream(SD_ENTRY_1.getBytes()));
|
||||
|
||||
assertEquals(1, map.get(SyslogHeaders.FACILITY));
|
||||
assertEquals(6, map.get(SyslogHeaders.SEVERITY));
|
||||
assertEquals(1, map.get(SyslogHeaders.VERSION));
|
||||
assertEquals("2014-06-20T09:14:07+00:00", map.get(SyslogHeaders.TIMESTAMP));
|
||||
assertEquals("loggregator", map.get(SyslogHeaders.HOST));
|
||||
assertEquals("d0602076-b14a-4c55-852a-981e7afeed38", map.get(SyslogHeaders.APP_NAME));
|
||||
assertEquals("DEA", map.get(SyslogHeaders.PROCID));
|
||||
assertEquals("-", map.get(SyslogHeaders.MSGID));
|
||||
assertEquals("Removing instance", map.get(SyslogHeaders.MESSAGE));
|
||||
assertEquals(1, ((List<?>) map.get(SyslogHeaders.STRUCTURED_DATA)).size());
|
||||
assertThat(map.get(SyslogHeaders.FACILITY)).isEqualTo(1);
|
||||
assertThat(map.get(SyslogHeaders.SEVERITY)).isEqualTo(6);
|
||||
assertThat(map.get(SyslogHeaders.VERSION)).isEqualTo(1);
|
||||
assertThat(map.get(SyslogHeaders.TIMESTAMP)).isEqualTo("2014-06-20T09:14:07+00:00");
|
||||
assertThat(map.get(SyslogHeaders.HOST)).isEqualTo("loggregator");
|
||||
assertThat(map.get(SyslogHeaders.APP_NAME)).isEqualTo("d0602076-b14a-4c55-852a-981e7afeed38");
|
||||
assertThat(map.get(SyslogHeaders.PROCID)).isEqualTo("DEA");
|
||||
assertThat(map.get(SyslogHeaders.MSGID)).isEqualTo("-");
|
||||
assertThat(map.get(SyslogHeaders.MESSAGE)).isEqualTo("Removing instance");
|
||||
assertThat(((List<?>) map.get(SyslogHeaders.STRUCTURED_DATA)).size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,9 +113,9 @@ public class SyslogDeserializerTests {
|
||||
|
||||
Map<String, ?> map = deserializer.deserialize(new ByteArrayInputStream(SD_ENTRY_2.getBytes()));
|
||||
|
||||
assertEquals("false", map.get(SyslogHeaders.DECODE_ERRORS));
|
||||
assertEquals("Removing instance", map.get(SyslogHeaders.MESSAGE));
|
||||
assertEquals(2, ((List<?>) map.get(SyslogHeaders.STRUCTURED_DATA)).size());
|
||||
assertThat(map.get(SyslogHeaders.DECODE_ERRORS)).isEqualTo("false");
|
||||
assertThat(map.get(SyslogHeaders.MESSAGE)).isEqualTo("Removing instance");
|
||||
assertThat(((List<?>) map.get(SyslogHeaders.STRUCTURED_DATA)).size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,8 +125,8 @@ public class SyslogDeserializerTests {
|
||||
|
||||
Map<String, ?> map = deserializer.deserialize(new ByteArrayInputStream(SD_ENTRY_3.getBytes()));
|
||||
|
||||
assertEquals("false", map.get(SyslogHeaders.DECODE_ERRORS));
|
||||
assertEquals("Removing instance", map.get(SyslogHeaders.MESSAGE));
|
||||
assertThat(map.get(SyslogHeaders.DECODE_ERRORS)).isEqualTo("false");
|
||||
assertThat(map.get(SyslogHeaders.MESSAGE)).isEqualTo("Removing instance");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,7 +136,7 @@ public class SyslogDeserializerTests {
|
||||
|
||||
Map<String, ?> map = deserializer.deserialize(new ByteArrayInputStream(SHORT_FRAMED_ENTRY.getBytes()));
|
||||
|
||||
assertEquals("true", map.get(SyslogHeaders.DECODE_ERRORS));
|
||||
assertThat(map.get(SyslogHeaders.DECODE_ERRORS)).isEqualTo("true");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.syslog.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -84,8 +82,8 @@ public class SyslogReceivingChannelAdapterTests {
|
||||
socket.send(packet);
|
||||
socket.close();
|
||||
Message<?> message = outputChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("WEBERN", message.getHeaders().get("syslog_HOST"));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getHeaders().get("syslog_HOST")).isEqualTo("WEBERN");
|
||||
adapter.stop();
|
||||
}
|
||||
|
||||
@@ -126,12 +124,12 @@ public class SyslogReceivingChannelAdapterTests {
|
||||
Socket socket = SocketFactory.getDefault().createSocket("localhost", server.getPort());
|
||||
socket.getOutputStream().write(buf);
|
||||
socket.close();
|
||||
assertTrue(sawLog.await(10, TimeUnit.SECONDS));
|
||||
assertThat(sawLog.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
Message<?> message = outputChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("WEBERN", message.getHeaders().get("syslog_HOST"));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getHeaders().get("syslog_HOST")).isEqualTo("WEBERN");
|
||||
adapter.stop();
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,10 +157,10 @@ public class SyslogReceivingChannelAdapterTests {
|
||||
socket.send(packet);
|
||||
socket.close();
|
||||
Message<?> message = outputChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("WEBERN", message.getHeaders().get("syslog_HOST"));
|
||||
assertEquals("<157>JUL 26 22:08:35 WEBERN TESTING[70729]: TEST SYSLOG MESSAGE",
|
||||
new String((byte[]) message.getPayload(), "UTF-8"));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getHeaders().get("syslog_HOST")).isEqualTo("WEBERN");
|
||||
assertThat(new String((byte[]) message.getPayload(), "UTF-8"))
|
||||
.isEqualTo("<157>JUL 26 22:08:35 WEBERN TESTING[70729]: TEST SYSLOG MESSAGE");
|
||||
adapter.stop();
|
||||
}
|
||||
|
||||
@@ -207,13 +205,13 @@ public class SyslogReceivingChannelAdapterTests {
|
||||
Socket socket = SocketFactory.getDefault().createSocket("localhost", connectionFactory.getPort());
|
||||
socket.getOutputStream().write(buf);
|
||||
socket.close();
|
||||
assertTrue(sawLog.await(10, TimeUnit.SECONDS));
|
||||
assertThat(sawLog.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<Map<String, ?>> message = (Message<Map<String, ?>>) outputChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("loggregator", message.getPayload().get("syslog_HOST"));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().get("syslog_HOST")).isEqualTo("loggregator");
|
||||
adapter.stop();
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -243,8 +241,8 @@ public class SyslogReceivingChannelAdapterTests {
|
||||
socket.close();
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<Map<String, ?>> message = (Message<Map<String, ?>>) outputChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("loggregator", message.getPayload().get("syslog_HOST"));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().get("syslog_HOST")).isEqualTo("loggregator");
|
||||
adapter.stop();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user