Skip to content

Commit feafaee

Browse files
refactor: Migrate core tests to junit5
Signed-off-by: Ninette Adhikari <[email protected]>
1 parent e446410 commit feafaee

21 files changed

+155
-170
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/MarkerMixInTest.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
*/
1717
package org.apache.logging.log4j;
1818

19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
1923
import com.fasterxml.jackson.core.JsonProcessingException;
2024
import com.fasterxml.jackson.databind.ObjectMapper;
2125
import com.fasterxml.jackson.databind.ObjectReader;
2226
import com.fasterxml.jackson.databind.ObjectWriter;
2327
import java.io.IOException;
2428
import org.apache.logging.log4j.MarkerManager.Log4jMarker;
25-
import org.junit.Assert;
26-
import org.junit.Before;
27-
import org.junit.Test;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
2831

2932
/**
3033
* Tests {@link MarkerMixIn}.
@@ -36,7 +39,7 @@ public abstract class MarkerMixInTest {
3639
private ObjectReader reader;
3740
private ObjectWriter writer;
3841

39-
@Before
42+
@BeforeEach
4043
public void setUp() {
4144
final ObjectMapper log4jObjectMapper = newObjectMapper();
4245
writer = log4jObjectMapper.writer();
@@ -50,9 +53,9 @@ public void setUp() {
5053
public void testNameOnly() throws IOException {
5154
final Marker expected = MarkerManager.getMarker("A");
5255
final String str = writeValueAsString(expected);
53-
Assert.assertFalse(str.contains("parents"));
56+
assertFalse(str.contains("parents"));
5457
final Marker actual = reader.readValue(str);
55-
Assert.assertEquals(expected, actual);
58+
assertEquals(expected, actual);
5659
}
5760

5861
@Test
@@ -61,9 +64,9 @@ public void testOneParent() throws IOException {
6164
final Marker parent = MarkerManager.getMarker("PARENT_MARKER");
6265
expected.addParents(parent);
6366
final String str = writeValueAsString(expected);
64-
Assert.assertTrue(str.contains("PARENT_MARKER"));
67+
assertTrue(str.contains("PARENT_MARKER"));
6568
final Marker actual = reader.readValue(str);
66-
Assert.assertEquals(expected, actual);
69+
assertEquals(expected, actual);
6770
}
6871

6972
/**
@@ -85,9 +88,9 @@ public void testTwoParents() throws IOException {
8588
expected.addParents(parent1);
8689
expected.addParents(parent2);
8790
final String str = writeValueAsString(expected);
88-
Assert.assertTrue(str.contains("PARENT_MARKER1"));
89-
Assert.assertTrue(str.contains("PARENT_MARKER2"));
91+
assertTrue(str.contains("PARENT_MARKER1"));
92+
assertTrue(str.contains("PARENT_MARKER2"));
9093
final Marker actual = reader.readValue(str);
91-
Assert.assertEquals(expected, actual);
94+
assertEquals(expected, actual);
9295
}
9396
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/GarbageCollectionHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.core;
1818

19-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import com.google.common.io.ByteStreams;
2222
import java.io.Closeable;
@@ -58,7 +58,7 @@ public void run() {
5858
public void close() {
5959
running.set(false);
6060
try {
61-
assertTrue("GarbageCollectionHelper did not shut down cleanly", latch.await(10, TimeUnit.SECONDS));
61+
assertTrue(latch.await(10, TimeUnit.SECONDS), "GarbageCollectionHelper did not shut down cleanly");
6262
} catch (final InterruptedException e) {
6363
throw new RuntimeException(e);
6464
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/Log4j1222Test.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.core;
1818

19-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import org.apache.logging.log4j.LogManager;
2222
import org.apache.logging.log4j.Logger;
@@ -50,7 +50,9 @@ public void run() {
5050

5151
private void trigger() {
5252
Holder.LOGGER.info("Attempt to trigger");
53-
assertTrue("Logger is of type " + Holder.LOGGER.getClass().getName(), Holder.LOGGER instanceof TestLogger);
53+
assertTrue(
54+
Holder.LOGGER instanceof TestLogger,
55+
"Logger is of type " + Holder.LOGGER.getClass().getName());
5456
if (((TestLogger) Holder.LOGGER).getEntries().isEmpty()) {
5557
System.out.println("Logger contains no messages");
5658
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderTest.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
package org.apache.logging.log4j.core.appender;
1818

19-
import static org.junit.Assert.assertNotNull;
20-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.io.BufferedReader;
2323
import java.io.File;
@@ -26,18 +26,17 @@
2626
import org.apache.logging.log4j.Logger;
2727
import org.apache.logging.log4j.core.config.ConfigurationFactory;
2828
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
29-
import org.apache.logging.log4j.core.test.categories.Layouts;
30-
import org.junit.BeforeClass;
31-
import org.junit.Test;
32-
import org.junit.experimental.categories.Category;
29+
import org.junit.jupiter.api.BeforeAll;
30+
import org.junit.jupiter.api.Tag;
31+
import org.junit.jupiter.api.Test;
3332

3433
/**
3534
* Tests a "compact" XML file, no extra spaces or end of lines.
3635
*/
37-
@Category(Layouts.Xml.class)
36+
@Tag("Layouts.Xml")
3837
public class XmlCompactFileAppenderTest {
3938

40-
@BeforeClass
39+
@BeforeAll
4140
public static void beforeClass() {
4241
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "XmlCompactFileAppenderTest.xml");
4342
}
@@ -57,21 +56,21 @@ public void testFlushAtEndOfBatch() throws Exception {
5756
} finally {
5857
file.delete();
5958
}
60-
assertNotNull("line1", line1);
59+
assertNotNull(line1, "line1");
6160
final String msg1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
62-
assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + ']', line1.contains(msg1));
61+
assertTrue(line1.contains(msg1), "line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + ']');
6362

6463
final String msg2 = "<Events xmlns=\"http://logging.apache.org/log4j/2.0/events\">";
65-
assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg2 + ']', line1.contains(msg2));
64+
assertTrue(line1.contains(msg2), "line1 incorrect: [" + line1 + "], does not contain: [" + msg2 + ']');
6665

