Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Migrate tests to JUnit 5 #101
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Dec 21, 2016
1 parent 07d0f12 commit 4ae4a0b
Show file tree
Hide file tree
Showing 61 changed files with 480 additions and 280 deletions.
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<log4j.version>1.2.14</log4j.version>
<log4j2.version>2.3</log4j2.version>
<junit.version>4.12</junit.version>
<junit5.version>5.0.0-M3</junit5.version>
<assertj.version>3.6.1</assertj.version>
<mockito.version>2.3.11</mockito.version>
<jackson.version>2.7.5</jackson.version>
Expand Down Expand Up @@ -305,6 +306,20 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class RuntimeContainerUnitTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import java.util.List;

import org.jboss.common.beans.property.ByteEditor;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class StackTraceFilterUnitTests {

@Before
@BeforeEach
public void before() throws Exception {
StackTraceFilter.loadSetttings(StackTraceFilter.FILTER_SETTINGS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.logging.Level;

import org.jboss.logmanager.ExtLogRecord;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import biz.paluch.logging.gelf.intern.GelfMessage;
import biz.paluch.logging.gelf.jboss7.JBoss7JulLogEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Mark Paluch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
import java.io.InputStream;
import java.net.Socket;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import external.MockitoExtension;

/**
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class CloserUnitTests {

@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.zip.GZIPInputStream;

import org.jboss.as.protocol.StreamUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import biz.paluch.logging.StackTraceFilter;
import biz.paluch.logging.gelf.GelfMessageBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
import java.util.Collections;
import java.util.HashMap;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import biz.paluch.logging.gelf.GelfMessageAssembler;
import external.MockitoExtension;

/**
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class GelfSenderFactoryUnitTests {

public static final String THE_HOST = "thehost";
Expand All @@ -44,14 +44,14 @@ public class GelfSenderFactoryUnitTests {

private GelfSenderFactory sut = new GelfSenderFactory();

@Before
@BeforeEach
public void before() throws Exception {
GelfSenderFactory.addGelfSenderProvider(senderProvider);

when(assembler.getHost()).thenReturn(THE_HOST);
}

@After
@AfterEach
public void after() throws Exception {
GelfSenderFactory.removeGelfSenderProvider(senderProvider);
GelfSenderFactory.removeAllAddedSenderProviders();
Expand Down Expand Up @@ -124,7 +124,7 @@ public void testCreateSenderFailIOException() throws Exception {

}

@Test(expected = NullPointerException.class)
@Test
public void testCreateSenderFailNPE() throws Exception {

mockSupports();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

Expand All @@ -19,7 +19,7 @@ public class JsonWriterUnitTests {

private String content;

@Before
@BeforeEach
public void before() throws Exception {

byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/utf8.txt"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.zip.GZIPInputStream;

import org.jboss.as.protocol.StreamUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import biz.paluch.logging.StackTraceFilter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
Expand All @@ -28,7 +26,6 @@
* @author Aleksandar Stojadinovic
*/
@SuppressWarnings("unchecked")
@RunWith(MockitoJUnitRunner.class)
public class GelfHTTPSenderIntegrationTests {

private static final GelfMessage GELF_MESSAGE = new GelfMessage("shortMessage", "fullMessage", 12121L, "WARNING");
Expand All @@ -38,7 +35,7 @@ public class GelfHTTPSenderIntegrationTests {
@Mock
ErrorReporter errorReporter;

@Before
@BeforeEach
public void setUp() throws Exception {
server = new NettyLocalHTTPServer();
server.run();
Expand All @@ -57,7 +54,7 @@ public void reportError(String message, Exception e) {
});
}

@After
@AfterEach
public void tearDown() {
server.close();
sender.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.lang.reflect.Field;
import java.util.Set;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import biz.paluch.logging.gelf.intern.GelfMessage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
Expand All @@ -33,7 +33,7 @@ public class GelfTCPSSLSenderIntegrationTests {
private static NettyLocalServer server = new NettyLocalServer(NioServerSocketChannel.class);
private static SSLContext sslContext;

@BeforeClass
@BeforeAll
public static void setupClass() throws Exception {

File file = new File("work/keystore.jks");
Expand Down Expand Up @@ -94,7 +94,7 @@ public void reportError(String message, Exception e) {
tcpsslSender.close();
}

@AfterClass
@AfterAll
public static void afterClass() throws Exception {
server.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
Expand All @@ -25,7 +25,7 @@ public class GelfTCPSenderIntegrationTests {

private ByteArrayOutputStream out = new ByteArrayOutputStream();

@Test(timeout = 10000)
@Test
public void name() throws Exception {

final ServerSocket serverSocket = new ServerSocket(1234);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,25 @@
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.util.Random;

import org.apache.commons.lang.RandomStringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
import external.MockitoExtension;

/**
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class GelfTCPSenderUnitTests {

@Mock
Expand Down Expand Up @@ -77,9 +76,11 @@ public void connectionTimeoutShouldApply() throws Exception {
assertThat(duration > 500).isTrue();
}

@Test(expected = UnknownHostException.class)
@Test
public void unknownHostShouldThrowException() throws Exception {

This comment has been minimized.

Copy link
@xasx

xasx Dec 29, 2016

Contributor

Don't you miss something here? Expected exception...

This comment has been minimized.

Copy link
@mp911de

mp911de Dec 30, 2016

Author Owner

Good catch! It didin't pop up as surefire/failsafe require a dedicated activation of JUnit 5 so tests didn't run with mvn test.

new GelfTCPSender("unknown.host.unknown", 65534, 100, 100, errorReporter);

}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package biz.paluch.logging.gelf.intern.sender;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
Expand All @@ -9,20 +10,21 @@
import java.net.UnknownHostException;
import java.util.Random;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.Executable;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
import external.MockitoExtension;

/**
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class GelfUDPSenderUnitTests {

@Mock
Expand All @@ -41,9 +43,15 @@ public void unreachablePacketsShouldBeDiscardedSilently() throws Exception {
verifyZeroInteractions(errorReporter);
}

@Test(expected = UnknownHostException.class)
@Test
public void unknownHostShouldThrowException() throws Exception {
new GelfUDPSender("unknown.host.unknown", 65534, errorReporter);

assertThrows(UnknownHostException.class, new Executable() {
@Override
public void execute() throws Throwable {
new GelfUDPSender("unknown.host.unknown", 65534, errorReporter);
}
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Map;

import org.fest.assertions.MapAssert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Mark Paluch
Expand Down
Loading

0 comments on commit 4ae4a0b

Please sign in to comment.