You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2020/08/29 19:43:48 UTC
[logging-log4j2] 01/02: [LOG4J2-2653] Migrate lookup and net tests
to JUnit 5
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit f8c68d1cfb442632530f5e13b9a15360b51c678d
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sun Aug 23 19:43:13 2020 -0500
[LOG4J2-2653] Migrate lookup and net tests to JUnit 5
Backported from 3.x.
Signed-off-by: Matt Sicker <bo...@gmail.com>
---
log4j-core/pom.xml | 5 +-
.../logging/log4j/core/lookup/CaseLookupTest.java | 12 +----
.../log4j/core/lookup/ContextMapLookupTest.java | 36 +++++--------
.../logging/log4j/core/lookup/DateLookupTest.java | 11 ++--
.../log4j/core/lookup/EnvironmentLookupTest.java | 8 +--
.../logging/log4j/core/lookup/EventLookupTest.java | 7 ++-
.../logging/log4j/core/lookup/Log4jLookupTest.java | 28 +++++-----
.../core/lookup/Log4jLookupWithSpacesTest.java | 29 +++++------
.../lookup/MainInputArgumentsJmxLookupTest.java | 14 ++---
.../logging/log4j/core/lookup/MainLookupTest.java | 30 +++++------
.../logging/log4j/core/lookup/MapLookupTest.java | 26 +++++-----
.../log4j/core/lookup/MarkerLookupConfigTest.java | 45 ++++++++--------
.../log4j/core/lookup/MarkerLookupTest.java | 7 ++-
.../core/lookup/ResourceBundleLookupTest.java | 17 +++---
.../log4j/core/lookup/StrSubstitutorTest.java | 15 +++---
.../core/lookup/StructuredDataLookupTest.java | 7 +--
.../core/lookup/SystemPropertiesLookupTest.java | 15 +++---
.../message/ExtendedThreadInformationTest.java | 6 +--
.../logging/log4j/core/net/PriorityTest.java | 9 ++--
.../log4j/core/net/SocketMessageLossTest.java | 24 ++++-----
.../log4j/core/net/SocketReconnectTest.java | 28 +++++-----
.../apache/logging/log4j/core/net/SocketTest.java | 37 ++++---------
.../net/ssl/EnvironmentPasswordProviderTest.java | 8 +--
.../core/net/ssl/FilePasswordProviderTest.java | 13 ++---
.../core/net/ssl/KeyStoreConfigurationTest.java | 60 ++++++++++++----------
.../core/net/ssl/MemoryPasswordProviderTest.java | 6 +--
.../log4j/core/net/ssl/SslConfigurationTest.java | 41 ++++++++-------
.../log4j/core/net/ssl/StoreConfigurationTest.java | 16 +++---
.../core/net/ssl/TrustStoreConfigurationTest.java | 54 ++++++++++---------
pom.xml | 6 +++
30 files changed, 282 insertions(+), 338 deletions(-)
diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index b2931ba..91333f3 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -212,7 +212,10 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
- <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<!-- Embedded JDBC drivers for database appender tests -->
<dependency>
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java
index ae7d5ac..16d5f37 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/CaseLookupTest.java
@@ -16,18 +16,10 @@
*/
package org.apache.logging.log4j.core.lookup;
-import java.util.Calendar;
+import org.junit.jupiter.api.Test;
-import org.apache.logging.log4j.core.AbstractLogEvent;
-import org.apache.logging.log4j.core.LogEvent;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-/**
- *
- */
public class CaseLookupTest {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java
index b80491e..f35c8b1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ContextMapLookupTest.java
@@ -31,9 +31,6 @@ import org.junit.runners.model.Statement;
import static org.junit.Assert.*;
-/**
- *
- */
public class ContextMapLookupTest {
private static final String TESTKEY = "TestKey";
@@ -42,27 +39,22 @@ public class ContextMapLookupTest {
private final LoggerContextRule context = new LoggerContextRule("ContextMapLookupTest.xml");
@Rule
- public RuleChain chain = RuleChain.outerRule(new TestRule() {
+ public RuleChain chain = RuleChain.outerRule((base, description) -> new Statement() {
@Override
- public Statement apply(final Statement base, final Description description) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- final File logFile = new File("target",
- description.getClassName() + '.' + description.getMethodName() + ".log");
- ThreadContext.put("testClassName", description.getClassName());
- ThreadContext.put("testMethodName", description.getMethodName());
- try {
- base.evaluate();
- } finally {
- ThreadContext.remove("testClassName");
- ThreadContext.remove("testMethodName");
- if (logFile.exists()) {
- logFile.deleteOnExit();
- }
- }
+ public void evaluate() throws Throwable {
+ final File logFile = new File("target",
+ description.getClassName() + '.' + description.getMethodName() + ".log");
+ ThreadContext.put("testClassName", description.getClassName());
+ ThreadContext.put("testMethodName", description.getMethodName());
+ try {
+ base.evaluate();
+ } finally {
+ ThreadContext.remove("testClassName");
+ ThreadContext.remove("testMethodName");
+ if (logFile.exists()) {
+ logFile.deleteOnExit();
}
- };
+ }
}
}).around(context);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java
index 09794e2..a90a6e7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/DateLookupTest.java
@@ -20,13 +20,10 @@ import java.util.Calendar;
import org.apache.logging.log4j.core.AbstractLogEvent;
import org.apache.logging.log4j.core.LogEvent;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
public class DateLookupTest {
@@ -39,7 +36,7 @@ public class DateLookupTest {
assertEquals("12/30/2011", value);
}
- private class MyLogEvent extends AbstractLogEvent {
+ private static class MyLogEvent extends AbstractLogEvent {
/**
* Generated serial version ID.
*/
@@ -48,7 +45,7 @@ public class DateLookupTest {
@Override
public long getTimeMillis() {
final Calendar cal = Calendar.getInstance();
- cal.set(2011, 11, 30, 10, 56, 35);
+ cal.set(2011, Calendar.DECEMBER, 30, 10, 56, 35);
return cal.getTimeInMillis();
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java
index 5cae1b1..7636a1f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EnvironmentLookupTest.java
@@ -16,16 +16,12 @@
*/
package org.apache.logging.log4j.core.lookup;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
public class EnvironmentLookupTest {
-
@Test
public void testLookup() {
final StrLookup lookup = new EnvironmentLookup();
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java
index 96f6027..25006d2 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/EventLookupTest.java
@@ -22,10 +22,9 @@ import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link MarkerLookup}.
@@ -114,4 +113,4 @@ public class EventLookupTest {
assertEquals("Main", value);
}
-}
\ No newline at end of file
+}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java
index 0db5db0..0ee103d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupTest.java
@@ -15,30 +15,26 @@
*/
package org.apache.logging.log4j.core.lookup;
-import java.io.File;
-import java.net.URISyntaxException;
-
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationAware;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.impl.ContextAnchor;
-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.runners.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_LOCATION;
import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_PARENT_LOCATION;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.BDDMockito.given;
-/**
- *
- */
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class Log4jLookupTest {
private final static File EXPECT = new File(System.getProperty("user.home"), "/a/b/c/d/e/log4j2.xml");
@@ -50,14 +46,14 @@ public class Log4jLookupTest {
@Mock
private ConfigurationSource configSrc;
- @Before
- public void setup() throws URISyntaxException {
+ @BeforeEach
+ public void setup() {
ContextAnchor.THREAD_CONTEXT.set(mockCtx);
given(config.getConfigurationSource()).willReturn(configSrc);
given(configSrc.getFile()).willReturn(EXPECT);
}
- @After
+ @AfterEach
public void cleanup() {
ContextAnchor.THREAD_CONTEXT.set(null);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java
index e5ecb49..94ff966 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/Log4jLookupWithSpacesTest.java
@@ -15,31 +15,26 @@
*/
package org.apache.logging.log4j.core.lookup;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationAware;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.impl.ContextAnchor;
-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.runners.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_LOCATION;
import static org.apache.logging.log4j.core.lookup.Log4jLookup.KEY_CONFIG_PARENT_LOCATION;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.BDDMockito.given;
-/**
- *
- */
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class Log4jLookupWithSpacesTest {
private final static File EXPECT = new File(System.getProperty("user.home"), "/a a/b b/c c/d d/e e/log4j2 file.xml");
@@ -50,14 +45,14 @@ public class Log4jLookupWithSpacesTest {
@Mock
private ConfigurationSource configSrc;
- @Before
- public void setup() throws URISyntaxException, MalformedURLException {
+ @BeforeEach
+ public void setup() {
ContextAnchor.THREAD_CONTEXT.set(mockCtx);
given(config.getConfigurationSource()).willReturn(configSrc);
given(configSrc.getFile()).willReturn(EXPECT);
}
- @After
+ @AfterEach
public void cleanup() {
ContextAnchor.THREAD_CONTEXT.set(null);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java
index 22583d3..a3106a1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java
@@ -16,9 +16,9 @@
*/
package org.apache.logging.log4j.core.lookup;
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link JmxRuntimeInputArgumentsLookup} from the command line, not a JUnit test.
@@ -36,15 +36,15 @@ public class MainInputArgumentsJmxLookupTest {
@Test
public void testMap() {
final JmxRuntimeInputArgumentsLookup lookup = JmxRuntimeInputArgumentsLookup.JMX_SINGLETON;
- assertEquals(null, lookup.lookup(null));
- assertEquals(null, lookup.lookup("X"));
- assertEquals(null, lookup.lookup("foo.txt"));
+ assertNull(lookup.lookup(null));
+ assertNull(lookup.lookup("X"));
+ assertNull(lookup.lookup("foo.txt"));
}
public void callFromMain() {
final JmxRuntimeInputArgumentsLookup lookup = JmxRuntimeInputArgumentsLookup.JMX_SINGLETON;
- assertEquals(null, lookup.lookup(null));
- assertEquals(null, lookup.lookup("X"));
+ assertNull(lookup.lookup(null));
+ assertNull(lookup.lookup("X"));
// Eclipse adds -Dfile.encoding=Cp1252
// assertEquals("--file", lookup.lookup("0"));
// assertEquals("foo.txt", lookup.lookup("1"));
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
index b019c2a..9c45774 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MainLookupTest.java
@@ -16,12 +16,12 @@
*/
package org.apache.logging.log4j.core.lookup;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests MainLookup.
@@ -39,18 +39,18 @@ public class MainLookupTest {
StrSubstitutor substitutor = new StrSubstitutor(lookup);
String replacedValue = substitutor.replace(null, str);
String[] values = replacedValue.split(" ");
- assertEquals("Item 0 is incorrect ", "value", values[0]);
- assertEquals("Item 1 is incorrect ", "1", values[1]);
- assertEquals("Item 2 is incorrect", "--file", values[2]);
- assertEquals("Item 3 is incorrect", "foo.txt", values[3]);
- assertEquals("Item 4 is incorrect", "--verbose", values[4]);
- assertEquals("Item 5 is incorrect", "-x", values[5]);
- assertEquals("Iten 6 is incorrect", "bar", values[6]);
- assertEquals("Item 7 is incorrect", "foo.txt", values[7]);
- assertEquals("Item 8 is incorrect", "--verbose", values[8]);
- assertEquals("Item 9 is incorrect", "-x", values[9]);
- assertEquals("Item 10 is incorrect", "bar", values[10]);
- assertEquals("Item 11 is incorrect", "default_bar_value", values[11]);
- assertEquals("Item 12 is incorrect", "true", values[12]);
+ assertEquals("value", values[0], "Item 0 is incorrect ");
+ assertEquals("1", values[1], "Item 1 is incorrect ");
+ assertEquals("--file", values[2], "Item 2 is incorrect");
+ assertEquals("foo.txt", values[3], "Item 3 is incorrect");
+ assertEquals("--verbose", values[4], "Item 4 is incorrect");
+ assertEquals("-x", values[5], "Item 5 is incorrect");
+ assertEquals("bar", values[6], "Iten 6 is incorrect");
+ assertEquals("foo.txt", values[7], "Item 7 is incorrect");
+ assertEquals("--verbose", values[8], "Item 8 is incorrect");
+ assertEquals("-x", values[9], "Item 9 is incorrect");
+ assertEquals("bar", values[10], "Item 10 is incorrect");
+ assertEquals("default_bar_value", values[11], "Item 11 is incorrect");
+ assertEquals("true", values[12], "Item 12 is incorrect");
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
index 4298d98..2804e97 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
@@ -16,15 +16,15 @@
*/
package org.apache.logging.log4j.core.lookup;
-import static org.junit.Assert.assertEquals;
-
import java.util.HashMap;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.MapMessage;
import org.apache.logging.log4j.message.StringMapMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link MapLookup}.
@@ -34,8 +34,8 @@ public class MapLookupTest {
@Test
public void testEmptyMap() {
final MapLookup lookup = new MapLookup(new HashMap<String, String>());
- assertEquals(null, lookup.lookup(null));
- assertEquals(null, lookup.lookup("X"));
+ assertNull(lookup.lookup(null));
+ assertNull(lookup.lookup("X"));
}
@Test
@@ -43,29 +43,27 @@ public class MapLookupTest {
final HashMap<String, String> map = new HashMap<>();
map.put("A", "B");
final MapLookup lookup = new MapLookup(map);
- assertEquals(null, lookup.lookup(null));
+ assertNull(lookup.lookup(null));
assertEquals("B", lookup.lookup("A"));
}
@Test
public void testNullMap() {
final MapLookup lookup = new MapLookup();
- assertEquals(null, lookup.lookup(null));
- assertEquals(null, lookup.lookup("X"));
+ assertNull(lookup.lookup(null));
+ assertNull(lookup.lookup("X"));
}
@Test
public void testMainMap() {
- MapLookup.setMainArguments(new String[] {
- "--file",
- "foo.txt" });
+ MainMapLookup.setMainArguments("--file", "foo.txt");
final MapLookup lookup = MainMapLookup.MAIN_SINGLETON;
- assertEquals(null, lookup.lookup(null));
- assertEquals(null, lookup.lookup("X"));
+ assertNull(lookup.lookup(null));
+ assertNull(lookup.lookup("X"));
assertEquals("--file", lookup.lookup("0"));
assertEquals("foo.txt", lookup.lookup("1"));
assertEquals("foo.txt", lookup.lookup("--file"));
- assertEquals(null, lookup.lookup("foo.txt"));
+ assertNull(lookup.lookup("foo.txt"));
}
@Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java
index e3ce8d4..33f1f26 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupConfigTest.java
@@ -16,28 +16,31 @@
*/
package org.apache.logging.log4j.core.lookup;
-import java.io.File;
-import java.io.IOException;
-
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests {@link MarkerLookup} with a configuration file.
*
* @since 2.4
*/
+@LoggerContextSource("log4j-marker-lookup.yaml")
+@Tag("yaml")
public class MarkerLookupConfigTest {
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule("log4j-marker-lookup.yaml");
public static final Marker PAYLOAD = MarkerManager.getMarker("PAYLOAD");
private static final String PAYLOAD_LOG = "Message in payload.log";
@@ -54,22 +57,22 @@ public class MarkerLookupConfigTest {
logger.info(PAYLOAD, PAYLOAD_LOG);
logger.info(PERFORMANCE, PERFORMANCE_LOG);
{
- final String log = FileUtils.readFileToString(new File("target/logs/sql.log"));
- Assert.assertTrue(log.contains(SQL_LOG));
- Assert.assertFalse(log.contains(PAYLOAD_LOG));
- Assert.assertFalse(log.contains(PERFORMANCE_LOG));
+ final String log = FileUtils.readFileToString(new File("target/logs/sql.log"), StandardCharsets.UTF_8);
+ assertTrue(log.contains(SQL_LOG));
+ assertFalse(log.contains(PAYLOAD_LOG));
+ assertFalse(log.contains(PERFORMANCE_LOG));
}
{
- final String log = FileUtils.readFileToString(new File("target/logs/payload.log"));
- Assert.assertFalse(log.contains(SQL_LOG));
- Assert.assertTrue(log.contains(PAYLOAD_LOG));
- Assert.assertFalse(log.contains(PERFORMANCE_LOG));
+ final String log = FileUtils.readFileToString(new File("target/logs/payload.log"), StandardCharsets.UTF_8);
+ assertFalse(log.contains(SQL_LOG));
+ assertTrue(log.contains(PAYLOAD_LOG));
+ assertFalse(log.contains(PERFORMANCE_LOG));
}
{
- final String log = FileUtils.readFileToString(new File("target/logs/performance.log"));
- Assert.assertFalse(log.contains(SQL_LOG));
- Assert.assertFalse(log.contains(PAYLOAD_LOG));
- Assert.assertTrue(log.contains(PERFORMANCE_LOG));
+ final String log = FileUtils.readFileToString(new File("target/logs/performance.log"), StandardCharsets.UTF_8);
+ assertFalse(log.contains(SQL_LOG));
+ assertFalse(log.contains(PAYLOAD_LOG));
+ assertTrue(log.contains(PERFORMANCE_LOG));
}
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
index fac33d4..3b27047 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
@@ -16,16 +16,15 @@
*/
package org.apache.logging.log4j.core.lookup;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.SimpleMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link MarkerLookup}.
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java
index f1aa6bf..6bd8838 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookupTest.java
@@ -16,36 +16,35 @@
*/
package org.apache.logging.log4j.core.lookup;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-/**
- *
- */
public class ResourceBundleLookupTest {
@Test
public void testLookup() {
final StrLookup lookup = new ResourceBundleLookup();
lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle_en:KeyA");
- Assert.assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
+ assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
}
@Test
public void testLookupWithLocale() {
final StrLookup lookup = new ResourceBundleLookup();
lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA");
- Assert.assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
+ assertEquals("ValueA", lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyA"));
}
public void testMissingKey() {
final StrLookup lookup = new ResourceBundleLookup();
- Assert.assertNull(lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyUnkown"));
+ assertNull(lookup.lookup("org.apache.logging.log4j.core.lookup.resource-bundle:KeyUnkown"));
}
@Test
public void testBadFormatBundleOnly() {
final StrLookup lookup = new ResourceBundleLookup();
- Assert.assertNull(lookup.lookup("X"));
+ assertNull(lookup.lookup("X"));
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java
index 41b7979..4edbd4e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StrSubstitutorTest.java
@@ -20,27 +20,24 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.ThreadContext;
-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 static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
public class StrSubstitutorTest {
private static final String TESTKEY = "TestKey";
private static final String TESTVAL = "TestValue";
- @BeforeClass
+ @BeforeAll
public static void before() {
System.setProperty(TESTKEY, TESTVAL);
}
- @AfterClass
+ @AfterAll
public static void after() {
System.clearProperty(TESTKEY);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java
index 09081dd..737ff41 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/StructuredDataLookupTest.java
@@ -21,13 +21,10 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
public class StructuredDataLookupTest {
private static final String TESTKEY = "type";
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java
index 5749548..e4db4cb 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookupTest.java
@@ -16,26 +16,23 @@
*/
package org.apache.logging.log4j.core.lookup;
-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 static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
public class SystemPropertiesLookupTest {
private static final String TESTKEY = "TestKey";
private static final String TESTVAL = "TestValue";
- @BeforeClass
+ @BeforeAll
public static void before() {
System.setProperty(TESTKEY, TESTVAL);
}
- @AfterClass
+ @AfterAll
public static void after() {
System.clearProperty(TESTKEY);
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java
index 8333f19..bc2b2df 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/message/ExtendedThreadInformationTest.java
@@ -17,9 +17,9 @@
package org.apache.logging.log4j.core.message;
import org.apache.logging.log4j.message.ThreadDumpMessage;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests that ThreadDumpMessage uses ExtendedThreadInformation when available.
@@ -31,6 +31,6 @@ public class ExtendedThreadInformationTest {
final String message = msg.getFormattedMessage();
//System.out.print(message);
- assertTrue("No header", message.contains(" Id="));
+ assertTrue(message.contains(" Id="), "No header");
}
}
\ No newline at end of file
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java
index 234bf6b..83eb42f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/PriorityTest.java
@@ -17,18 +17,15 @@
package org.apache.logging.log4j.core.net;
import org.apache.logging.log4j.Level;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-/**
- *
- */
public class PriorityTest {
@Test
public void testP1() {
final int p = Priority.getPriority(Facility.AUTH, Level.INFO);
- assertTrue("Expected priority value is 38, got "+ p, p == 38);
+ assertEquals(38, p, "Expected priority value is 38, got " + p);
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java
index 70ab122..27b4754 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketMessageLossTest.java
@@ -28,26 +28,22 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.junit.LoggerContextSource;
import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-@Ignore("Currently needs better port choosing support")
+@Disabled("Currently needs better port choosing support")
+@LoggerContextSource("log4j-socket2.xml")
public class SocketMessageLossTest {
private static final int SOCKET_PORT = AvailablePortFinder.getNextAvailable();
- private static final String CONFIG = "log4j-socket2.xml";
-
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule(CONFIG);
-
@Test
- public void testSocket() throws Exception {
+ public void testSocket(final LoggerContext context) throws Exception {
TestSocketServer testServer;
ExecutorService executor = null;
Future<InputStream> futureIn;
@@ -59,7 +55,7 @@ public class SocketMessageLossTest {
futureIn = executor.submit(testServer);
//System.err.println("Initializing logger");
- final Logger logger = context.getLogger();
+ final Logger logger = context.getLogger(getClass().getName());
String message = "Log #1";
logger.error(message);
@@ -69,7 +65,7 @@ public class SocketMessageLossTest {
//System.err.println("Closing server");
closeQuietly(testServer);
- assertTrue("Server not shutdown", testServer.server.isClosed());
+ assertTrue(testServer.server.isClosed(), "Server not shutdown");
//System.err.println("Sleeping to ensure no race conditions");
Thread.sleep(1000);
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
index 2edc1f3..918da60 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
@@ -23,10 +23,10 @@ import org.apache.logging.log4j.core.appender.AppenderLoggingException;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.test.AvailablePortFinder;
import org.apache.logging.log4j.util.Strings;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
import java.io.IOException;
@@ -40,9 +40,9 @@ import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-//@Ignore("Currently needs better port choosing support")
+//@Disabled("Currently needs better port choosing support")
public class SocketReconnectTest {
private static final int SOCKET_PORT1 = AvailablePortFinder.getNextAvailable();
private static final int SOCKET_PORT2 = AvailablePortFinder.getNextAvailable();
@@ -66,7 +66,7 @@ public class SocketReconnectTest {
private static Logger logger;
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
server1 = new TestSocketServer(0);
server2 = new TestSocketServer(0);
@@ -89,12 +89,12 @@ public class SocketReconnectTest {
list.clear();
}
- @AfterClass
+ @AfterAll
public static void afterClass() {
Configurator.shutdown(loggerContext);
}
- @After
+ @AfterEach
public void after() throws InterruptedException {
if (server1 != null) {
server1.shutdown();
@@ -128,7 +128,7 @@ public class SocketReconnectTest {
}
}
}
- assertNotNull("No message", msg);
+ assertNotNull(msg, "No message");
assertEquals(message, msg);
logger.error(SHUTDOWN);
@@ -148,7 +148,7 @@ public class SocketReconnectTest {
// System.err.println("Caught expected exception");
}
}
- assertTrue("No Exception thrown", exceptionCaught);
+ assertTrue(exceptionCaught, "No Exception thrown");
message = "Log #3";
@@ -167,7 +167,7 @@ public class SocketReconnectTest {
}
}
}
- assertNotNull("No message", msg);
+ assertNotNull(msg, "No message");
assertEquals(message, msg);
logger.error(SHUTDOWN);
server1.join();
@@ -196,7 +196,7 @@ public class SocketReconnectTest {
}
}
}
- assertNotNull("No message", msg);
+ assertNotNull(msg, "No message");
assertEquals(message, msg);
server1.shutdown();
@@ -215,7 +215,7 @@ public class SocketReconnectTest {
}
}
}
- assertNotNull("No message", msg);
+ assertNotNull(msg, "No message");
assertEquals(message, msg);
server2.shutdown();
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
index bcc207c..a50334a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
@@ -23,42 +23,25 @@ import java.net.Socket;
import java.util.concurrent.Callable;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.junit.LoggerContextSource;
import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-@Ignore("Currently needs better port choosing support")
+@Disabled("Currently needs better port choosing support")
+@LoggerContextSource("log4j-socket.xml")
public class SocketTest {
private static final int SOCKET_PORT = AvailablePortFinder.getNextAvailable();
- private static final String CONFIG = "log4j-socket.xml";
-
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule(CONFIG);
-
@Test
- public void testConnect() throws Exception {
- // TODO: there's a JUnit rule that simplifies this (matt)
+ public void testConnect(final LoggerContext context) {
System.err.println("Initializing logger");
- Logger logger = null;
- try {
- logger = context.getLogger();
- } catch (final NullPointerException e) {
- fail("Unexpected exception; should not occur until first logging statement " + e.getMessage());
- }
-
- final String message = "Log #1";
- try {
- logger.error(message);
- fail("Expected exception not thrown");
- } catch (final AppenderLoggingException e) {
- //System.err.println("Expected exception here, but already errored out when initializing logger");
- }
+ Logger logger = assertDoesNotThrow(() -> context.getLogger(getClass().getName()));
+ assertThrows(AppenderLoggingException.class, () -> logger.error("Log #1"));
}
private static class TestSocketServer implements Callable<InputStream> {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java
index a9b266f..61afab6 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/EnvironmentPasswordProviderTest.java
@@ -15,15 +15,15 @@ package org.apache.logging.log4j.core.net.ssl;/*
* limitations under the license.
*/
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class EnvironmentPasswordProviderTest {
- @Test(expected = NullPointerException.class)
+ @Test
public void testConstructorDisallowsNull() {
- new EnvironmentPasswordProvider(null);
+ assertThrows(NullPointerException.class, () -> new EnvironmentPasswordProvider(null));
}
@Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java
index 13ca8a4..cfe03cc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/FilePasswordProviderTest.java
@@ -19,9 +19,10 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
-import org.junit.Test;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class FilePasswordProviderTest {
@@ -36,13 +37,13 @@ public class FilePasswordProviderTest {
assertArrayEquals(PASSWORD.toCharArray(), actual);
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testConstructorDisallowsNull() throws Exception {
- new FilePasswordProvider(null);
+ assertThrows(NullPointerException.class, () -> new FilePasswordProvider(null));
}
- @Test(expected = NoSuchFileException.class)
+ @Test
public void testConstructorFailsIfFileDoesNotExist() throws Exception {
- new FilePasswordProvider("nosuchfile");
+ assertThrows(NoSuchFileException.class, () -> new FilePasswordProvider("nosuchfile"));
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java
index d5761ac..cb76930 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfigurationTest.java
@@ -16,31 +16,33 @@
*/
package org.apache.logging.log4j.core.net.ssl;
+import org.junit.jupiter.api.Test;
+
import java.security.KeyStore;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
public class KeyStoreConfigurationTest {
- @Test(expected = StoreConfigurationException.class)
- public void loadEmptyConfigurationDeprecated() throws StoreConfigurationException {
- final KeyStoreConfiguration ksc = new KeyStoreConfiguration(null, TestConstants.NULL_PWD, null, null);
- final KeyStore ks = ksc.getKeyStore();
- Assert.assertTrue(ks == null);
+ @SuppressWarnings("deprecation")
+ @Test
+ public void loadEmptyConfigurationDeprecated() {
+ assertThrows(StoreConfigurationException.class,
+ () -> new KeyStoreConfiguration(null, TestConstants.NULL_PWD, null, null));
}
- @Test(expected = StoreConfigurationException.class)
- public void loadEmptyConfiguration() throws StoreConfigurationException {
- final KeyStoreConfiguration ksc = new KeyStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null);
- final KeyStore ks = ksc.getKeyStore();
- Assert.assertTrue(ks == null);
+
+ @Test
+ public void loadEmptyConfiguration() {
+ assertThrows(StoreConfigurationException.class,
+ () -> new KeyStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null));
}
@Test
public void loadNotEmptyConfigurationDeprecated() throws StoreConfigurationException {
- final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
- TestConstants.KEYSTORE_TYPE, null);
+ @SuppressWarnings("deprecation") final KeyStoreConfiguration ksc =
+ new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
+ TestConstants.KEYSTORE_TYPE, null);
final KeyStore ks = ksc.getKeyStore();
- Assert.assertTrue(ks != null);
+ assertNotNull(ks);
}
@Test
@@ -48,16 +50,17 @@ public class KeyStoreConfigurationTest {
final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, new MemoryPasswordProvider(TestConstants.KEYSTORE_PWD()),
TestConstants.KEYSTORE_TYPE, null);
final KeyStore ks = ksc.getKeyStore();
- Assert.assertTrue(ks != null);
+ assertNotNull(ks);
}
@Test
public void returnTheSameKeyStoreAfterMultipleLoadsDeprecated() throws StoreConfigurationException {
- final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
- TestConstants.KEYSTORE_TYPE, null);
+ @SuppressWarnings("deprecation") final KeyStoreConfiguration ksc =
+ new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(),
+ TestConstants.KEYSTORE_TYPE, null);
final KeyStore ks = ksc.getKeyStore();
final KeyStore ks2 = ksc.getKeyStore();
- Assert.assertTrue(ks == ks2);
+ assertSame(ks, ks2);
}
@Test
@@ -66,18 +69,19 @@ public class KeyStoreConfigurationTest {
TestConstants.KEYSTORE_TYPE, null);
final KeyStore ks = ksc.getKeyStore();
final KeyStore ks2 = ksc.getKeyStore();
- Assert.assertTrue(ks == ks2);
+ assertSame(ks, ks2);
}
- @Test(expected = StoreConfigurationException.class)
- public void wrongPasswordDeprecated() throws StoreConfigurationException {
- final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, "wrongPassword!", null, null);
- ksc.getKeyStore();
+ @SuppressWarnings("deprecation")
+ @Test
+ public void wrongPasswordDeprecated() {
+ assertThrows(StoreConfigurationException.class,
+ () -> new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, "wrongPassword!", null, null));
}
- @Test(expected = StoreConfigurationException.class)
- public void wrongPassword() throws StoreConfigurationException {
- final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE, new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null);
- ksc.getKeyStore();
+ @Test
+ public void wrongPassword() {
+ assertThrows(StoreConfigurationException.class, () -> new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE,
+ new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null));
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java
index 99b3097..be9d27c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/MemoryPasswordProviderTest.java
@@ -17,14 +17,14 @@ package org.apache.logging.log4j.core.net.ssl;/*
import java.util.Arrays;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class MemoryPasswordProviderTest {
@Test
public void testConstructorAllowsNull() {
- assertEquals(null, new MemoryPasswordProvider(null).getPassword());
+ assertNull(new MemoryPasswordProvider(null).getPassword());
}
@Test
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
index 41349a0..091f08c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
@@ -23,14 +23,16 @@ import java.net.UnknownHostException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
public class SslConfigurationTest {
private static final String TLS_TEST_HOST = "login.yahoo.com";
private static final int TLS_TEST_PORT = 443;
+ @SuppressWarnings("deprecation")
public static SslConfiguration createTestSslConfigurationResourcesDeprecated() throws StoreConfigurationException {
final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE_RESOURCE,
TestConstants.KEYSTORE_PWD(), TestConstants.KEYSTORE_TYPE, null);
@@ -47,6 +49,7 @@ public class SslConfigurationTest {
return SslConfiguration.createSSLConfiguration(null, ksc, tsc);
}
+ @SuppressWarnings("deprecation")
public static SslConfiguration createTestSslConfigurationFilesDeprecated() throws StoreConfigurationException {
final KeyStoreConfiguration ksc = new KeyStoreConfiguration(TestConstants.KEYSTORE_FILE,
TestConstants.KEYSTORE_PWD(), TestConstants.KEYSTORE_TYPE, null);
@@ -65,32 +68,32 @@ public class SslConfigurationTest {
@Test
public void testGettersFromScratchFiles() throws StoreConfigurationException {
- Assert.assertNotNull(createTestSslConfigurationFiles().getProtocol());
- Assert.assertNotNull(createTestSslConfigurationFiles().getKeyStoreConfig());
- Assert.assertNotNull(createTestSslConfigurationFiles().getSslContext());
- Assert.assertNotNull(createTestSslConfigurationFiles().getSslSocketFactory());
- Assert.assertNotNull(createTestSslConfigurationFiles().getTrustStoreConfig());
+ assertNotNull(createTestSslConfigurationFiles().getProtocol());
+ assertNotNull(createTestSslConfigurationFiles().getKeyStoreConfig());
+ assertNotNull(createTestSslConfigurationFiles().getSslContext());
+ assertNotNull(createTestSslConfigurationFiles().getSslSocketFactory());
+ assertNotNull(createTestSslConfigurationFiles().getTrustStoreConfig());
}
@Test
public void testGettersFromScratchResources() throws StoreConfigurationException {
- Assert.assertNotNull(createTestSslConfigurationResources().getProtocol());
- Assert.assertNotNull(createTestSslConfigurationResources().getKeyStoreConfig());
- Assert.assertNotNull(createTestSslConfigurationResources().getSslContext());
- Assert.assertNotNull(createTestSslConfigurationResources().getSslSocketFactory());
- Assert.assertNotNull(createTestSslConfigurationResources().getTrustStoreConfig());
+ assertNotNull(createTestSslConfigurationResources().getProtocol());
+ assertNotNull(createTestSslConfigurationResources().getKeyStoreConfig());
+ assertNotNull(createTestSslConfigurationResources().getSslContext());
+ assertNotNull(createTestSslConfigurationResources().getSslSocketFactory());
+ assertNotNull(createTestSslConfigurationResources().getTrustStoreConfig());
}
@Test
public void equals() {
- Assert.assertEquals(SslConfiguration.createSSLConfiguration(null, null, null), SslConfiguration.createSSLConfiguration(null, null, null));
+ assertEquals(SslConfiguration.createSSLConfiguration(null, null, null), SslConfiguration.createSSLConfiguration(null, null, null));
}
@Test
public void emptyConfigurationDoesntCauseNullSSLSocketFactory() {
final SslConfiguration sc = SslConfiguration.createSSLConfiguration(null, null, null);
final SSLSocketFactory factory = sc.getSslSocketFactory();
- Assert.assertNotNull(factory);
+ assertNotNull(factory);
}
@Test
@@ -99,8 +102,7 @@ public class SslConfigurationTest {
final SSLSocketFactory factory = sc.getSslSocketFactory();
try {
try (final SSLSocket clientSocket = (SSLSocket) factory.createSocket(TLS_TEST_HOST, TLS_TEST_PORT)) {
- Assert.assertNotNull(clientSocket);
- clientSocket.close();
+ assertNotNull(clientSocket);
}
} catch (final UnknownHostException offline) {
// this exception is thrown on Windows when offline
@@ -116,10 +118,7 @@ public class SslConfigurationTest {
try {
try (final SSLSocket clientSocket = (SSLSocket) factory.createSocket(TLS_TEST_HOST, TLS_TEST_PORT)) {
try (final OutputStream os = clientSocket.getOutputStream()) {
- os.write("GET config/login_verify2?".getBytes());
- Assert.fail("Expected IOException");
- } catch (final IOException e) {
- // Expected, do nothing.
+ assertThrows(IOException.class, () -> os.write("GET config/login_verify2?".getBytes()));
}
}
} catch (final UnknownHostException offline) {
@@ -133,6 +132,6 @@ public class SslConfigurationTest {
new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null);
final SslConfiguration sslConf = SslConfiguration.createSSLConfiguration(null, ksc, null);
final SSLSocketFactory factory = sslConf.getSslSocketFactory();
- Assert.assertNotNull(factory);
+ assertNotNull(factory);
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java
index 2224ab6..cf73ea4 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/StoreConfigurationTest.java
@@ -16,12 +16,12 @@
*/
package org.apache.logging.log4j.core.net.ssl;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-@Ignore
+@Disabled
public class StoreConfigurationTest<T extends StoreConfiguration<?>> {
@Test
@@ -31,8 +31,8 @@ public class StoreConfigurationTest<T extends StoreConfiguration<?>> {
final StoreConfiguration<Object> a = new StoreConfiguration<>(location, password);
final StoreConfiguration<Object> b = new StoreConfiguration<>(location, password);
- assertTrue(a.equals(b));
- assertTrue(b.equals(a));
+ assertEquals(b, a);
+ assertEquals(a, b);
}
@Test
@@ -51,7 +51,7 @@ public class StoreConfigurationTest<T extends StoreConfiguration<?>> {
final StoreConfiguration<Object> a = new StoreConfiguration<>(null, new MemoryPasswordProvider(null));
final StoreConfiguration<Object> b = new StoreConfiguration<>(null, new MemoryPasswordProvider(null));
- assertTrue(a.equals(b));
- assertTrue(b.equals(a));
+ assertEquals(b, a);
+ assertEquals(a, b);
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java
index d27a1fd..e5777a4 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfigurationTest.java
@@ -16,45 +16,46 @@
*/
package org.apache.logging.log4j.core.net.ssl;
+import org.junit.jupiter.api.Test;
+
import java.security.KeyStore;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
public class TrustStoreConfigurationTest {
- @Test(expected = StoreConfigurationException.class)
- public void loadEmptyConfigurationDeprecated() throws StoreConfigurationException {
- final TrustStoreConfiguration ksc = new TrustStoreConfiguration(null, TestConstants.NULL_PWD, null, null);
- final KeyStore ks = ksc.getKeyStore();
- Assert.assertTrue(ks == null);
+ @SuppressWarnings("deprecation")
+ @Test
+ public void loadEmptyConfigurationDeprecated() {
+ assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(null, TestConstants.NULL_PWD, null, null));
}
- @Test(expected = StoreConfigurationException.class)
- public void loadEmptyConfiguration() throws StoreConfigurationException {
- final TrustStoreConfiguration ksc = new TrustStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null);
- final KeyStore ks = ksc.getKeyStore();
- Assert.assertTrue(ks == null);
+
+ @Test
+ public void loadEmptyConfiguration() {
+ assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(null, new MemoryPasswordProvider(TestConstants.NULL_PWD), null, null));
}
@Test
public void loadConfigurationDeprecated() throws StoreConfigurationException {
- final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
+ @SuppressWarnings("deprecation") final TrustStoreConfiguration ksc =
+ new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
final KeyStore ks = ksc.getKeyStore();
- Assert.assertNotNull(ks);
+ assertNotNull(ks);
}
@Test
public void loadConfiguration() throws StoreConfigurationException {
final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider(TestConstants.TRUSTSTORE_PWD()), null, null);
final KeyStore ks = ksc.getKeyStore();
- Assert.assertNotNull(ks);
+ assertNotNull(ks);
}
@Test
public void returnTheSameKeyStoreAfterMultipleLoadsDeprecated() throws StoreConfigurationException {
- final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
+ @SuppressWarnings("deprecation") final TrustStoreConfiguration ksc =
+ new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), null, null);
final KeyStore ks = ksc.getKeyStore();
final KeyStore ks2 = ksc.getKeyStore();
- Assert.assertTrue(ks == ks2);
+ assertSame(ks, ks2);
}
@Test
@@ -62,20 +63,17 @@ public class TrustStoreConfigurationTest {
final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider(TestConstants.TRUSTSTORE_PWD()), null, null);
final KeyStore ks = ksc.getKeyStore();
final KeyStore ks2 = ksc.getKeyStore();
- Assert.assertTrue(ks == ks2);
+ assertSame(ks, ks2);
}
- @Test(expected = StoreConfigurationException.class)
- public void wrongPasswordDeprecated() throws StoreConfigurationException {
- final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, "wrongPassword!".toCharArray(), null, null);
- ksc.getKeyStore();
- Assert.assertTrue(false);
+ @SuppressWarnings("deprecation")
+ @Test
+ public void wrongPasswordDeprecated() {
+ assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, "wrongPassword!".toCharArray(), null, null));
}
- @Test(expected = StoreConfigurationException.class)
- public void wrongPassword() throws StoreConfigurationException {
- final TrustStoreConfiguration ksc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null);
- ksc.getKeyStore();
- Assert.assertTrue(false);
+ @Test
+ public void wrongPassword() {
+ assertThrows(StoreConfigurationException.class, () -> new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, new MemoryPasswordProvider("wrongPassword!".toCharArray()), null, null));
}
}
diff --git a/pom.xml b/pom.xml
index 9e5247c..a4fb263 100644
--- a/pom.xml
+++ b/pom.xml
@@ -736,6 +736,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <version>${mockitoVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${springVersion}</version>