6766
final String msg3 = "<Event ";
68-
assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg3 + ']', line1.contains(msg3));
67+
assertTrue(line1.contains(msg3), "line1 incorrect: [" + line1 + "], does not contain: [" + msg3 + ']');
6968

7069
final String msg4 = logMsg;
71-
assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg4 + ']', line1.contains(msg4));
70+
assertTrue(line1.contains(msg4), "line1 incorrect: [" + line1 + "], does not contain: [" + msg4 + ']');
7271

7372
final String location = "testFlushAtEndOfBatch";
74-
assertTrue("no location", !line1.contains(location));
73+
assertTrue(!line1.contains(location), "no location");
7574

7675
assertTrue(line1.indexOf('\r') == -1);
7776
assertTrue(line1.indexOf('\n') == -1);

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.core.appender;
1818

19-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.io.File;
2222
import java.nio.charset.Charset;
@@ -26,18 +26,17 @@
2626
import org.apache.logging.log4j.Logger;
2727
import org.apache.logging.log4j.core.config.ConfigurationFactory;
2828
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
29-
import org.apache.logging.log4j.core.test.categories.Layouts;
30-
import org.junit.BeforeClass;
31-
import org.junit.Test;
32-
import org.junit.experimental.categories.Category;
29+
import org.junit.jupiter.api.BeforeAll;
30+
import org.junit.jupiter.api.Tag;
31+
import org.junit.jupiter.api.Test;
3332

3433
/**
3534
* Tests a "complete" XML file a.k.a. a well-formed XML file.
3635
*/
37-
@Category(Layouts.Xml.class)
36+
@Tag("Layouts.Xml")
3837
public class XmlFileAppenderTest {
3938

40-
@BeforeClass
39+
@BeforeAll
4140
public static void beforeClass() {
4241
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "XmlFileAppenderTest.xml");
4342
}
@@ -65,11 +64,11 @@ public void testFlushAtEndOfBatch() throws Exception {
6564

6665
for (int i = 0; i < expect.length; i++) {
6766
assertTrue(
68-
"Expected line " + i + " to contain " + expect[i] + " but got: " + lines.get(i),
69-
lines.get(i).contains(expect[i]));
67+
lines.get(i).contains(expect[i]),
68+
"Expected line " + i + " to contain " + expect[i] + " but got: " + lines.get(i));
7069
}
7170

7271
final String location = "testFlushAtEndOfBatch";
73-
assertTrue("no location", !lines.get(0).contains(location));
72+
assertTrue(!lines.get(0).contains(location), "no location");
7473
}
7574
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerH2ConnectionSourceTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import java.sql.SQLException;
2121
import org.apache.logging.log4j.core.config.Property;
2222
import org.apache.logging.log4j.core.test.appender.db.jdbc.JdbcH2TestHelper;
23-
import org.junit.Assert;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
2525

