@Test
public void testReplaceMultipleKeysWithSysPropAndEnv() {

    // neither env var or sysprop is set - get default
    Assert.assertEquals("abc", StringPropertyReplacer.replaceProperties("${env._DOES_NOT_EXIST_,my.sysprop:abc}"));
    Assert.assertEquals("${env._X_,_x_}", StringPropertyReplacer.replaceProperties("${env._X_,_x_}"));
    // env var set but not sys prop
    Map.Entry<String, String> envvar = System.getenv().entrySet().iterator().next(); // just pick a env var to use
    String envFirst = String.format("${env.%s,my.sysprop:abc}", envvar.getKey());
    String syspropFirst = String.format("${my.sysprop,env.%s:abc}", envvar.getKey());
    String envFirstNoDefault = String.format("${env.%s,my.sysprop}", envvar.getKey());
    String syspropFirstNoDefault = String.format("${my.sysprop,env.%s}", envvar.getKey());
    Assert.assertEquals(envvar.getValue(), StringPropertyReplacer.replaceProperties(envFirst));
    Assert.assertEquals(envvar.getValue(), StringPropertyReplacer.replaceProperties(syspropFirst));
    Assert.assertEquals(envvar.getValue(), StringPropertyReplacer.replaceProperties(envFirstNoDefault));
    Assert.assertEquals(envvar.getValue(), StringPropertyReplacer.replaceProperties(syspropFirstNoDefault));
    // sys prop set but not env var
    System.setProperty("my.sysprop", "xyz");
    envFirst = "${env._DOES_NOT_EXIST_,my.sysprop:abc}";
    syspropFirst = "${my.sysprop,env._DOES_NOT_EXIST_:abc}";
    envFirstNoDefault = "${env._DOES_NOT_EXIST_,my.sysprop}";
    syspropFirstNoDefault = "${my.sysprop,env._DOES_NOT_EXIST_}";
    Assert.assertEquals("xyz", StringPropertyReplacer.replaceProperties(envFirst));
    Assert.assertEquals("xyz", StringPropertyReplacer.replaceProperties(syspropFirst));
    Assert.assertEquals("xyz", StringPropertyReplacer.replaceProperties(envFirstNoDefault));
    Assert.assertEquals("xyz", StringPropertyReplacer.replaceProperties(syspropFirstNoDefault));
    // env var set AND sys prop set
    envFirst = String.format("${env.%s,my.sysprop:abc}", envvar.getKey());
    syspropFirst = String.format("${my.sysprop,env.%s:abc}", envvar.getKey());
    envFirstNoDefault = String.format("${env.%s,my.sysprop}", envvar.getKey());
    syspropFirstNoDefault = String.format("${my.sysprop,env.%s}", envvar.getKey());
    Assert.assertEquals(envvar.getValue(), StringPropertyReplacer.replaceProperties(envFirst));
    Assert.assertEquals("xyz", StringPropertyReplacer.replaceProperties(syspropFirst));
    Assert.assertEquals(envvar.getValue(), StringPropertyReplacer.replaceProperties(envFirstNoDefault));
    Assert.assertEquals("xyz", StringPropertyReplacer.replaceProperties(syspropFirstNoDefault));
    System.clearProperty("my.sysprop");
}