This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new 40f1bde55a Simplify `log4j-jcl` tests (#2163)
40f1bde55a is described below
commit 40f1bde55a1b83ad800fc8f97e3ac3dda5cae732
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Wed Jan 10 14:06:29 2024 +0100
Simplify `log4j-jcl` tests (#2163)
---
.../logging/log4j/jcl/CallerInformationTest.java | 20 +++++++---------
.../org/apache/logging/log4j/jcl/LoggerTest.java | 28 ++++++++++------------
.../log4j/jcl => }/CallerInformationTest.xml | 0
.../apache/logging/log4j/jcl => }/LoggerTest.xml | 0
4 files changed, 22 insertions(+), 26 deletions(-)
diff --git
a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
index 8a29772b34..3580a3b837 100644
---
a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
+++
b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/CallerInformationTest.java
@@ -16,24 +16,22 @@
*/
package org.apache.logging.log4j.jcl;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.appender.ListAppender;
-import org.apache.logging.log4j.test.junit.SetTestProperty;
-import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.junit.jupiter.api.Test;
-@UsingStatusListener
-@SetTestProperty(key = "log4j2.configurationFile", value =
"org/apache/logging/log4j/jcl/CallerInformationTest.xml")
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
public class CallerInformationTest {
@Test
- public void testClassLogger() throws Exception {
- final LoggerContext ctx = LoggerContext.getContext(false);
+ @LoggerContextSource("CallerInformationTest.xml")
+ public void testClassLogger(final LoggerContext ctx) {
final ListAppender app = ctx.getConfiguration().getAppender("Class");
app.clear();
final Log logger = LogFactory.getLog("ClassLogger");
@@ -45,8 +43,8 @@ public class CallerInformationTest {
}
@Test
- public void testMethodLogger() throws Exception {
- final LoggerContext ctx = LoggerContext.getContext(false);
+ @LoggerContextSource("CallerInformationTest.xml")
+ public void testMethodLogger(final LoggerContext ctx) {
final ListAppender app = ctx.getConfiguration().getAppender("Method");
app.clear();
final Log logger = LogFactory.getLog("MethodLogger");
diff --git
a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
index 1054c3435c..771a8a89aa 100644
--- a/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
+++ b/log4j-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
@@ -16,20 +16,18 @@
*/
package org.apache.logging.log4j.jcl;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.appender.ListAppender;
-import org.apache.logging.log4j.test.junit.SetTestProperty;
-import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.util.Strings;
import org.junit.jupiter.api.Test;
-@UsingStatusListener
-@SetTestProperty(key = "log4j2.configurationFile", value =
"org/apache/logging/log4j/jcl/LoggerTest.xml")
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
class LoggerTest {
@Test
@@ -39,21 +37,21 @@ class LoggerTest {
}
@Test
- void testLog() {
+ @LoggerContextSource("LoggerTest.xml")
+ void testLog(final LoggerContext context) {
final Log logger = LogFactory.getLog("LoggerTest");
logger.debug("Test message");
- verify("List", "o.a.l.l.j.LoggerTest Test message MDC{}" +
Strings.LINE_SEPARATOR);
+ verify(context, "o.a.l.l.j.LoggerTest Test message MDC{}" +
Strings.LINE_SEPARATOR);
logger.debug("Exception: ", new NullPointerException("Test"));
- verify("List", "o.a.l.l.j.LoggerTest Exception: MDC{}" +
Strings.LINE_SEPARATOR);
+ verify(context, "o.a.l.l.j.LoggerTest Exception: MDC{}" +
Strings.LINE_SEPARATOR);
logger.info("Info Message");
- verify("List", "o.a.l.l.j.LoggerTest Info Message MDC{}" +
Strings.LINE_SEPARATOR);
+ verify(context, "o.a.l.l.j.LoggerTest Info Message MDC{}" +
Strings.LINE_SEPARATOR);
logger.info("Info Message {}");
- verify("List", "o.a.l.l.j.LoggerTest Info Message {} MDC{}" +
Strings.LINE_SEPARATOR);
+ verify(context, "o.a.l.l.j.LoggerTest Info Message {} MDC{}" +
Strings.LINE_SEPARATOR);
}
- private void verify(final String name, final String expected) {
- final LoggerContext context = LoggerContext.getContext(false);
- final ListAppender listApp =
context.getConfiguration().getAppender(name);
+ private static void verify(final LoggerContext context, final String
expected) {
+ final ListAppender listApp =
context.getConfiguration().getAppender("List");
final List<String> events = listApp.getMessages();
assertThat(events).hasSize(1).containsExactly(expected);
listApp.clear();
diff --git
a/log4j-jcl/src/test/resources/org/apache/logging/log4j/jcl/CallerInformationTest.xml
b/log4j-jcl/src/test/resources/CallerInformationTest.xml
similarity index 100%
rename from
log4j-jcl/src/test/resources/org/apache/logging/log4j/jcl/CallerInformationTest.xml
rename to log4j-jcl/src/test/resources/CallerInformationTest.xml
diff --git
a/log4j-jcl/src/test/resources/org/apache/logging/log4j/jcl/LoggerTest.xml
b/log4j-jcl/src/test/resources/LoggerTest.xml
similarity index 100%
rename from
log4j-jcl/src/test/resources/org/apache/logging/log4j/jcl/LoggerTest.xml
rename to log4j-jcl/src/test/resources/LoggerTest.xml