Skip to content

Commit 28da720

Browse files
authored
Migrate log4j-to-slf4j to JUnit5 (#3040)
1 parent 38bc033 commit 28da720

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

log4j-to-slf4j/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@
102102
<artifactId>junit-jupiter-params</artifactId>
103103
<scope>test</scope>
104104
</dependency>
105-
<dependency>
106-
<groupId>org.junit.vintage</groupId>
107-
<artifactId>junit-vintage-engine</artifactId>
108-
<scope>test</scope>
109-
</dependency>
110105
<dependency>
111106
<groupId>ch.qos.logback</groupId>
112107
<artifactId>logback-classic</artifactId>

log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.apache.logging.slf4j;
1818

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

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

@@ -53,9 +53,9 @@ public void testMethodLogger() throws Exception {
5353
logger.warn("brains~~~");
5454
logger.info("Itchy. Tasty.");
5555
final List<String> messages = app.strList;
56-
assertEquals("Incorrect number of messages.", 5, messages.size());
56+
assertEquals(5, messages.size(), "Incorrect number of messages.");
5757
for (final String message : messages) {
58-
assertEquals("Incorrect caller method name.", "testMethodLogger", message);
58+
assertEquals("testMethodLogger", message, "Incorrect caller method name.");
5959
}
6060
}
6161
}

log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
*/
1717
package org.apache.logging.slf4j;
1818

19+
import static org.hamcrest.MatcherAssert.assertThat;
1920
import static org.hamcrest.Matchers.hasItem;
2021
import static org.hamcrest.Matchers.hasSize;
2122
import static org.hamcrest.Matchers.is;
2223
import static org.hamcrest.Matchers.notNullValue;
2324
import static org.hamcrest.Matchers.theInstance;
24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.assertFalse;
26-
import static org.junit.Assert.assertNotNull;
27-
import static org.junit.Assert.assertNull;
28-
import static org.junit.Assert.assertThat;
29-
import static org.junit.Assert.assertTrue;
30-
import static org.junit.Assert.fail;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.junit.jupiter.api.Assertions.assertNotNull;
28+
import static org.junit.jupiter.api.Assertions.assertNull;
29+
import static org.junit.jupiter.api.Assertions.assertTrue;
30+
import static org.junit.jupiter.api.Assertions.fail;
3131

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

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

230230
@Test
231231
public void mdcNullBackedIsEmpty() {
232-
assertNull("Setup wrong", MDC.getCopyOfContextMap());
232+
assertNull(MDC.getCopyOfContextMap(), "Setup wrong");
233233
assertTrue(ThreadContext.isEmpty());
234234
}
235235

236236
@Test
237237
public void mdcNullBackedContainsKey() {
238-
assertNull("Setup wrong", MDC.getCopyOfContextMap());
238+
assertNull(MDC.getCopyOfContextMap(), "Setup wrong");
239239
assertFalse(ThreadContext.containsKey("something"));
240240
}
241241

242242
@Test
243243
public void mdcNullBackedContainsNullKey() {
244-
assertNull("Setup wrong", MDC.getCopyOfContextMap());
244+
assertNull(MDC.getCopyOfContextMap(), "Setup wrong");
245245
assertFalse(ThreadContext.containsKey(null));
246246
}
247247

248248
@Test
249249
public void mdcContainsNullKey() {
250250
try {
251251
ThreadContext.put("some", "thing");
252-
assertNotNull("Setup wrong", MDC.getCopyOfContextMap());
252+
assertNotNull(MDC.getCopyOfContextMap(), "Setup wrong");
253253
assertFalse(ThreadContext.containsKey(null));
254254
} finally {
255255
ThreadContext.clearMap();

0 commit comments

Comments
 (0)