From 4ae4a0b338acde7f8fe784244b4a78f2c9c6a7d0 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 21 Dec 2016 21:44:03 +0100 Subject: [PATCH] Migrate tests to JUnit 5 #101 --- pom.xml | 15 ++++ .../logging/RuntimeContainerUnitTests.java | 2 +- .../logging/StackTraceFilterUnitTests.java | 6 +- .../logging/gelf/GelfUtilUnitTests.java | 2 +- .../logging/gelf/MessageFieldUnitTests.java | 2 +- .../logging/gelf/intern/CloserUnitTests.java | 9 ++- .../gelf/intern/GelfMessageUnitTests.java | 2 +- .../intern/GelfSenderFactoryUnitTests.java | 18 ++--- .../gelf/intern/JsonWriterUnitTests.java | 6 +- .../PoolingGelfMessageIntegrationTests.java | 2 +- .../GelfHTTPSenderIntegrationTests.java | 13 ++-- .../GelfREDISSenderIntegrationTests.java | 2 +- .../GelfTCPSSLSenderIntegrationTests.java | 10 +-- .../sender/GelfTCPSenderIntegrationTests.java | 4 +- .../intern/sender/GelfTCPSenderUnitTests.java | 13 ++-- .../intern/sender/GelfUDPSenderUnitTests.java | 20 +++-- .../sender/QueryStringParserUnitTests.java | 2 +- .../JBoss7GelfLogHandlerDynamicMdcTests.java | 6 +- .../jboss7/JBoss7GelfLogHandlerTests.java | 22 ++++-- .../jboss7/JBoss7GelfLogHandlerUnitTests.java | 2 +- .../gelf/jul/GelfLogHandlerErrorsTests.java | 16 ++-- .../gelf/jul/GelfLogHandlerFilterTests.java | 10 +-- .../GelfLogHandlerRedisIntegrationTests.java | 62 ++++++++++++---- .../GelfLogHandlerSystemPropertiesTests.java | 6 +- .../logging/gelf/jul/GelfLogHandlerTests.java | 6 +- .../gelf/jul/GelfLogHandlerUnitTests.java | 2 +- .../log4j/AbstractGelfLogAppenderTests.java | 2 +- .../logging/gelf/log4j/GelfLayoutTest.java | 10 +-- .../log4j/GelfLogAppenderErrorsUnitTests.java | 18 ++--- .../GelfLogAppenderNettyIntegrationTests.java | 14 ++-- ...lfLogAppenderPropertiesDynamicMdcTest.java | 6 +- ...gAppenderPropertiesIncludeFullMdcTest.java | 6 +- .../log4j/GelfLogAppenderPropertiesTests.java | 4 +- .../GelfLogAppenderSystemPropertiesTests.java | 6 +- .../gelf/log4j/GelfLogAppenderUnitTests.java | 2 +- .../gelf/log4j/GelfLogAppenderXmlTests.java | 4 +- ...AppenderAsyncNettyTcpIntegrationTests.java | 14 ++-- .../GelfLogAppenderDynamicMdcTests.java | 14 ++-- ...EmptyFacilityNettyUdpIntegrationTests.java | 26 ++++--- .../GelfLogAppenderIncludeFullMdcTests.java | 14 ++-- .../log4j2/GelfLogAppenderMinimalTests.java | 14 ++-- ...lfLogAppenderNettyTcpIntegrationTests.java | 26 ++++--- ...lfLogAppenderNettyUdpIntegrationTests.java | 26 ++++--- ...lfLogAppenderPropagateExceptionsTests.java | 20 +++-- .../GelfLogAppenderSystemPropertiesTests.java | 14 ++-- .../gelf/log4j2/GelfLogAppenderTests.java | 10 +-- .../logback/AbstractGelfLogAppenderTests.java | 2 +- ...lfLogbackAppenderDynamicHostnameTests.java | 6 +- .../GelfLogbackAppenderDynamicMdcTests.java | 6 +- .../GelfLogbackAppenderErrorsUnitTests.java | 24 ++---- ...lfLogbackAppenderHTTPIntegrationTests.java | 10 +-- .../GelfLogbackAppenderHostnameTests.java | 6 +- ...fLogbackAppenderSystemPropertiesTests.java | 6 +- .../logback/GelfLogbackAppenderTests.java | 4 +- .../logback/GelfLogbackAppenderUnitTests.java | 40 +++++++--- .../standalone/DatenpumpeImplUnitTests.java | 6 +- .../standalone/StandaloneGelfSenderTests.java | 6 +- .../wildfly/WildFlyGelfLogFormatterTests.java | 32 +++++--- .../WildFlyGelfLogHandlerDynamicMdcTests.java | 6 +- .../wildfly/WildFlyGelfLogHandlerTests.java | 23 ++++-- src/test/java/external/MockitoExtension.java | 73 +++++++++++++++++++ 61 files changed, 480 insertions(+), 280 deletions(-) create mode 100644 src/test/java/external/MockitoExtension.java diff --git a/pom.xml b/pom.xml index ab5e9bc90..e0a3aa332 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,7 @@ 1.2.14 2.3 4.12 + 5.0.0-M3 3.6.1 2.3.11 2.7.5 @@ -305,6 +306,20 @@ test + + org.junit.jupiter + junit-jupiter-api + ${junit5.version} + test + + + + org.junit.jupiter + junit-jupiter-engine + ${junit5.version} + test + + org.assertj assertj-core diff --git a/src/test/java/biz/paluch/logging/RuntimeContainerUnitTests.java b/src/test/java/biz/paluch/logging/RuntimeContainerUnitTests.java index 43e12e2ef..b5237694c 100644 --- a/src/test/java/biz/paluch/logging/RuntimeContainerUnitTests.java +++ b/src/test/java/biz/paluch/logging/RuntimeContainerUnitTests.java @@ -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 { diff --git a/src/test/java/biz/paluch/logging/StackTraceFilterUnitTests.java b/src/test/java/biz/paluch/logging/StackTraceFilterUnitTests.java index b6c20f9f8..42068097e 100644 --- a/src/test/java/biz/paluch/logging/StackTraceFilterUnitTests.java +++ b/src/test/java/biz/paluch/logging/StackTraceFilterUnitTests.java @@ -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); } diff --git a/src/test/java/biz/paluch/logging/gelf/GelfUtilUnitTests.java b/src/test/java/biz/paluch/logging/gelf/GelfUtilUnitTests.java index 93ec45007..60ed732a2 100644 --- a/src/test/java/biz/paluch/logging/gelf/GelfUtilUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/GelfUtilUnitTests.java @@ -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; diff --git a/src/test/java/biz/paluch/logging/gelf/MessageFieldUnitTests.java b/src/test/java/biz/paluch/logging/gelf/MessageFieldUnitTests.java index 0ff37acf9..ff1f2a569 100644 --- a/src/test/java/biz/paluch/logging/gelf/MessageFieldUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/MessageFieldUnitTests.java @@ -4,7 +4,7 @@ import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Mark Paluch diff --git a/src/test/java/biz/paluch/logging/gelf/intern/CloserUnitTests.java b/src/test/java/biz/paluch/logging/gelf/intern/CloserUnitTests.java index b86203dae..7c851d514 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/CloserUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/CloserUnitTests.java @@ -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 diff --git a/src/test/java/biz/paluch/logging/gelf/intern/GelfMessageUnitTests.java b/src/test/java/biz/paluch/logging/gelf/intern/GelfMessageUnitTests.java index 962217437..c64a399a8 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/GelfMessageUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/GelfMessageUnitTests.java @@ -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; diff --git a/src/test/java/biz/paluch/logging/gelf/intern/GelfSenderFactoryUnitTests.java b/src/test/java/biz/paluch/logging/gelf/intern/GelfSenderFactoryUnitTests.java index 9ed2e3c95..5a91c4a63 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/GelfSenderFactoryUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/GelfSenderFactoryUnitTests.java @@ -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"; @@ -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(); @@ -124,7 +124,7 @@ public void testCreateSenderFailIOException() throws Exception { } - @Test(expected = NullPointerException.class) + @Test public void testCreateSenderFailNPE() throws Exception { mockSupports(); diff --git a/src/test/java/biz/paluch/logging/gelf/intern/JsonWriterUnitTests.java b/src/test/java/biz/paluch/logging/gelf/intern/JsonWriterUnitTests.java index d4dd44516..f44bf3deb 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/JsonWriterUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/JsonWriterUnitTests.java @@ -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; @@ -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")); diff --git a/src/test/java/biz/paluch/logging/gelf/intern/PoolingGelfMessageIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/intern/PoolingGelfMessageIntegrationTests.java index d4b9232b5..569081003 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/PoolingGelfMessageIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/PoolingGelfMessageIntegrationTests.java @@ -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; diff --git a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSenderIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSenderIntegrationTests.java index 41d59010f..e1e358890 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSenderIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSenderIntegrationTests.java @@ -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; @@ -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"); @@ -38,7 +35,7 @@ public class GelfHTTPSenderIntegrationTests { @Mock ErrorReporter errorReporter; - @Before + @BeforeEach public void setUp() throws Exception { server = new NettyLocalHTTPServer(); server.run(); @@ -57,7 +54,7 @@ public void reportError(String message, Exception e) { }); } - @After + @AfterEach public void tearDown() { server.close(); sender.close(); diff --git a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSenderIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSenderIntegrationTests.java index 04f5fee5d..ad45a0822 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSenderIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSenderIntegrationTests.java @@ -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; diff --git a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSenderIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSenderIntegrationTests.java index 26108ac39..4bb0e909a 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSenderIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSenderIntegrationTests.java @@ -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; @@ -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"); @@ -94,7 +94,7 @@ public void reportError(String message, Exception e) { tcpsslSender.close(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { server.close(); } diff --git a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderIntegrationTests.java index 011065aac..4a9596302 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderIntegrationTests.java @@ -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; @@ -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); diff --git a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderUnitTests.java b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderUnitTests.java index 0b994caae..37c8e238f 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSenderUnitTests.java @@ -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 @@ -77,9 +76,11 @@ public void connectionTimeoutShouldApply() throws Exception { assertThat(duration > 500).isTrue(); } - @Test(expected = UnknownHostException.class) + @Test public void unknownHostShouldThrowException() throws Exception { + new GelfTCPSender("unknown.host.unknown", 65534, 100, 100, errorReporter); + } @Test diff --git a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSenderUnitTests.java b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSenderUnitTests.java index 5770f13c4..43f1b401f 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSenderUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSenderUnitTests.java @@ -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; @@ -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 @@ -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 diff --git a/src/test/java/biz/paluch/logging/gelf/intern/sender/QueryStringParserUnitTests.java b/src/test/java/biz/paluch/logging/gelf/intern/sender/QueryStringParserUnitTests.java index aa7c2e4eb..4e8459187 100644 --- a/src/test/java/biz/paluch/logging/gelf/intern/sender/QueryStringParserUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/intern/sender/QueryStringParserUnitTests.java @@ -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 diff --git a/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerDynamicMdcTests.java b/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerDynamicMdcTests.java index 9be258cf0..f2fdbf86e 100644 --- a/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerDynamicMdcTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerDynamicMdcTests.java @@ -7,8 +7,8 @@ import java.util.logging.Logger; import org.jboss.logmanager.MDC; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -28,7 +28,7 @@ public class JBoss7GelfLogHandlerDynamicMdcTests { public static final String VALUE_3 = "value3"; public static final String MDC_MY_MDC = "myMdc"; - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); LogManager.getLogManager().reset(); diff --git a/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerTests.java b/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerTests.java index cf725326f..f5897b4b1 100644 --- a/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerTests.java @@ -2,6 +2,7 @@ import static biz.paluch.logging.gelf.jboss7.JBoss7LogTestUtil.getJBoss7GelfLogHandler; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.logging.Level; import java.util.logging.LogManager; @@ -9,8 +10,9 @@ import org.jboss.logmanager.MDC; import org.jboss.logmanager.NDC; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.LogMessageField; @@ -25,7 +27,7 @@ public class JBoss7GelfLogHandlerTests { public static final String LOG_MESSAGE = "foo bar test log message"; public static final String EXPECTED_LOG_MESSAGE = LOG_MESSAGE; - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); LogManager.getLogManager().reset(); @@ -201,12 +203,18 @@ public void testFields() throws Exception { } - @Test(expected = IllegalArgumentException.class) + @Test public void testWrongConfig() throws Exception { - JBoss7GelfLogHandler handler = new JBoss7GelfLogHandler(); - handler.setGraylogHost(null); - handler.setGraylogPort(0); + assertThrows(IllegalArgumentException.class, new Executable() { + @Override + public void execute() throws Throwable { + JBoss7GelfLogHandler handler = new JBoss7GelfLogHandler(); + + handler.setGraylogHost(null); + handler.setGraylogPort(0); + } + }); } } diff --git a/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerUnitTests.java b/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerUnitTests.java index e95dde6a6..de71ed385 100644 --- a/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandlerUnitTests.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Mark Paluch diff --git a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerErrorsTests.java b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerErrorsTests.java index b5ffdd270..d9e710d6f 100644 --- a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerErrorsTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerErrorsTests.java @@ -11,23 +11,23 @@ import java.util.logging.Level; import java.util.logging.LogRecord; -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.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; import biz.paluch.logging.gelf.GelfMessageAssembler; import biz.paluch.logging.gelf.intern.GelfSenderConfiguration; import biz.paluch.logging.gelf.intern.GelfSenderFactory; import biz.paluch.logging.gelf.intern.GelfSenderProvider; +import external.MockitoExtension; /** * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GelfLogHandlerErrorsTests { public static final String THE_HOST = "the host"; @@ -44,7 +44,7 @@ public class GelfLogHandlerErrorsTests { private GelfLogHandler sut = new GelfLogHandler(); - @Before + @BeforeEach public void before() throws Exception { GelfSenderFactory.addGelfSenderProvider(senderProvider); @@ -53,7 +53,7 @@ public void before() throws Exception { } - @After + @AfterEach public void after() throws Exception { GelfSenderFactory.removeGelfSenderProvider(senderProvider); GelfSenderFactory.removeAllAddedSenderProviders(); diff --git a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerFilterTests.java b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerFilterTests.java index 8c97bf55e..221790e92 100644 --- a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerFilterTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerFilterTests.java @@ -6,9 +6,9 @@ import java.util.logging.Logger; import org.apache.log4j.MDC; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; @@ -18,7 +18,7 @@ */ public class GelfLogHandlerFilterTests { - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); @@ -27,7 +27,7 @@ public void before() throws Exception { MDC.remove("mdcField1"); } - @After + @AfterEach public void after() throws Exception { LogManager.getLogManager().reset(); diff --git a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerRedisIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerRedisIntegrationTests.java index de99d1dd7..39833434e 100644 --- a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerRedisIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerRedisIntegrationTests.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import java.util.Map; @@ -10,8 +11,9 @@ import java.util.logging.Logger; import org.apache.log4j.MDC; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.JsonUtil; @@ -30,7 +32,7 @@ public class GelfLogHandlerRedisIntegrationTests { private Jedis jedis; - @Before + @BeforeEach public void before() throws Exception { // enable the test with -Dtest.withRedis=true assumeTrue(Sockets.isOpen("localhost", 6479)); @@ -117,48 +119,76 @@ public void testRedisWithPortUri() throws Exception { gelfSender.close(); } - @Test(expected = IllegalArgumentException.class) + @Test public void uriWithoutHost() throws Exception { String uri = "redis:///#list"; - DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); + final DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); configuration.setHost(uri); - new RedisGelfSenderProvider().create(configuration); + + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + new RedisGelfSenderProvider().create(configuration); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void uriWithoutFragment() throws Exception { String uri = "redis://host/"; - DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); + final DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); configuration.setHost(uri); - new RedisGelfSenderProvider().create(configuration); + + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + new RedisGelfSenderProvider().create(configuration); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void uriWithoutFragment2() throws Exception { String uri = "redis://host"; - DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); + final DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); configuration.setHost(uri); - new RedisGelfSenderProvider().create(configuration); + + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + new RedisGelfSenderProvider().create(configuration); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void uriWithoutFragment3() throws Exception { String uri = "redis://host#"; - DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); + final DefaultGelfSenderConfiguration configuration = new DefaultGelfSenderConfiguration(); configuration.setHost(uri); - new RedisGelfSenderProvider().create(configuration); + + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + new RedisGelfSenderProvider().create(configuration); + } + }); } - @Test(timeout = 5000) + @Test public void testRedisNotAvailable() throws Exception { LogManager.getLogManager() diff --git a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerSystemPropertiesTests.java b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerSystemPropertiesTests.java index 7395cc2ff..47cf3fd12 100644 --- a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerSystemPropertiesTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerSystemPropertiesTests.java @@ -5,8 +5,8 @@ import java.util.logging.LogManager; import java.util.logging.Logger; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -24,7 +24,7 @@ public class GelfLogHandlerSystemPropertiesTests { public static final String PROPERTY2 = "otherproperty"; public static final String PROPERTY2_VALUE = "value of otherproperty"; - @Before + @BeforeEach public void before() throws Exception { System.clearProperty(PROPERTY1); diff --git a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerTests.java b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerTests.java index 5056f6207..5cf418a58 100644 --- a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerTests.java @@ -7,8 +7,8 @@ import java.util.logging.Logger; import org.apache.log4j.MDC; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -18,7 +18,7 @@ * @since 27.09.13 08:25 */ public class GelfLogHandlerTests { - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); diff --git a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerUnitTests.java b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerUnitTests.java index 807aedcbf..9da187927 100644 --- a/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/jul/GelfLogHandlerUnitTests.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import biz.paluch.logging.RuntimeContainer; diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/AbstractGelfLogAppenderTests.java b/src/test/java/biz/paluch/logging/gelf/log4j/AbstractGelfLogAppenderTests.java index e1e489915..2f8e5e0b9 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/AbstractGelfLogAppenderTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/AbstractGelfLogAppenderTests.java @@ -8,7 +8,7 @@ import org.apache.log4j.Logger; import org.apache.log4j.MDC; import org.apache.log4j.NDC; -import org.junit.Test; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.GelfUtil; diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLayoutTest.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLayoutTest.java index eee15a9b1..7ec6c78b0 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLayoutTest.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLayoutTest.java @@ -11,9 +11,9 @@ import org.apache.log4j.MDC; import org.apache.log4j.NDC; import org.apache.log4j.xml.DOMConfigurator; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.JsonUtil; import biz.paluch.logging.gelf.LogMessageField; @@ -25,12 +25,12 @@ public class GelfLayoutTest { private Logger logger; - @BeforeClass + @BeforeAll public static void beforeClass() { DOMConfigurator.configure(GelfLayoutTest.class.getResource("/log4j/log4j-gelf-layout.xml")); } - @Before + @BeforeEach public void before() { TestAppender.clearLoggedLines(); logger = Logger.getLogger(GelfLayoutTest.class); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderErrorsUnitTests.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderErrorsUnitTests.java index ef81608ce..2e780d3cd 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderErrorsUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderErrorsUnitTests.java @@ -10,23 +10,23 @@ import org.apache.log4j.spi.ErrorHandler; import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.xml.DOMConfigurator; -import org.junit.After; -import org.junit.Before; import org.junit.Ignore; -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.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; import biz.paluch.logging.gelf.GelfMessageAssembler; import biz.paluch.logging.gelf.intern.GelfSenderFactory; import biz.paluch.logging.gelf.intern.GelfSenderProvider; +import external.MockitoExtension; /** * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GelfLogAppenderErrorsUnitTests { public static final String THE_HOST = "the host"; @@ -45,7 +45,7 @@ public class GelfLogAppenderErrorsUnitTests { private GelfLogAppender sut = new GelfLogAppender(); - @Before + @BeforeEach public void before() throws Exception { GelfSenderFactory.addGelfSenderProvider(senderProvider); @@ -53,7 +53,7 @@ public void before() throws Exception { sut.setErrorHandler(errorHandler); } - @After + @AfterEach public void after() throws Exception { GelfSenderFactory.removeGelfSenderProvider(senderProvider); GelfSenderFactory.removeAllAddedSenderProviders(); @@ -84,7 +84,7 @@ public void testErrorOnSend() throws Exception { verify(errorHandler, atLeast(1)).error(anyString(), ArgumentMatchers. isNull(), anyInt()); } - @Test(timeout = 500) + @Test @Ignore("Flakey during to execution environment") public void gelfPortNotReachable() throws Exception { diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderNettyIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderNettyIntegrationTests.java index cd8fdaaa3..ff4a6ef6e 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderNettyIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderNettyIntegrationTests.java @@ -7,10 +7,10 @@ import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.xml.DOMConfigurator; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.code.tempusfugit.temporal.*; @@ -24,17 +24,17 @@ public class GelfLogAppenderNettyIntegrationTests { private static NettyLocalServer server = new NettyLocalServer(NioDatagramChannel.class); - @BeforeClass + @BeforeAll public static void setupClass() throws Exception { server.run(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { server.close(); } - @Before + @BeforeEach public void before() throws Exception { LogManager.getLoggerRepository().resetConfiguration(); DOMConfigurator.configure(getClass().getResource("/log4j/log4j-netty-warn.xml")); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesDynamicMdcTest.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesDynamicMdcTest.java index 3f29f7517..ee82c8018 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesDynamicMdcTest.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesDynamicMdcTest.java @@ -11,8 +11,8 @@ import org.apache.log4j.Logger; import org.apache.log4j.MDC; import org.apache.log4j.PropertyConfigurator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -33,7 +33,7 @@ public class GelfLogAppenderPropertiesDynamicMdcTest { public static final String SOME_FIELD = "someField"; public static final String SOME_OTHER_FIELD = "someOtherField"; - @Before + @BeforeEach public void before() throws Exception { LogManager.getLoggerRepository().resetConfiguration(); GelfTestSender.getMessages().clear(); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesIncludeFullMdcTest.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesIncludeFullMdcTest.java index 5f447acf5..17da12376 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesIncludeFullMdcTest.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesIncludeFullMdcTest.java @@ -11,8 +11,8 @@ import org.apache.log4j.Logger; import org.apache.log4j.MDC; import org.apache.log4j.PropertyConfigurator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -29,7 +29,7 @@ public class GelfLogAppenderPropertiesIncludeFullMdcTest { public static final String VALUE_1 = "value1"; public static final String VALUE_2 = "value2"; - @Before + @BeforeEach public void before() throws Exception { assumeTrue(Log4jUtil.isLog4jMDCAvailable()); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesTests.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesTests.java index 7f34061b1..aff94fbaa 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderPropertiesTests.java @@ -3,7 +3,7 @@ import org.apache.log4j.LogManager; import org.apache.log4j.MDC; import org.apache.log4j.PropertyConfigurator; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import biz.paluch.logging.gelf.GelfTestSender; @@ -13,7 +13,7 @@ */ public class GelfLogAppenderPropertiesTests extends AbstractGelfLogAppenderTests { - @Before + @BeforeEach public void before() throws Exception { LogManager.getLoggerRepository().resetConfiguration(); GelfTestSender.getMessages().clear(); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderSystemPropertiesTests.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderSystemPropertiesTests.java index b8fa7991c..3d68ef4ef 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderSystemPropertiesTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderSystemPropertiesTests.java @@ -5,8 +5,8 @@ import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.xml.DOMConfigurator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -24,7 +24,7 @@ public class GelfLogAppenderSystemPropertiesTests { public static final String PROPERTY2 = "otherproperty"; public static final String PROPERTY2_VALUE = "value of otherproperty"; - @Before + @BeforeEach public void before() throws Exception { System.clearProperty(PROPERTY1); System.clearProperty(PROPERTY2); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderUnitTests.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderUnitTests.java index c956e8b6b..74008a3d5 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderUnitTests.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import biz.paluch.logging.RuntimeContainer; diff --git a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderXmlTests.java b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderXmlTests.java index 9b835bbef..707e2c820 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderXmlTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j/GelfLogAppenderXmlTests.java @@ -3,7 +3,7 @@ import org.apache.log4j.LogManager; import org.apache.log4j.MDC; import org.apache.log4j.xml.DOMConfigurator; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import biz.paluch.logging.gelf.GelfTestSender; @@ -13,7 +13,7 @@ */ public class GelfLogAppenderXmlTests extends AbstractGelfLogAppenderTests { - @Before + @BeforeEach public void before() throws Exception { LogManager.getLoggerRepository().resetConfiguration(); GelfTestSender.getMessages().clear(); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderAsyncNettyTcpIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderAsyncNettyTcpIntegrationTests.java index 8cfcfa53d..13a1e7f65 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderAsyncNettyTcpIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderAsyncNettyTcpIntegrationTests.java @@ -11,10 +11,10 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.code.tempusfugit.temporal.Condition; import com.google.code.tempusfugit.temporal.Duration; @@ -38,7 +38,7 @@ public class GelfLogAppenderAsyncNettyTcpIntegrationTests { private static LoggerContext loggerContext; private static NettyLocalServer server = new NettyLocalServer(NioServerSocketChannel.class); - @BeforeClass + @BeforeAll public static void setupClass() throws Exception { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-async-netty-tcp.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); @@ -46,14 +46,14 @@ public static void setupClass() throws Exception { server.run(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); server.close(); } - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); ThreadContext.clearAll(); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderDynamicMdcTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderDynamicMdcTests.java index 5643deebc..74172a5ef 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderDynamicMdcTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderDynamicMdcTests.java @@ -9,10 +9,10 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.JsonUtil; @@ -34,20 +34,20 @@ public class GelfLogAppenderDynamicMdcTests { private static LoggerContext loggerContext; - @BeforeClass + @BeforeAll public static void setupClass() { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-dynamic-mdc.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); loggerContext.reconfigure(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); } - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); ThreadContext.clearAll(); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderEmptyFacilityNettyUdpIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderEmptyFacilityNettyUdpIntegrationTests.java index ce1df6c49..d937e0f06 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderEmptyFacilityNettyUdpIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderEmptyFacilityNettyUdpIntegrationTests.java @@ -1,6 +1,7 @@ package biz.paluch.logging.gelf.log4j2; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import java.util.Map; @@ -11,10 +12,11 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import com.google.code.tempusfugit.temporal.Condition; import com.google.code.tempusfugit.temporal.Duration; @@ -36,7 +38,7 @@ public class GelfLogAppenderEmptyFacilityNettyUdpIntegrationTests { private static LoggerContext loggerContext; private static NettyLocalServer server = new NettyLocalServer(NioDatagramChannel.class); - @BeforeClass + @BeforeAll public static void setupClass() throws Exception { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-empty-facility-netty-udp.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); @@ -44,14 +46,14 @@ public static void setupClass() throws Exception { server.run(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); server.close(); } - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); ThreadContext.clearAll(); @@ -77,14 +79,20 @@ public void testSimpleInfo() throws Exception { } - @Test(expected = TimeoutException.class) + @Test public void testEmptyMessage() throws Exception { Logger logger = loggerContext.getLogger(getClass().getName()); logger.info(""); - waitForGelf(); + assertThrows(TimeoutException.class, new Executable() { + + @Override + public void execute() throws Throwable { + waitForGelf(); + } + }); } diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderIncludeFullMdcTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderIncludeFullMdcTests.java index 19515240b..0257c648f 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderIncludeFullMdcTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderIncludeFullMdcTests.java @@ -7,10 +7,10 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -28,20 +28,20 @@ public class GelfLogAppenderIncludeFullMdcTests { private static LoggerContext loggerContext; - @BeforeClass + @BeforeAll public static void setupClass() { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-include-full-mdc.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); loggerContext.reconfigure(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); } - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); ThreadContext.clearAll(); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderMinimalTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderMinimalTests.java index 142c40294..907bae277 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderMinimalTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderMinimalTests.java @@ -8,10 +8,10 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.LogMessageField; @@ -27,20 +27,20 @@ public class GelfLogAppenderMinimalTests { private static LoggerContext loggerContext; - @BeforeClass + @BeforeAll public static void beforeClass() { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-minimal.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); loggerContext.reconfigure(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); } - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); ThreadContext.clearAll(); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyTcpIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyTcpIntegrationTests.java index 325f9545f..5c5745043 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyTcpIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyTcpIntegrationTests.java @@ -1,6 +1,7 @@ package biz.paluch.logging.gelf.log4j2; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import java.util.Map; @@ -11,10 +12,11 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import com.google.code.tempusfugit.temporal.Condition; import com.google.code.tempusfugit.temporal.Duration; @@ -38,7 +40,7 @@ public class GelfLogAppenderNettyTcpIntegrationTests { private static LoggerContext loggerContext; private static NettyLocalServer server = new NettyLocalServer(NioServerSocketChannel.class); - @BeforeClass + @BeforeAll public static void setupClass() throws Exception { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-netty-tcp.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); @@ -46,14 +48,14 @@ public static void setupClass() throws Exception { server.run(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); server.close(); } - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); ThreadContext.clearAll(); @@ -97,14 +99,20 @@ public void testSimpleInfo() throws Exception { } - @Test(expected = TimeoutException.class) + @Test public void testEmptyMessage() throws Exception { Logger logger = loggerContext.getLogger(getClass().getName()); logger.info(""); - waitForGelf(); + assertThrows(TimeoutException.class, new Executable() { + + @Override + public void execute() throws Throwable { + waitForGelf(); + } + }); } diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyUdpIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyUdpIntegrationTests.java index 156b1c60d..fd8f2be6a 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyUdpIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderNettyUdpIntegrationTests.java @@ -1,6 +1,7 @@ package biz.paluch.logging.gelf.log4j2; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import java.util.Map; @@ -11,10 +12,11 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import com.google.code.tempusfugit.temporal.Condition; import com.google.code.tempusfugit.temporal.Duration; @@ -38,7 +40,7 @@ public class GelfLogAppenderNettyUdpIntegrationTests { private static LoggerContext loggerContext; private static NettyLocalServer server = new NettyLocalServer(NioDatagramChannel.class); - @BeforeClass + @BeforeAll public static void setupClass() throws Exception { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-netty-udp.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); @@ -46,14 +48,14 @@ public static void setupClass() throws Exception { server.run(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); server.close(); } - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); ThreadContext.clearAll(); @@ -97,14 +99,20 @@ public void testSimpleInfo() throws Exception { } - @Test(expected = TimeoutException.class) + @Test public void testEmptyMessage() throws Exception { Logger logger = loggerContext.getLogger(getClass().getName()); logger.info(""); - waitForGelf(); + assertThrows(TimeoutException.class, new Executable() { + + @Override + public void execute() throws Throwable { + waitForGelf(); + } + }); } diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderPropagateExceptionsTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderPropagateExceptionsTests.java index 97f994235..d7653daba 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderPropagateExceptionsTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderPropagateExceptionsTests.java @@ -1,15 +1,17 @@ package biz.paluch.logging.gelf.log4j2; import static org.fest.assertions.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.appender.AppenderLoggingException; import org.apache.logging.log4j.junit.InitialLoggerContext; import org.apache.logging.log4j.test.appender.ListAppender; -import org.junit.Before; import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; /** * @author Mark Paluch @@ -22,16 +24,22 @@ public class GelfLogAppenderPropagateExceptionsTests { @ClassRule public static final InitialLoggerContext loggerContext = new InitialLoggerContext("log4j2/log4j2-propagate-exceptions.xml"); - @Before + @BeforeEach public void before() throws Exception { ThreadContext.clearAll(); } - @Test(expected = AppenderLoggingException.class) + @Test public void shouldPropagateException() throws Exception { - Logger logger = loggerContext.getLogger("biz.exception"); - logger.info(LOG_MESSAGE); + assertThrows(AppenderLoggingException.class, new Executable() { + + @Override + public void execute() throws Throwable { + Logger logger = loggerContext.getLogger("biz.exception"); + logger.info(LOG_MESSAGE); + } + }); } @Test diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderSystemPropertiesTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderSystemPropertiesTests.java index e63e8bb12..253b843cd 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderSystemPropertiesTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderSystemPropertiesTests.java @@ -7,10 +7,10 @@ import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -28,20 +28,20 @@ public class GelfLogAppenderSystemPropertiesTests { public static final String PROPERTY2_VALUE = "value of otherproperty"; private static LoggerContext loggerContext; - @BeforeClass + @BeforeAll public static void setupClass() { System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2/log4j2-systemproperties.xml"); loggerContext = (LoggerContext) LogManager.getContext(false); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); } - @Before + @BeforeEach public void before() throws Exception { System.clearProperty(PROPERTY1); System.clearProperty(PROPERTY2); diff --git a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderTests.java b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderTests.java index bab6cc3d6..6105eff5b 100644 --- a/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderTests.java +++ b/src/test/java/biz/paluch/logging/gelf/log4j2/GelfLogAppenderTests.java @@ -7,9 +7,9 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.RuntimeContainer; import biz.paluch.logging.gelf.GelfTestSender; @@ -33,13 +33,13 @@ protected static void reconfigure(String configXml) { loggerContext.reconfigure(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); loggerContext.reconfigure(); } - @Before + @BeforeEach public void before() throws Exception { reconfigure(CONFIG_XML); GelfTestSender.getMessages().clear(); diff --git a/src/test/java/biz/paluch/logging/gelf/logback/AbstractGelfLogAppenderTests.java b/src/test/java/biz/paluch/logging/gelf/logback/AbstractGelfLogAppenderTests.java index 9d8ba7dbb..bb04cb4e7 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/AbstractGelfLogAppenderTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/AbstractGelfLogAppenderTests.java @@ -4,7 +4,7 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.MDC; import org.slf4j.MarkerFactory; diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicHostnameTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicHostnameTests.java index 82815895a..dfe788da3 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicHostnameTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicHostnameTests.java @@ -6,8 +6,8 @@ import java.net.URL; import org.hamcrest.core.StringContains; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.MDC; import biz.paluch.logging.gelf.GelfTestSender; @@ -25,7 +25,7 @@ public class GelfLogbackAppenderDynamicHostnameTests { public static final String LOG_MESSAGE = "foo bar test log message"; LoggerContext lc = null; - @Before + @BeforeEach public void before() throws Exception { lc = new LoggerContext(); JoranConfigurator configurator = new JoranConfigurator(); diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicMdcTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicMdcTests.java index 16d8d20af..a6b26b343 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicMdcTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderDynamicMdcTests.java @@ -5,8 +5,8 @@ import java.net.URL; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.MDC; import biz.paluch.logging.gelf.GelfTestSender; @@ -33,7 +33,7 @@ public class GelfLogbackAppenderDynamicMdcTests { public static final String SOME_OTHER_FIELD = "someOtherField"; LoggerContext lc = null; - @Before + @BeforeEach public void before() throws Exception { lc = new LoggerContext(); JoranConfigurator configurator = new JoranConfigurator(); diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderErrorsUnitTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderErrorsUnitTests.java index 07df7a37d..c0f69649d 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderErrorsUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderErrorsUnitTests.java @@ -5,15 +5,12 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -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 biz.paluch.logging.gelf.intern.GelfSender; import biz.paluch.logging.gelf.intern.GelfSenderFactory; import biz.paluch.logging.gelf.intern.GelfSenderProvider; import ch.qos.logback.classic.Level; @@ -22,8 +19,9 @@ import ch.qos.logback.core.Context; import ch.qos.logback.core.status.Status; import ch.qos.logback.core.status.StatusManager; +import external.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GelfLogbackAppenderErrorsUnitTests { public static final String THE_HOST = "the host"; @@ -31,15 +29,9 @@ public class GelfLogbackAppenderErrorsUnitTests { public static final LoggingEvent LOGGING_EVENT = new LoggingEvent("my.class", new LoggerContext().getLogger("my.class"), Level.INFO, "message", null, null); - @Mock - private GelfSender sender; - @Mock private GelfSenderProvider senderProvider; - @Mock - private GelfMessageAssembler assembler; - @Mock private Context context; @@ -48,7 +40,7 @@ public class GelfLogbackAppenderErrorsUnitTests { private GelfLogbackAppender sut = new GelfLogbackAppender(); - @Before + @BeforeEach public void before() throws Exception { GelfSenderFactory.addGelfSenderProvider(senderProvider); @@ -59,7 +51,7 @@ public void before() throws Exception { } - @After + @AfterEach public void after() throws Exception { GelfSenderFactory.removeGelfSenderProvider(senderProvider); GelfSenderFactory.removeAllAddedSenderProviders(); diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHTTPIntegrationTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHTTPIntegrationTests.java index 450adfae0..93345b1ba 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHTTPIntegrationTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHTTPIntegrationTests.java @@ -6,9 +6,9 @@ import java.util.List; import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.MDC; import biz.paluch.logging.gelf.netty.NettyLocalHTTPServer; @@ -25,7 +25,7 @@ public class GelfLogbackAppenderHTTPIntegrationTests { LoggerContext lc = null; - @Before + @BeforeEach public void before() throws Exception { lc = new LoggerContext(); JoranConfigurator configurator = new JoranConfigurator(); @@ -41,7 +41,7 @@ public void before() throws Exception { MDC.remove("mdcField1"); } - @After + @AfterEach public void after() throws Exception { server.close(); } diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHostnameTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHostnameTests.java index 1c49b3f14..19c1ab607 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHostnameTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderHostnameTests.java @@ -6,8 +6,8 @@ import java.net.URL; import org.hamcrest.core.StringContains; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.MDC; import biz.paluch.logging.gelf.GelfTestSender; @@ -25,7 +25,7 @@ public class GelfLogbackAppenderHostnameTests { public static final String LOG_MESSAGE = "foo bar test log message"; LoggerContext lc = null; - @Before + @BeforeEach public void before() throws Exception { lc = new LoggerContext(); JoranConfigurator configurator = new JoranConfigurator(); diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderSystemPropertiesTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderSystemPropertiesTests.java index 05bb92601..ce445e1a0 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderSystemPropertiesTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderSystemPropertiesTests.java @@ -4,8 +4,8 @@ import java.net.URL; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -25,7 +25,7 @@ public class GelfLogbackAppenderSystemPropertiesTests { private LoggerContext lc = null; - @Before + @BeforeEach public void before() throws Exception { System.clearProperty(PROPERTY1); diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderTests.java index 469e997c2..795923b0f 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderTests.java @@ -2,7 +2,7 @@ import java.net.URL; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.slf4j.MDC; import biz.paluch.logging.gelf.GelfTestSender; @@ -15,7 +15,7 @@ */ public class GelfLogbackAppenderTests extends AbstractGelfLogAppenderTests { - @Before + @BeforeEach public void before() throws Exception { lc = new LoggerContext(); JoranConfigurator configurator = new JoranConfigurator(); diff --git a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderUnitTests.java b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderUnitTests.java index 450ea391d..40972e3f0 100644 --- a/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/logback/GelfLogbackAppenderUnitTests.java @@ -1,8 +1,10 @@ package biz.paluch.logging.gelf.logback; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import biz.paluch.logging.RuntimeContainer; @@ -48,24 +50,42 @@ public void testSameFieldsGelfLogbackAppender() { assertThat(sut.isMdcProfiling()).isTrue(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidPort() throws Exception { - GelfLogbackAppender sut = new GelfLogbackAppender(); - sut.setPort(-1); + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + GelfLogbackAppender sut = new GelfLogbackAppender(); + sut.setPort(-1); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidMaximumMessageSize() throws Exception { - GelfLogbackAppender sut = new GelfLogbackAppender(); - sut.setMaximumMessageSize(-1); + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + GelfLogbackAppender sut = new GelfLogbackAppender(); + sut.setMaximumMessageSize(-1); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidVersion() throws Exception { - GelfLogbackAppender sut = new GelfLogbackAppender(); - sut.setVersion("7"); + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + GelfLogbackAppender sut = new GelfLogbackAppender(); + sut.setVersion("7"); + } + }); } } diff --git a/src/test/java/biz/paluch/logging/gelf/standalone/DatenpumpeImplUnitTests.java b/src/test/java/biz/paluch/logging/gelf/standalone/DatenpumpeImplUnitTests.java index 2024daac1..845d00cf5 100644 --- a/src/test/java/biz/paluch/logging/gelf/standalone/DatenpumpeImplUnitTests.java +++ b/src/test/java/biz/paluch/logging/gelf/standalone/DatenpumpeImplUnitTests.java @@ -2,8 +2,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -13,7 +13,7 @@ */ public class DatenpumpeImplUnitTests { - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); } diff --git a/src/test/java/biz/paluch/logging/gelf/standalone/StandaloneGelfSenderTests.java b/src/test/java/biz/paluch/logging/gelf/standalone/StandaloneGelfSenderTests.java index 22ed080a4..e2918a12e 100644 --- a/src/test/java/biz/paluch/logging/gelf/standalone/StandaloneGelfSenderTests.java +++ b/src/test/java/biz/paluch/logging/gelf/standalone/StandaloneGelfSenderTests.java @@ -3,8 +3,8 @@ import static biz.paluch.logging.gelf.GelfMessageBuilder.newInstance; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.intern.GelfMessage; @@ -16,7 +16,7 @@ */ public class StandaloneGelfSenderTests { - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); } diff --git a/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogFormatterTests.java b/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogFormatterTests.java index ca87de6f3..f637b1878 100644 --- a/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogFormatterTests.java +++ b/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogFormatterTests.java @@ -1,6 +1,7 @@ package biz.paluch.logging.gelf.wildfly; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.StringWriter; import java.util.Map; @@ -11,8 +12,9 @@ import org.jboss.logmanager.MDC; import org.jboss.logmanager.NDC; import org.jboss.logmanager.handlers.WriterHandler; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.JsonUtil; @@ -28,7 +30,7 @@ public class WildFlyGelfLogFormatterTests { private WriterHandler handler = new WriterHandler(); private StringWriter stringWriter = new StringWriter(); - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); LogManager.getLogManager().reset(); @@ -116,18 +118,30 @@ public void testSimpleWithStringFormatSubstitution() throws Exception { } - @Test(expected = IllegalArgumentException.class) + @Test public void testUnknownField() throws Exception { - WildFlyJsonFormatter formatter = new WildFlyJsonFormatter(); - formatter.setFields("dummy"); + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + WildFlyJsonFormatter formatter = new WildFlyJsonFormatter(); + formatter.setFields("dummy"); + } + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNotSupportedField() throws Exception { - WildFlyJsonFormatter formatter = new WildFlyJsonFormatter(); - formatter.setFields("Marker"); + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + WildFlyJsonFormatter formatter = new WildFlyJsonFormatter(); + formatter.setFields("Marker"); + } + }); } @Test diff --git a/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerDynamicMdcTests.java b/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerDynamicMdcTests.java index c153100e3..9c64fb939 100644 --- a/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerDynamicMdcTests.java +++ b/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerDynamicMdcTests.java @@ -8,8 +8,8 @@ import java.util.logging.Logger; import org.jboss.logmanager.MDC; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.JsonUtil; @@ -31,7 +31,7 @@ public class WildFlyGelfLogHandlerDynamicMdcTests { public static final String VALUE_3 = "value3"; public static final String MDC_MY_MDC = "myMdc"; - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); LogManager.getLogManager().reset(); diff --git a/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerTests.java b/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerTests.java index ced4541b6..e2e6278bf 100644 --- a/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerTests.java +++ b/src/test/java/biz/paluch/logging/gelf/wildfly/WildFlyGelfLogHandlerTests.java @@ -2,6 +2,7 @@ import static biz.paluch.logging.gelf.wildfly.WildFlyLogTestUtil.getWildFlyGelfLogHandler; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.logging.Level; import java.util.logging.LogManager; @@ -9,8 +10,9 @@ import org.jboss.logmanager.MDC; import org.jboss.logmanager.NDC; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import biz.paluch.logging.gelf.GelfTestSender; import biz.paluch.logging.gelf.LogMessageField; @@ -26,7 +28,7 @@ public class WildFlyGelfLogHandlerTests { public static final String LOG_MESSAGE = "foo bar test log message"; public static final String EXPECTED_LOG_MESSAGE = LOG_MESSAGE; - @Before + @BeforeEach public void before() throws Exception { GelfTestSender.getMessages().clear(); LogManager.getLogManager().reset(); @@ -196,12 +198,19 @@ public void testFields() throws Exception { } - @Test(expected = IllegalArgumentException.class) + @Test public void testWrongConfig() throws Exception { - JBoss7GelfLogHandler handler = new JBoss7GelfLogHandler(); - handler.setGraylogHost(null); - handler.setGraylogPort(0); + assertThrows(IllegalArgumentException.class, new Executable() { + + @Override + public void execute() throws Throwable { + JBoss7GelfLogHandler handler = new JBoss7GelfLogHandler(); + + handler.setGraylogHost(null); + handler.setGraylogPort(0); + } + }); } } diff --git a/src/test/java/external/MockitoExtension.java b/src/test/java/external/MockitoExtension.java new file mode 100644 index 000000000..1670d73a0 --- /dev/null +++ b/src/test/java/external/MockitoExtension.java @@ -0,0 +1,73 @@ +package external; + +import static org.mockito.Mockito.mock; + +import java.lang.reflect.Parameter; +import java.util.function.Function; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ExtensionContext.Namespace; +import org.junit.jupiter.api.extension.ExtensionContext.Store; +import org.junit.jupiter.api.extension.ParameterContext; +import org.junit.jupiter.api.extension.ParameterResolver; +import org.junit.jupiter.api.extension.TestInstancePostProcessor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * {@code MockitoExtension} showcases the {@link TestInstancePostProcessor} and {@link ParameterResolver} extension APIs of + * JUnit 5 by providing dependency injection support at the field level and at the method parameter level via Mockito 2.x's + * {@link Mock @Mock} annotation. + * + * @since 5.0 + */ +public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver { + + @Override + public void postProcessTestInstance(Object testInstance, ExtensionContext context) { + MockitoAnnotations.initMocks(testInstance); + } + + @Override + public boolean supports(ParameterContext parameterContext, ExtensionContext extensionContext) { + return parameterContext.getParameter().isAnnotationPresent(Mock.class); + } + + @Override + public Object resolve(ParameterContext parameterContext, ExtensionContext extensionContext) { + return getMock(parameterContext.getParameter(), extensionContext); + } + + private Object getMock(Parameter parameter, ExtensionContext extensionContext) { + final Class mockType = parameter.getType(); + final Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); + final String mockName = getMockName(parameter); + + if (mockName != null) { + return mocks.getOrComputeIfAbsent(mockName, new Function() { + @Override + public Object apply(String s) { + return mock(mockType, mockName); + } + }); + } else { + return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), new Function() { + @Override + public Object apply(String s) { + return mock(mockType, mockName); + } + }); + } + } + + private String getMockName(final Parameter parameter) { + String explicitMockName = parameter.getAnnotation(Mock.class).name().trim(); + if (!explicitMockName.isEmpty()) { + return explicitMockName; + } else if (parameter.isNamePresent()) { + return parameter.getName(); + } + return null; + } + +} \ No newline at end of file