Skip to content

Commit

Permalink
Update modules using junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
ninetteadhikari committed Sep 25, 2024
1 parent 6da542e commit 12a1600
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.core;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.io.ByteStreams;
import java.io.Closeable;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void run() {
public void close() {
running.set(false);
try {
assertTrue("GarbageCollectionHelper did not shut down cleanly", latch.await(10, TimeUnit.SECONDS));
assertTrue(latch.await(10, TimeUnit.SECONDS), "GarbageCollectionHelper did not shut down cleanly");
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.core;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -50,7 +50,9 @@ public void run() {

private void trigger() {
Holder.LOGGER.info("Attempt to trigger");
assertTrue("Logger is of type " + Holder.LOGGER.getClass().getName(), Holder.LOGGER instanceof TestLogger);
assertTrue(
Holder.LOGGER instanceof TestLogger,
"Logger is of type " + Holder.LOGGER.getClass().getName());
if (((TestLogger) Holder.LOGGER).getEntries().isEmpty()) {
System.out.println("Logger contains no messages");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ public void testFileName() {
final String message = messages.get(0);
System.out.println(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.sql.SQLException;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.test.appender.db.jdbc.JdbcH2TestHelper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class DriverManagerH2ConnectionSourceTest extends AbstractH2Test {

Expand All @@ -40,7 +40,7 @@ public void testH2Properties() throws SQLException {
.build();
// @formatter:on
try (final Connection conn = source.getConnection()) {
Assert.assertFalse(conn.isClosed());
Assertions.assertFalse(conn.isClosed());
}
}

Expand All @@ -54,7 +54,7 @@ public void testH2UserAndPassword() throws SQLException {
.build();
// @formatter:on
try (final Connection conn = source.getConnection()) {
Assert.assertFalse(conn.isClosed());
Assertions.assertFalse(conn.isClosed());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import static org.junit.Assert.assertEquals;

import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.categories.Appenders;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -30,7 +29,7 @@
*
* @see <a href="https://issues.apache.org/jira/browse/LOG4J2-2916">LOG4J2-2916</a>
*/
@Category(Appenders.Kafka.class)
@Tag("Appenders.Kafka")
@LoggerContextSource("KafkaManagerProducerThreadLeakTest.xml")
class KafkaManagerProducerThreadLeakTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*/
package org.apache.logging.log4j.core.appender.nosql;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

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 org.mockito.junit.jupiter.MockitoExtension;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class NoSqlAppenderTest {

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

assertNull("The appender should be null.", appender);
assertNull(appender, "The appender should be null.");
}

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

assertNotNull("The appender should not be null.", appender);
assertNotNull(appender, "The appender should not be null.");
assertEquals(
"The toString value is not correct.",
"myName01{ manager=noSqlManager{ description=myName01, bufferSize=0, provider=" + provider + " } }",
appender.toString());
appender.toString(),
"The toString value is not correct.");

appender.stop();
}
Expand All @@ -55,12 +55,12 @@ public void testProvider() {
public void testProviderBuffer() {
final NoSqlAppender appender = NoSqlAppender.createAppender("anotherName02", null, null, "25", provider);

assertNotNull("The appender should not be null.", appender);
assertNotNull(appender, "The appender should not be null.");
assertEquals(
"The toString value is not correct.",
"anotherName02{ manager=noSqlManager{ description=anotherName02, bufferSize=25, provider=" + provider
+ " } }",
appender.toString());
appender.toString(),
"The toString value is not correct.");

appender.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*/
package org.apache.logging.log4j.core.appender.rolling;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.regex.Matcher;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test getEligibleFiles method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.TimeUnit;

/**
* Test class loading deadlock condition from the LOG4J2-1457
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
import org.apache.logging.log4j.core.test.categories.AsyncLoggers;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("AsyncLoggers")
public class AsyncLoggerConfigAutoFlushTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package org.apache.logging.log4j.core.async;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -27,18 +27,17 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
import org.apache.logging.log4j.core.test.categories.AsyncLoggers;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category(AsyncLoggers.class)
@Tag("AsyncLoggers")
public class AsyncLoggerConfigTest2 {

@Test
public void testConsecutiveReconfigure() throws Exception {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "AsyncLoggerConfigTest2.xml");
final File file = new File("target", "AsyncLoggerConfigTest2.log");
assertTrue("Deleted old file before test", !file.exists() || file.delete());
assertTrue(!file.exists() || file.delete(), "Deleted old file before test");

final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Message before reconfig";
Expand All @@ -57,9 +56,9 @@ public void testConsecutiveReconfigure() throws Exception {
final String line2 = reader.readLine();
reader.close();
file.delete();
assertNotNull("line1", line1);
assertNotNull("line2", line2);
assertTrue("line1 " + line1, line1.contains(msg));
assertTrue("line2 " + line2, line2.contains(msg2));
assertNotNull(line1, "line1");
assertNotNull(line2, "line2");
assertTrue(line1.contains(msg), "line1 " + line1);
assertTrue(line2.contains(msg2), "line2 " + line2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static org.junit.jupiter.api.Assertions.assertTrue;

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

@Tag("AsyncLoggers")
public class AsyncLoggerContextSelectorInitialStateTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
*/
package org.apache.logging.log4j.core.async;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.categories.AsyncLoggers;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category(AsyncLoggers.class)
@Tag("AsyncLoggers")
public class AsyncLoggerContextSelectorTest {

private static final String FQCN = AsyncLoggerContextSelectorTest.class.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,33 @@
*/
package org.apache.logging.log4j.core.async;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.apache.logging.log4j.core.test.categories.AsyncLoggers;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.util.Strings;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category(AsyncLoggers.class)
@Tag("AsyncLoggers")
public class AsyncLoggerDefaultLocationTest {

@BeforeClass
@BeforeAll
public static void beforeClass() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "AsyncLoggerDefaultLocationTest.xml");
}

@AfterClass
@AfterAll
public static void afterClass() {
System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, Strings.EMPTY);
}
Expand All @@ -59,7 +58,7 @@ public void testAsyncLogWritesToLog() throws Exception {
context.stop();
assertEquals(1, app.getEvents().size());
final LogEvent event = app.getEvents().get(0);
assertFalse("includeLocation should be false", event.isIncludeLocation());
assertNull("Location data should not be present", event.getSource());
assertFalse(event.isIncludeLocation(), "includeLocation should be false");
assertNull(event.getSource(), "Location data should not be present");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,33 @@
*/
package org.apache.logging.log4j.core.async;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.apache.logging.log4j.core.test.categories.AsyncLoggers;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.util.Strings;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category(AsyncLoggers.class)
@Tag("AsyncLoggers")
public class AsyncRootLoggerDefaultLocationTest {

@BeforeClass
@BeforeAll
public static void beforeClass() {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "AsyncRootLoggerDefaultLocationTest.xml");
}

@AfterClass
@AfterAll
public static void afterClass() {
System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, Strings.EMPTY);
}
Expand All @@ -59,7 +58,7 @@ public void testAsyncLogWritesToLog() throws Exception {
context.stop();
assertEquals(1, app.getEvents().size());
final LogEvent event = app.getEvents().get(0);
assertFalse("includeLocation should be false", event.isIncludeLocation());
assertNull("Location data should not be present", event.getSource());
assertFalse(event.isIncludeLocation(), "includeLocation should be false");
assertNull(event.getSource(), "Location data should not be present");
}
}
Loading

0 comments on commit 12a1600

Please sign in to comment.