This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
The following commit(s) were added to refs/heads/master by this push: new f5daf70 Fix tests which compare against the environment (#28) f5daf70 is described below commit f5daf70f5c00e585eb45813ef90aec459dc8be89 Author: Alex Herbert <a.herb...@sussex.ac.uk> AuthorDate: Tue May 28 13:08:57 2019 +0100 Fix tests which compare against the environment (#28) * Directly use the System environment Map to set the expected. Removes use of EnvironmentConfiguration to set the expected result as this may interpolate values with substitution. * Disable interpolation when testing against the system environment. The runtime environment is not entirely controlled by the test and so may contain values that are subject to interpolation by the configuration. Disabling this allows the configuration to be tested directly against the environment properties. * Added spotbugs version to reports section. --- pom.xml | 1 + .../builder/combined/TestCombinedConfigurationBuilder.java | 7 +++++++ .../configuration2/interpol/TestEnvironmentLookup.java | 13 +++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 7fc0b43..a6b3b1f 100644 --- a/pom.xml +++ b/pom.xml @@ -850,6 +850,7 @@ <plugin> <groupId>com.github.spotbugs</groupId> <artifactId>spotbugs-maven-plugin</artifactId> + <version>${commons.spotbugs.version}</version> <configuration> <threshold>Normal</threshold> <effort>Default</effort> diff --git a/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedConfigurationBuilder.java b/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedConfigurationBuilder.java index 791f4f2..1017c21 100644 --- a/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedConfigurationBuilder.java +++ b/src/test/java/org/apache/commons/configuration2/builder/combined/TestCombinedConfigurationBuilder.java @@ -703,6 +703,13 @@ public class TestCombinedConfigurationBuilder builder.configure(createParameters().setFile(envFile)); final CombinedConfiguration cc = builder.getConfiguration(); assertFalse("Configuration is empty", cc.isEmpty()); + + // The environment may contain settings with values that + // are altered by interpolation. Disable this for direct access + // to the String associated with the environment property name. + cc.setInterpolator(null); + + // Test the environment is available through the configuration for (final Map.Entry<String, String> e : System.getenv().entrySet()) { assertEquals("Wrong value for property: " + e.getKey(), diff --git a/src/test/java/org/apache/commons/configuration2/interpol/TestEnvironmentLookup.java b/src/test/java/org/apache/commons/configuration2/interpol/TestEnvironmentLookup.java index bd7e2f9..203c2a0 100644 --- a/src/test/java/org/apache/commons/configuration2/interpol/TestEnvironmentLookup.java +++ b/src/test/java/org/apache/commons/configuration2/interpol/TestEnvironmentLookup.java @@ -19,12 +19,11 @@ package org.apache.commons.configuration2.interpol; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import java.util.Iterator; - -import org.apache.commons.configuration2.EnvironmentConfiguration; import org.junit.Before; import org.junit.Test; +import java.util.Map; + /** * Test class for EnvironmentLookup. * @@ -49,12 +48,10 @@ public class TestEnvironmentLookup @Test public void testLookup() { - final EnvironmentConfiguration envConf = new EnvironmentConfiguration(); - for (final Iterator<String> it = envConf.getKeys(); it.hasNext();) + for (final Map.Entry<String, String> e : System.getenv().entrySet()) { - final String var = it.next(); - assertEquals("Wrong value for " + var, envConf.getString(var), - lookup.lookup(var)); + assertEquals("Wrong value for " + e.getKey(), e.getValue(), + lookup.lookup(e.getKey())); } }