This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 012026ea3444018326526ae358703bc13c4ab667
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Thu Oct 27 22:33:51 2022 +0200

    Add per-test property source
    
    The `@SetTestProperty` annotation allows to set a single property into
    the Log4j2 environment properties.
    
    The `@UsingTestProperties` annotation injects a `TestProperties`
    instance into fields and method parameters. This can be used to set
    multiple Log4j2 environment properties in code.
---
 .../apache/logging/log4j/test/TestProperties.java} |  39 +++---
 .../logging/log4j/test/junit/SetTestProperty.java  |  63 +++++++++
 .../log4j/test/junit/TestPropertyResolver.java     |  81 ++++++++++++
 .../log4j/test/junit/TestPropertySource.java       | 141 +++++++++++++++++++++
 .../log4j/test/junit/ThreadContextInitializer.java |  17 +++
 .../test/junit/TypeBasedParameterResolver.java     |   4 +-
 .../log4j/test/junit/UsingTestProperties.java      |  46 +++++++
 log4j-api-test/src/main/module/module-info.java    |   4 +
 .../org.apache.logging.log4j.util.PropertySource   |  15 +++
 .../log4j/test/junit/TestPropertySourceTest.java   |  57 +++++++++
 .../core/test/junit/ConfigurationResolver.java     |   1 +
 .../core/test/junit/LoggerContextResolver.java     |   1 +
 12 files changed, 451 insertions(+), 18 deletions(-)

