Skip to content

Commit

Permalink
[Java] Clean up after setting system properties. Issue #226.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Nov 9, 2020
1 parent e536cff commit 076d033
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions agrona/src/test/java/org/agrona/SystemUtilTest.java
Expand Up @@ -76,7 +76,6 @@ public void shouldDoNothingToSystemPropsWhenLoadingFileWhichDoesNotExist()
final int originalSystemPropSize = System.getProperties().size();

loadPropertiesFile("$unknown-file$");

assertEquals(originalSystemPropSize, System.getProperties().size());
}

Expand All @@ -86,10 +85,17 @@ public void shouldMergeMultiplePropFilesTogether()
assertThat(System.getProperty("TestFileA.foo"), is(emptyOrNullString()));
assertThat(System.getProperty("TestFileB.foo"), is(emptyOrNullString()));

loadPropertiesFiles("TestFileA.properties", "TestFileB.properties");

assertEquals("AAA", System.getProperty("TestFileA.foo"));
assertEquals("BBB", System.getProperty("TestFileB.foo"));
try
{
loadPropertiesFiles("TestFileA.properties", "TestFileB.properties");
assertEquals("AAA", System.getProperty("TestFileA.foo"));
assertEquals("BBB", System.getProperty("TestFileB.foo"));
}
finally
{
System.clearProperty("TestFileA.foo");
System.clearProperty("TestFileB.foo");
}
}

@Test
Expand All @@ -98,11 +104,15 @@ public void shouldOverrideSystemPropertiesWithConfigFromPropFile()
System.setProperty("TestFileA.foo", "ToBeOverridden");
assertEquals("ToBeOverridden", System.getProperty("TestFileA.foo"));

loadPropertiesFile("TestFileA.properties");

assertEquals("AAA", System.getProperty("TestFileA.foo"));

System.clearProperty("TestFileA.foo");
try
{
loadPropertiesFiles("TestFileA.properties");
assertEquals("AAA", System.getProperty("TestFileA.foo"));
}
finally
{
System.clearProperty("TestFileA.foo");
}
}

@Test
Expand All @@ -111,10 +121,15 @@ public void shouldNotOverrideSystemPropertiesWithConfigFromPropFile()
System.setProperty("TestFileA.foo", "ToBeNotOverridden");
assertEquals("ToBeNotOverridden", System.getProperty("TestFileA.foo"));

loadPropertiesFile(PropertyAction.PRESERVE, "TestFileA.properties");
assertEquals("ToBeNotOverridden", System.getProperty("TestFileA.foo"));

System.clearProperty("TestFileA.foo");
try
{
loadPropertiesFile(PropertyAction.PRESERVE, "TestFileA.properties");
assertEquals("ToBeNotOverridden", System.getProperty("TestFileA.foo"));
}
finally
{
System.clearProperty("TestFileA.foo");
}
}

@Test
Expand Down

0 comments on commit 076d033

Please sign in to comment.