Skip to content

Commit

Permalink
💎 Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpavlov authored and kpavlov committed Feb 8, 2022
1 parent e6181e4 commit ac8abfa
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 52 deletions.
4 changes: 2 additions & 2 deletions build.sh
Expand Up @@ -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
Expand Up @@ -14,7 +14,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class AbstractIso8583ConnectorTest<M extends IsoMessage> {
class AbstractIso8583ConnectorTest<M extends IsoMessage> {

private AbstractIso8583Connector<ConnectorConfiguration, ServerBootstrap, M> subject;

Expand Down Expand Up @@ -45,7 +45,7 @@ protected ServerBootstrap createBootstrap() {
}

@Test
public void addMessageListener() throws Exception {
void addMessageListener() throws Exception {
//given
@SuppressWarnings("unchecked") final IsoMessageListener<M> listener = mock(IsoMessageListener.class);
when(listener.applies(message)).thenReturn(true);
Expand All @@ -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<M> listener = mock(IsoMessageListener.class);
Expand Down
Expand Up @@ -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<Integer, IsoMessage> receivedMessages = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -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));
Expand Down
Expand Up @@ -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()));
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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(() -> {
Expand Down Expand Up @@ -96,7 +97,7 @@ public void shutdownClients() {
}

@Test
public void shouldProcessRequestsFromMultipleClientsWithoutDeadlocks() throws Exception {
void shouldProcessRequestsFromMultipleClientsWithoutDeadlocks() throws Exception {

for (final var client : clients) {
new Thread(() -> {
Expand All @@ -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<IsoMessage> 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)) {
Expand All @@ -150,12 +152,13 @@ protected void configureServer(final Iso8583Server<IsoMessage> 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));
Expand Down
Expand Up @@ -16,7 +16,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class Iso8583DecoderTest {
class Iso8583DecoderTest {

private Iso8583Decoder decoder;

Expand All @@ -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);
Expand Down
Expand Up @@ -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));
Expand Down
Expand Up @@ -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<IsoMessage> listener1;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Expand Up @@ -19,7 +19,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class IsoMessageLoggingHandlerTest {
class IsoMessageLoggingHandlerTest {

private IsoMessageLoggingHandler handler;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit ac8abfa

Please sign in to comment.