diff --git a/log4j-api-test/src/main/module/module-info.java 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestProperties.java
similarity index 56%
copy from log4j-api-test/src/main/module/module-info.java
copy to 
log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestProperties.java
index 650b21d769..0c66fc8b94 100644
--- a/log4j-api-test/src/main/module/module-info.java
+++ 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestProperties.java
@@ -14,20 +14,27 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-module org.apache.logging.log4j.test {
-    exports org.apache.logging.log4j.test;
-    exports org.apache.logging.log4j.test.junit;
-
-    opens org.apache.logging.log4j.test.junit to org.junit.platform.commons;
-
-    requires transitive org.apache.logging.log4j;
-    requires static org.apache.commons.lang3;
-    requires static org.assertj.core;
-    requires static org.hamcrest;
-    requires static org.junit.jupiter.api;
-    requires static org.junit.jupiter.params;
-    requires static org.junit.platform.commons;
-    requires static org.junit.platform.launcher;
-    requires static org.junitpioneer;
-    requires static junit;
+
+package org.apache.logging.log4j.test;
+
+/**
+ * A container for per-test properties.
+ */
+public interface TestProperties {
+
+    String getProperty(final String key);
+
+    boolean containsProperty(final String key);
+
+    void setProperty(final String key, final String value);
+
+    default void setProperty(final String key, final boolean value) {
+        setProperty(key, value ? "true" : "false");
+    }
+
+    default void setProperty(final String key, final int value) {
+        setProperty(key, Integer.toString(value));
+    }
+
+    void clearProperty(final String key);
 }
diff --git 
a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/SetTestProperty.java
 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/SetTestProperty.java
new file mode 100644
index 0000000000..2d85d168a3
--- /dev/null
+++ 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/SetTestProperty.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.test.junit;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junitpioneer.jupiter.ReadsEnvironmentVariable;
+import org.junitpioneer.jupiter.ReadsSystemProperty;
+
+/**
+ * Registers a Log4j2 system property with the {@link TestPropertySource}. The
+ * property will also be available in configuration files using the
+ * {@code ${test:...} lookup.
+ *
+ */
+@Retention(RUNTIME)
+@Target({ TYPE, METHOD })
+@Inherited
+@Documented
+@ExtendWith(ExtensionContextAnchor.class)
+@ExtendWith(TestPropertyResolver.class)
+@Repeatable(SetTestProperty.SetTestProperties.class)
+@ReadsSystemProperty
+@ReadsEnvironmentVariable
+public @interface SetTestProperty {
+
+    String key();
+
+    String value();
+
+    @Retention(RUNTIME)
+    @Target({ TYPE, METHOD })
+    @Documented
+    @Inherited
+    public @interface SetTestProperties {
+
+        SetTestProperty[] value();
+    }
+}
diff --git 
a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertyResolver.java
 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertyResolver.java
new file mode 100644
index 0000000000..abb659f255
--- /dev/null
+++ 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertyResolver.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.test.junit;
+
+import org.apache.logging.log4j.test.TestProperties;
+import org.apache.logging.log4j.util.ReflectionUtil;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.platform.commons.support.HierarchyTraversalMode;
+import org.junit.platform.commons.support.ModifierSupport;
+import org.junit.platform.commons.support.ReflectionSupport;
+
+public class TestPropertyResolver extends 
TypeBasedParameterResolver<TestProperties>
+        implements BeforeAllCallback, BeforeEachCallback {
+
+    public TestPropertyResolver() {
+        super(TestProperties.class);
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext context) throws Exception {
+        final TestProperties props = 
TestPropertySource.createProperties(context);
+        final SetTestProperty[] setProperties = context.getRequiredTestMethod()
+                .getAnnotationsByType(SetTestProperty.class);
+        if (setProperties.length > 0) {
+            for (final SetTestProperty setProperty : setProperties) {
+                props.setProperty(setProperty.key(), setProperty.value());
+            }
+        }
+        final Class<?> testClass = context.getRequiredTestClass();
+        Object testInstance = context.getRequiredTestInstance();
+        ReflectionSupport
+                .findFields(testClass,
+                        field -> ModifierSupport.isNotStatic(field)
+                                && 
field.getType().isAssignableFrom(TestProperties.class),
+                        HierarchyTraversalMode.BOTTOM_UP)
+                .forEach(field -> ReflectionUtil.setFieldValue(field, 
testInstance, props));
+    }
+
+    @Override
+    public void beforeAll(ExtensionContext context) throws Exception {
+        final TestProperties props = 
TestPropertySource.createProperties(context);
+        final SetTestProperty[] setProperties = context.getRequiredTestClass()
+                .getAnnotationsByType(SetTestProperty.class);
+        if (setProperties.length > 0) {
+            for (final SetTestProperty setProperty : setProperties) {
+                props.setProperty(setProperty.key(), setProperty.value());
+            }
+        }
+        final Class<?> testClass = context.getRequiredTestClass();
+        ReflectionSupport
+        .findFields(testClass,
+                field -> ModifierSupport.isStatic(field)
+                        && 
field.getType().isAssignableFrom(TestProperties.class),
+                HierarchyTraversalMode.BOTTOM_UP)
+        .forEach(field -> ReflectionUtil.setStaticFieldValue(field, props));
+    }
+
+    @Override
+    public TestProperties resolveParameter(ParameterContext parameterContext, 
ExtensionContext extensionContext)
+            throws ParameterResolutionException {
+        return TestPropertySource.createProperties(extensionContext);
+    }
+}
diff --git 
a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertySource.java
 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertySource.java
new file mode 100644
index 0000000000..d8190fdf4f
--- /dev/null
+++ 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertySource.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.test.junit;
+
+import org.apache.logging.log4j.test.TestProperties;
+import org.apache.logging.log4j.util.PropertySource;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
+import org.junit.jupiter.api.extension.ExtensionContext.Store;
+
+public class TestPropertySource implements PropertySource {
+
+    private static final String PREFIX = "log4j2.";
+    private static final Namespace NAMESPACE = 
ExtensionContextAnchor.LOG4J2_NAMESPACE.append("properties");
+    private static final TestProperties EMPTY_PROPERTIES = new 
EmptyTestProperties();
+
+    @Override
+    public int getPriority() {
+        // Highest priority
+        return Integer.MIN_VALUE;
+    }
+
+    public static TestProperties createProperties(ExtensionContext context) {
+        TestProperties props = getProperties(context);
+        // Make sure that the properties do not come from the parent 
ExtensionContext
+        if (props instanceof JUnitTestProperties && 
context.equals(((JUnitTestProperties) props).getContext())) {
+            return props;
+        }
+        props = new JUnitTestProperties(context);
+        ExtensionContextAnchor.setAttribute(TestProperties.class, props, 
context);
+        return props;
+    }
+
+    public static TestProperties getProperties() {
+        return getProperties(null);
+    }
+
+    private static TestProperties getProperties(ExtensionContext context) {
+        final ExtensionContext actualContext = context != null ? context : 
ExtensionContextAnchor.getContext();
+        if (actualContext != null) {
+            TestProperties props = 
ExtensionContextAnchor.getAttribute(TestProperties.class, TestProperties.class,
+                    actualContext);
+            if (props != null) {
+                return props;
+            }
+        }
+        return EMPTY_PROPERTIES;
+    }
+
+    @Override
+    public CharSequence getNormalForm(Iterable<? extends CharSequence> tokens) 
{
+        final CharSequence camelCase = Util.joinAsCamelCase(tokens);
+        // Do not use Strings to prevent recursive initialization
+        return camelCase.length() > 0 ? PREFIX + camelCase.toString() : null;
+    }
+
+    @Override
+    public String getProperty(String key) {
+        return getProperties().getProperty(key);
+    }
+
+    @Override
+    public boolean containsProperty(String key) {
+        return getProperties().containsProperty(key);
+    }
+
+    private static class JUnitTestProperties implements TestProperties {
+
+        private final ExtensionContext context;
+        private final Store store;
+
+        public JUnitTestProperties(ExtensionContext context) {
+            this.context = context;
+            this.store = context.getStore(NAMESPACE);
+        }
+
+        public ExtensionContext getContext() {
+            return context;
+        }
+
+        @Override
+        public String getProperty(String key) {
+            return store.get(key, String.class);
+        }
+
+        @Override
+        public boolean containsProperty(String key) {
+            return getProperty(key) != null;
+        }
+
+        @Override
+        public void setProperty(String key, String value) {
+            store.put(key, value);
+        }
+
+        @Override
+        public void clearProperty(String key) {
+            store.remove(key, String.class);
+        }
+
+    }
+
+    private static class EmptyTestProperties implements TestProperties {
+
+        @Override
+        public String getProperty(String key) {
+            return null;
+        }
+
+        @Override
+        public boolean containsProperty(String key) {
+            return false;
+        }
+
+        @Override
+        public void setProperty(String key, String value) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void clearProperty(String key) {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+}
diff --git 
a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextInitializer.java
 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextInitializer.java
index 9cca4ca9b8..c246c3ce5f 100644
--- 
a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextInitializer.java
+++ 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextInitializer.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
 package org.apache.logging.log4j.test.junit;
 
 import org.apache.logging.log4j.ThreadContext;
@@ -8,6 +24,7 @@ import org.junit.jupiter.api.extension.ExtensionContext;
 import 
org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
 import org.junit.platform.commons.support.AnnotationSupport;
 
+
 class ThreadContextInitializer implements BeforeAllCallback, 
BeforeEachCallback {
 
     @Override
diff --git 
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/TypeBasedParameterResolver.java
 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TypeBasedParameterResolver.java
similarity index 93%
rename from 
log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/TypeBasedParameterResolver.java
rename to 
log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TypeBasedParameterResolver.java
index 5e0e76782e..8cf338493b 100644
--- 
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/TypeBasedParameterResolver.java
+++ 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TypeBasedParameterResolver.java
@@ -14,7 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-package org.apache.logging.log4j.core.test.junit;
+package org.apache.logging.log4j.test.junit;
 
 import java.lang.reflect.Type;
 
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.extension.ParameterContext;
 import org.junit.jupiter.api.extension.ParameterResolutionException;
 import org.junit.jupiter.api.extension.ParameterResolver;
 
-abstract class TypeBasedParameterResolver<T> implements ParameterResolver {
+public abstract class TypeBasedParameterResolver<T> implements 
ParameterResolver {
 
     private final Type supportedParameterType;
 
diff --git 
a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingTestProperties.java
 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingTestProperties.java
new file mode 100644
index 0000000000..cc696522ab
--- /dev/null
+++ 
b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingTestProperties.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.test.junit;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.apache.logging.log4j.test.TestProperties;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junitpioneer.jupiter.ReadsEnvironmentVariable;
+import org.junitpioneer.jupiter.ReadsSystemProperty;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * A field or method parameter of type {@link TestProperties} will be injected 
with a per-test source of Log4j2's
+ * system properties.
+ */
+@Retention(RUNTIME)
+@Target({ TYPE, METHOD })
+@Inherited
+@Documented
+@ExtendWith(ExtensionContextAnchor.class)
+@ExtendWith(TestPropertyResolver.class)
+@ReadsSystemProperty
+@ReadsEnvironmentVariable
+public @interface UsingTestProperties {
+}
diff --git a/log4j-api-test/src/main/module/module-info.java 
b/log4j-api-test/src/main/module/module-info.java
index 650b21d769..4cf9336ae3 100644
--- a/log4j-api-test/src/main/module/module-info.java
+++ b/log4j-api-test/src/main/module/module-info.java
@@ -14,6 +14,8 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
+import org.apache.logging.log4j.util.PropertySource;
+import org.apache.logging.log4j.test.junit.TestPropertySource;
 module org.apache.logging.log4j.test {
     exports org.apache.logging.log4j.test;
     exports org.apache.logging.log4j.test.junit;
@@ -30,4 +32,6 @@ module org.apache.logging.log4j.test {
     requires static org.junit.platform.launcher;
     requires static org.junitpioneer;
     requires static junit;
+
+    provides PropertySource with TestPropertySource;
 }
diff --git 
a/log4j-api-test/src/main/resources/META-INF/services/org.apache.logging.log4j.util.PropertySource
 
b/log4j-api-test/src/main/resources/META-INF/services/org.apache.logging.log4j.util.PropertySource
new file mode 100644
index 0000000000..2c7cb498d9
--- /dev/null
+++ 
b/log4j-api-test/src/main/resources/META-INF/services/org.apache.logging.log4j.util.PropertySource
@@ -0,0 +1,15 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache license, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the license for the specific language governing permissions and
+# limitations under the license.
+org.apache.logging.log4j.test.junit.TestPropertySource
diff --git 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/test/junit/TestPropertySourceTest.java
 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/test/junit/TestPropertySourceTest.java
new file mode 100644
index 0000000000..48cab10a31
--- /dev/null
+++ 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/test/junit/TestPropertySourceTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.test.junit;
+
+import org.apache.logging.log4j.test.TestProperties;
+import org.apache.logging.log4j.util.PropertyEnvironment;
+import org.apache.logging.log4j.util3.PropertiesUtil;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@UsingTestProperties
+public class TestPropertySourceTest {
+
+    private static TestProperties staticProperties;
+    private TestProperties instanceProperties;
+
+    @Test
+    public void testInjectedFields() {
+        assertThat(staticProperties).isNotNull();
+        assertThat(instanceProperties).isNotNull();
+
+        // Test that per-class properties are overridden by per-test properties
+        final PropertyEnvironment env = PropertiesUtil.getProperties();
+        staticProperties.setProperty("log4j2.staticProperty", "static");
+        staticProperties.setProperty("log4j2.instanceProperty", "static");
+        instanceProperties.setProperty("log4j2.instanceProperty", "instance");
+        
assertThat(env.getStringProperty("log4j2.staticProperty")).isEqualTo("static");
+        
assertThat(env.getStringProperty("log4j.instanceProperty")).isEqualTo("instance");
+    }
+
+    @Test
+    public void testInjectedParameter(final TestProperties paramProperties) {
+        assertThat(paramProperties).isEqualTo(instanceProperties);
+    }
+
+    @Test
+    @SetTestProperty(key = "log4j2.testSetTestProperty", value = "true")
+    public void testSetTestProperty() {
+        final PropertyEnvironment env = PropertiesUtil.getProperties();
+        
assertThat(env.getBooleanProperty("log4j2.testSetTestProperty")).isTrue();
+    }
+}
diff --git 
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/ConfigurationResolver.java
 
b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/ConfigurationResolver.java
index 97d19ab225..a545fd2342 100644
--- 
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/ConfigurationResolver.java
+++ 
b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/ConfigurationResolver.java
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.test.junit;
 
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.test.junit.TypeBasedParameterResolver;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.ParameterContext;
 import org.junit.jupiter.api.extension.ParameterResolutionException;
diff --git 
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java
 
b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java
index 657b72a65d..e2b01200fa 100644
--- 
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java
+++ 
b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.impl.Log4jContextFactory;
 import org.apache.logging.log4j.core.util.NetUtils;
 import org.apache.logging.log4j.plugins.di.DI;
 import org.apache.logging.log4j.plugins.di.Injector;
+import org.apache.logging.log4j.test.junit.TypeBasedParameterResolver;
 import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;

Reply via email to