Skip to content

refactor: Migrate log4j-to-slf4j to JUnit5 #3040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions log4j-to-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.apache.logging.slf4j;

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

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.testUtil.StringListAppender;
Expand All @@ -37,9 +37,9 @@ public void testClassLogger() throws Exception {
logger.warn("Verifying the caller class is still correct.");
logger.error("Hopefully nobody breaks me!");
final List<String> messages = app.strList;
assertEquals("Incorrect number of messages.", 3, messages.size());
assertEquals(3, messages.size(), "Incorrect number of messages.");
for (final String message : messages) {
assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
assertEquals(this.getClass().getName(), message, "Incorrect caller class name.");
}
}

Expand All @@ -53,9 +53,9 @@ public void testMethodLogger() throws Exception {
logger.warn("brains~~~");
logger.info("Itchy. Tasty.");
final List<String> messages = app.strList;
assertEquals("Incorrect number of messages.", 5, messages.size());
assertEquals(5, messages.size(), "Incorrect number of messages.");
for (final String message : messages) {
assertEquals("Incorrect caller method name.", "testMethodLogger", message);
assertEquals("testMethodLogger", message, "Incorrect caller method name.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
*/
package org.apache.logging.slf4j;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.theInstance;
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.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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 static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
Expand Down Expand Up @@ -213,7 +213,7 @@ public void testImpliedThrowable() {
final List<String> msgs = list.strList;
assertThat(msgs, hasSize(1));
final String expected = "java.lang.Throwable: Testing";
assertTrue("Incorrect message data", msgs.get(0).contains(expected));
assertTrue(msgs.get(0).contains(expected), "Incorrect message data");
}

@SuppressWarnings("unchecked")
Expand All @@ -224,32 +224,32 @@ public void mdc() {
ThreadContext.clearMap();
logger.debug("Debug message");
assertThat(list.strList, hasSize(2));
assertTrue("Incorrect year", list.strList.get(0).startsWith("2010"));
assertTrue(list.strList.get(0).startsWith("2010"), "Incorrect year");
}

@Test
public void mdcNullBackedIsEmpty() {
assertNull("Setup wrong", MDC.getCopyOfContextMap());
assertNull(MDC.getCopyOfContextMap(), "Setup wrong");
assertTrue(ThreadContext.isEmpty());
}

@Test
public void mdcNullBackedContainsKey() {
assertNull("Setup wrong", MDC.getCopyOfContextMap());
assertNull(MDC.getCopyOfContextMap(), "Setup wrong");
assertFalse(ThreadContext.containsKey("something"));
}

@Test
public void mdcNullBackedContainsNullKey() {
assertNull("Setup wrong", MDC.getCopyOfContextMap());
assertNull(MDC.getCopyOfContextMap(), "Setup wrong");
assertFalse(ThreadContext.containsKey(null));
}

@Test
public void mdcContainsNullKey() {
try {
ThreadContext.put("some", "thing");
assertNotNull("Setup wrong", MDC.getCopyOfContextMap());
assertNotNull(MDC.getCopyOfContextMap(), "Setup wrong");
assertFalse(ThreadContext.containsKey(null));
} finally {
ThreadContext.clearMap();
Expand Down