From 1076538e30f2056eb376d4629369a92f31af2777 Mon Sep 17 00:00:00 2001 From: kpavlov <{ID}+{username}@users.noreply.github.com> Date: Tue, 8 Feb 2022 21:55:10 +0200 Subject: [PATCH] :gem: Cleanup tests --- build.sh | 4 +- .../AbstractIso8583ConnectorTest.java | 6 +-- .../jreactive8583/example/ClientServerIT.java | 4 +- .../jreactive8583/it/ClientReconnectIT.java | 4 +- .../jreactive8583/it/LockDetectionIT.java | 21 +++++---- .../netty/codec/Iso8583DecoderTest.java | 4 +- ...tringLengthFieldBasedFrameDecoderTest.java | 2 +- .../CompositeIsoMessageHandlerTest.java | 14 +++--- .../IsoMessageLoggingHandlerTest.java | 46 ++++++++++--------- .../pipeline/ParseExceptionHandlerTest.java | 2 +- 10 files changed, 55 insertions(+), 52 deletions(-) diff --git a/build.sh b/build.sh index acb2441..52cacfd 100755 --- a/build.sh +++ b/build.sh @@ -4,9 +4,9 @@ set -e echo "Cleanup 🧹" rm -rf build -echo "Building 📦" +echo "\nBuilding 📦" #./gradlew build --scan ./gradlew $GRADLE_ARGS build -echo "Testing 🧪" +echo "\nTesting 🧪" ./gradlew $GRADLE_ARGS check --stacktrace diff --git a/src/test/java/com/github/kpavlov/jreactive8583/AbstractIso8583ConnectorTest.java b/src/test/java/com/github/kpavlov/jreactive8583/AbstractIso8583ConnectorTest.java index c03a99c..6da2c77 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/AbstractIso8583ConnectorTest.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/AbstractIso8583ConnectorTest.java @@ -14,7 +14,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class AbstractIso8583ConnectorTest { +class AbstractIso8583ConnectorTest { private AbstractIso8583Connector subject; @@ -45,7 +45,7 @@ protected ServerBootstrap createBootstrap() { } @Test - public void addMessageListener() throws Exception { + void addMessageListener() throws Exception { //given @SuppressWarnings("unchecked") final IsoMessageListener listener = mock(IsoMessageListener.class); when(listener.applies(message)).thenReturn(true); @@ -59,7 +59,7 @@ public void addMessageListener() throws Exception { } @Test - public void removeMessageListener() throws Exception { + void removeMessageListener() throws Exception { //given subject.addMessageListener(listener); @SuppressWarnings("unchecked") final IsoMessageListener listener = mock(IsoMessageListener.class); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/example/ClientServerIT.java b/src/test/java/com/github/kpavlov/jreactive8583/example/ClientServerIT.java index 658b741..bef4022 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/example/ClientServerIT.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/example/ClientServerIT.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -public class ClientServerIT extends AbstractIT { +class ClientServerIT extends AbstractIT { private final Map receivedMessages = new ConcurrentHashMap<>(); @@ -55,7 +55,7 @@ public boolean onMessage(final ChannelHandlerContext ctx, final IsoMessage isoMe } @Test - public void shouldSendAsyncCaptureRequest() { + void shouldSendAsyncCaptureRequest() { // given final var finMessage = client.getIsoMessageFactory().newMessage(0x0200); finMessage.setField(60, IsoType.LLLVAR.value("foo", 3)); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/it/ClientReconnectIT.java b/src/test/java/com/github/kpavlov/jreactive8583/it/ClientReconnectIT.java index bfbef72..0dc136e 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/it/ClientReconnectIT.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/it/ClientReconnectIT.java @@ -8,10 +8,10 @@ import static org.awaitility.Awaitility.await; @Tag("reconnect") -public class ClientReconnectIT extends AbstractIT { +class ClientReconnectIT extends AbstractIT { @Test - public void clientShouldReconnectWhenConnectionLost() throws Exception { + void clientShouldReconnectWhenConnectionLost() throws Exception { //when server.shutdown(); await().alias("client was disconnected").until(() -> (!client.isConnected())); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/it/LockDetectionIT.java b/src/test/java/com/github/kpavlov/jreactive8583/it/LockDetectionIT.java index 2aef79b..4c421a4 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/it/LockDetectionIT.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/it/LockDetectionIT.java @@ -7,6 +7,7 @@ import com.solab.iso8583.IsoMessage; import com.solab.iso8583.IsoType; import io.netty.channel.ChannelHandlerContext; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.*; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -22,7 +23,7 @@ import static org.slf4j.LoggerFactory.getLogger; @Tag("slow") -public class LockDetectionIT extends AbstractIT { +class LockDetectionIT extends AbstractIT { private static final int NUM_CLIENTS = 20; private static final int NUM_MESSAGES = 100; @@ -39,7 +40,7 @@ public class LockDetectionIT extends AbstractIT { @BeforeAll public static void beforeAll() { threadMXBean = ManagementFactory.getThreadMXBean(); - assertThat(threadMXBean.isThreadContentionMonitoringSupported()); + assertThat(threadMXBean.isThreadContentionMonitoringSupported()).isTrue(); threadMXBean.setThreadContentionMonitoringEnabled(true); monitoringThread = new Thread(() -> { @@ -96,7 +97,7 @@ public void shutdownClients() { } @Test - public void shouldProcessRequestsFromMultipleClientsWithoutDeadlocks() throws Exception { + void shouldProcessRequestsFromMultipleClientsWithoutDeadlocks() throws Exception { for (final var client : clients) { new Thread(() -> { @@ -119,20 +120,21 @@ public void shouldProcessRequestsFromMultipleClientsWithoutDeadlocks() throws Ex latch.await(); monitoringThread.join(); - assertThat(monitorDeadlockedCount.get()).as("Monitor Deadlock Count").isEqualTo(0); - assertThat(deadlockedCount.get()).as("Deadlock Count").isEqualTo(0); + assertThat(monitorDeadlockedCount.get()).as("Monitor Deadlock Count").isZero(); + assertThat(deadlockedCount.get()).as("Deadlock Count").isZero(); } @Override protected void configureClient(final Iso8583Client client) { client.addMessageListener(new IsoMessageListener<>() { @Override - public boolean applies(final IsoMessage isoMessage) { + public boolean applies(@NotNull final IsoMessage isoMessage) { return isoMessage.getType() == 0x210; } @Override - public boolean onMessage(final ChannelHandlerContext ctx, final IsoMessage isoMessage) { + public boolean onMessage(@NotNull final ChannelHandlerContext ctx, + @NotNull final IsoMessage isoMessage) { latch.countDown(); final var count = latch.getCount(); if (count % 100 == 0 || (count < 10 && count % 10 == 0)) { @@ -150,12 +152,13 @@ protected void configureServer(final Iso8583Server server) { server.addMessageListener(new IsoMessageListener<>() { @Override - public boolean applies(final IsoMessage isoMessage) { + public boolean applies(@NotNull final IsoMessage isoMessage) { return isoMessage.getType() == 0x200; } @Override - public boolean onMessage(final ChannelHandlerContext ctx, final IsoMessage isoMessage) { + public boolean onMessage(@NotNull final ChannelHandlerContext ctx, + @NotNull final IsoMessage isoMessage) { final var response = server.getIsoMessageFactory().createResponse(isoMessage); response.setField(39, IsoType.ALPHA.value("00", 2)); response.setField(60, IsoType.LLLVAR.value("XXX", 3)); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/Iso8583DecoderTest.java b/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/Iso8583DecoderTest.java index bf8ebc4..56a89fb 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/Iso8583DecoderTest.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/Iso8583DecoderTest.java @@ -16,7 +16,7 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -public class Iso8583DecoderTest { +class Iso8583DecoderTest { private Iso8583Decoder decoder; @@ -35,7 +35,7 @@ public void beforeClass() { } @Test - public void testDecodeEmptyByteBufDoesNothing() throws Exception { + void testDecodeEmptyByteBufDoesNothing() throws Exception { when(byteBuf.isReadable()).thenReturn(false); decoder.decode(ctx, byteBuf, out); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/StringLengthFieldBasedFrameDecoderTest.java b/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/StringLengthFieldBasedFrameDecoderTest.java index 9bd7a1d..4708b71 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/StringLengthFieldBasedFrameDecoderTest.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/netty/codec/StringLengthFieldBasedFrameDecoderTest.java @@ -49,7 +49,7 @@ public void beforeClass() { } @Test - public void shouldGetUnadjustedFrameLength() { + void shouldGetUnadjustedFrameLength() { // given final var content = "MESSAGE"; when(message.writeData()).thenReturn(content.getBytes(StandardCharsets.US_ASCII)); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/CompositeIsoMessageHandlerTest.java b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/CompositeIsoMessageHandlerTest.java index 426b31e..7622af9 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/CompositeIsoMessageHandlerTest.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/CompositeIsoMessageHandlerTest.java @@ -9,12 +9,10 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -public class CompositeIsoMessageHandlerTest { +class CompositeIsoMessageHandlerTest { @Mock private IsoMessageListener listener1; @@ -35,7 +33,7 @@ public void setUp() { } @Test - public void shouldRemoveListener() throws Exception { + void shouldRemoveListener() throws Exception { //given when(listener1.applies(message)).thenReturn(true); when(listener3.applies(message)).thenReturn(true); @@ -52,7 +50,7 @@ public void shouldRemoveListener() throws Exception { } @Test - public void shouldHandleWithAppropriateHandler() throws Exception { + void shouldHandleWithAppropriateHandler() throws Exception { //given when(listener1.applies(message)).thenReturn(false); when(listener2.applies(message)).thenReturn(true); @@ -69,7 +67,7 @@ public void shouldHandleWithAppropriateHandler() throws Exception { } @Test - public void testStopProcessing() throws Exception { + void testStopProcessing() throws Exception { //given when(listener1.applies(message)).thenReturn(true); when(listener2.applies(message)).thenReturn(true); @@ -86,7 +84,7 @@ public void testStopProcessing() throws Exception { } @Test - public void shouldNotFailOnExceptionInFailsafeMode() throws Exception { + void shouldNotFailOnExceptionInFailsafeMode() throws Exception { //given handler = new CompositeIsoMessageHandler<>(false); handler.addListeners(listener1, listener2, listener3); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandlerTest.java b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandlerTest.java index 76648fd..96a721e 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandlerTest.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandlerTest.java @@ -19,7 +19,7 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -public class IsoMessageLoggingHandlerTest { +class IsoMessageLoggingHandlerTest { private IsoMessageLoggingHandler handler; @@ -56,48 +56,50 @@ public void setUp() throws Exception { } @Test - public void testMaskSensitiveData() { + void testMaskSensitiveData() { handler = new IsoMessageLoggingHandler(LogLevel.DEBUG, false, true, new int[]{34, 35, 36, 45, 112}); final var result = handler.format(ctx, "someEvent", message); - assertThat(result).doesNotContain(pan); - assertThat(result).doesNotContain(cvv); - assertThat(result).doesNotContain(track1); - assertThat(result).doesNotContain(track2); - assertThat(result).doesNotContain(track3); + assertThat(result) + .doesNotContain(pan) + .doesNotContain(cvv) + .doesNotContain(track1) + .doesNotContain(track2) + .doesNotContain(track3); } @Test - public void testMaskDefaultSensitiveData() { + void testMaskDefaultSensitiveData() { handler = new IsoMessageLoggingHandler(LogLevel.DEBUG, false, true, IsoMessageLoggingHandler.DEFAULT_MASKED_FIELDS); final var result = handler.format(ctx, "someEvent", message); - assertThat(result).doesNotContain(pan); - assertThat(result).doesNotContain(track1).as("track1"); - assertThat(result).doesNotContain(track2).as("track2"); - assertThat(result).doesNotContain(track3).as("track3"); - // there is no standard field for CVV, so it's not masked by default - assertThat(result).contains(cvv); + assertThat(result) + .doesNotContain(pan) + .doesNotContain(track1).as("track1") + .doesNotContain(track2).as("track2") + .doesNotContain(track3).as("track3") + .contains(cvv); // there is no standard field for CVV, so it's not masked by default } @Test - public void testPrintSensitiveData() { + void testPrintSensitiveData() { handler = new IsoMessageLoggingHandler(LogLevel.DEBUG, true, true, IsoMessageLoggingHandler.DEFAULT_MASKED_FIELDS); final var result = handler.format(ctx, "someEvent", message); - assertThat(result).contains(pan); - assertThat(result).contains(cvv); - assertThat(result).contains(track1); - assertThat(result).contains(track2); - assertThat(result).contains(track3); + assertThat(result) + .contains(pan) + .contains(cvv) + .contains(track1) + .contains(track2) + .contains(track3); } @Test - public void testHideFieldDescriptions() { + void testHideFieldDescriptions() { handler = new IsoMessageLoggingHandler(LogLevel.DEBUG, false, false, IsoMessageLoggingHandler.DEFAULT_MASKED_FIELDS); final var result = handler.format(ctx, "someEvent", message); @@ -106,7 +108,7 @@ public void testHideFieldDescriptions() { } @Test - public void testShowFieldDescriptions() { + void testShowFieldDescriptions() { handler = new IsoMessageLoggingHandler(LogLevel.DEBUG, false, true, IsoMessageLoggingHandler.DEFAULT_MASKED_FIELDS); final var result = handler.format(ctx, "someEvent", message); diff --git a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java index 2cd5c99..026add6 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java @@ -43,7 +43,7 @@ public void setUp() { } @Test - public void testExceptionCaught() throws Exception { + void testExceptionCaught() throws Exception { final var errorMessage = UUID.randomUUID().toString(); final var exception = new ParseException(errorMessage, 0);