2626
public class DriverManagerH2ConnectionSourceTest extends AbstractH2Test {
2727

@@ -40,7 +40,7 @@ public void testH2Properties() throws SQLException {
4040
.build();
4141
// @formatter:on
4242
try (final Connection conn = source.getConnection()) {
43-
Assert.assertFalse(conn.isClosed());
43+
Assertions.assertFalse(conn.isClosed());
4444
}
4545
}
4646

@@ -54,7 +54,7 @@ public void testH2UserAndPassword() throws SQLException {
5454
.build();
5555
// @formatter:on
5656
try (final Connection conn = source.getConnection()) {
57-
Assert.assertFalse(conn.isClosed());
57+
Assertions.assertFalse(conn.isClosed());
5858
}
5959
}
6060
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManagerProducerThreadLeakTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
import static org.junit.Assert.assertEquals;
2020

2121
import org.apache.logging.log4j.core.LoggerContext;
22-
import org.apache.logging.log4j.core.test.categories.Appenders;
2322
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
24-
import org.junit.experimental.categories.Category;
23+
import org.junit.jupiter.api.Tag;
2524
import org.junit.jupiter.api.Test;
2625

2726
/**
@@ -30,7 +29,7 @@
3029
*
3130
* @see <a href="https://issues.apache.org/jira/browse/LOG4J2-2916">LOG4J2-2916</a>
3231
*/
33-
@Category(Appenders.Kafka.class)
32+
@Tag("Appenders.Kafka")
3433
@LoggerContextSource("KafkaManagerProducerThreadLeakTest.xml")
3534
class KafkaManagerProducerThreadLeakTest {
3635

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/nosql/NoSqlAppenderTest.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
*/
1717
package org.apache.logging.log4j.core.appender.nosql;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertNull;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
2222

23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.extension.ExtendWith;
2525
import org.mockito.Mock;
26-
import org.mockito.junit.MockitoJUnitRunner;
26+
import org.mockito.junit.jupiter.MockitoExtension;
2727

28-
@RunWith(MockitoJUnitRunner.class)
28+
@ExtendWith(MockitoExtension.class)
2929
public class NoSqlAppenderTest {
3030

3131
@Mock
@@ -35,18 +35,18 @@ public class NoSqlAppenderTest {
3535
public void testNoProvider() {
3636
final NoSqlAppender appender = NoSqlAppender.createAppender("myName01", null, null, null, null);
3737

38-
assertNull("The appender should be null.", appender);
38+
assertNull(appender, "The appender should be null.");
3939
}
4040

4141
@Test
4242
public void testProvider() {
4343
final NoSqlAppender appender = NoSqlAppender.createAppender("myName01", null, null, null, provider);
4444

45-
assertNotNull("The appender should not be null.", appender);
45+
assertNotNull(appender, "The appender should not be null.");
4646
assertEquals(
47-
"The toString value is not correct.",
4847
"myName01{ manager=noSqlManager{ description=myName01, bufferSize=0, provider=" + provider + " } }",
49-
appender.toString());
48+
appender.toString(),
49+
"The toString value is not correct.");
5050

5151
appender.stop();
5252
}
@@ -55,12 +55,12 @@ public void testProvider() {
5555
public void testProviderBuffer() {
5656
final NoSqlAppender appender = NoSqlAppender.createAppender("anotherName02", null, null, "25", provider);
5757

58-
assertNotNull("The appender should not be null.", appender);
58+
assertNotNull(appender, "The appender should not be null.");
5959
assertEquals(
60-
"The toString value is not correct.",
6160
"anotherName02{ manager=noSqlManager{ description=anotherName02, bufferSize=25, provider=" + provider
6261
+ " } }",
63-
appender.toString());
62+
appender.toString(),
63+
"The toString value is not correct.");
6464

6565
appender.stop();
6666
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/PathConditionTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*/
1717
package org.apache.logging.log4j.core.appender.rolling.action;
1818

19-
import static org.junit.Assert.assertArrayEquals;
20-
import static org.junit.Assert.assertNotSame;
21-
import static org.junit.Assert.assertSame;
19+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotSame;
21+
import static org.junit.jupiter.api.Assertions.assertSame;
2222

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

log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigAutoFlushTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void testFlushAtEndOfBatch() throws Exception {
5151
final String line1 = reader.readLine();
5252
reader.close();
5353
file.delete();
54-
assertNotNull("line1", line1);
54+
assertNotNull(line1, "line1");
5555
assertTrue(line1.contains(msg), "line1 correct");
5656
}
5757
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerLocationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testAsyncLogWritesToLog() throws Exception {
6363
final String line1 = reader.readLine();
6464
reader.close();
6565
file.delete();
66-
assertNotNull("line1", line1);
66+
assertNotNull(line1, "line1");
6767
assertTrue(line1.contains(msg), "line1 correct");
6868

6969
final String location = "testAsyncLogWritesToLog";

log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncQueueFullPolicyTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
*/
1717
package org.apache.logging.log4j.core.async;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

2121
import org.apache.logging.log4j.Level;
22-
import org.apache.logging.log4j.core.test.categories.AsyncLoggers;
23-
import org.junit.Test;
24-
import org.junit.experimental.categories.Category;
22+
import org.junit.jupiter.api.Tag;
23+
import org.junit.jupiter.api.Test;
2524

2625
/**
2726
* Tests the DefaultAsyncQueueFullPolicy class.
2827
*/
29-
@Category(AsyncLoggers.class)
28+
@Tag("AsyncLoggers")
3029
public class DefaultAsyncQueueFullPolicyTest {
3130

3231
private static long currentThreadId() {

0 commit comments

Comments
 (0)