You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/05/30 22:52:39 UTC
[logging-log4j2] 03/03: LOG4J2-3521 - Fix broken test using system props
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit a15dbe46eaf01cbdee98c6e9930fee0e7b98a3aa
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Mon May 30 17:52:09 2022 -0500
LOG4J2-3521 - Fix broken test using system props
---
.../plugins/condition/OnPropertyConditionTest.java | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/condition/OnPropertyConditionTest.java b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/condition/OnPropertyConditionTest.java
index 893ef158ed..991c233f59 100644
--- a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/condition/OnPropertyConditionTest.java
+++ b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/condition/OnPropertyConditionTest.java
@@ -21,16 +21,12 @@ import org.apache.logging.log4j.plugins.Factory;
import org.apache.logging.log4j.plugins.Ordered;
import org.apache.logging.log4j.plugins.di.DI;
import org.apache.logging.log4j.util.PropertiesUtil;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
+import org.junitpioneer.jupiter.ClearSystemProperty;
+import org.junitpioneer.jupiter.SetSystemProperty;
import static org.junit.jupiter.api.Assertions.assertEquals;
-@ResourceLock(Resources.SYSTEM_PROPERTIES)
-@Disabled //"https://issues.apache.org/jira/browse/LOG4J2-3521"
class OnPropertyConditionTest {
static class OnProperty {
@@ -54,28 +50,26 @@ class OnPropertyConditionTest {
}
}
- @AfterEach
- void tearDown() {
- System.clearProperty("foo.bar");
- PropertiesUtil.getProperties().reload();
- }
-
@Test
+ @ClearSystemProperty(key = "foo.bar")
void whenPropertyAbsent() {
+ PropertiesUtil.getProperties().reload();
final String value = DI.createInjector(OnProperty.class).getInstance(String.class);
assertEquals("goodbye", value);
}
@Test
+ @SetSystemProperty(key = "foo.bar", value = "whatever")
void whenPropertyPresent() {
- System.setProperty("foo.bar", "whatever");
+ PropertiesUtil.getProperties().reload();
final String value = DI.createInjector(OnProperty.class).getInstance(String.class);
assertEquals("hello", value);
}
@Test
+ @SetSystemProperty(key = "foo.bar", value = "true")
void whenPropertyMatches() {
- System.setProperty("foo.bar", "true");
+ PropertiesUtil.getProperties().reload();
final String value = DI.createInjector(OnProperty.class).getInstance(String.class);
assertEquals("truth", value);
}