@Test
public void substituteWithProperties() throws Exception {

    // create test properties
    Properties props = new Properties();
    props.put("TEST1", "Hello World");
    props.put(" TEST1", "whitespace matters");
    props.put("TEST2", "Hello");
    props.put("TEST3", "World");
    // simple substitution
    String result = StringUtil.substituteWithProperties("$ENV{TEST1}", "$ENV{", "}", props);
    Assert.assertEquals("Hello World", result);
    // simple substitution, different delimiters
ult = StringUtil.substituteWithProperties("{{{TEST1}}}", "{{{", "}}}", props);
    Assert.assertEquals("Hello World", result);
    // no substitution
    result = StringUtil.substituteWithProperties("no key here", "$ENV{", "}", props);
    Assert.assertEquals("no key here", result);
    // substitution with text before and after
    result = StringUtil.substituteWithProperties("Yo $ENV{TEST1} this is cool", "$ENV{", "}", props);
    Assert.assertEquals("Yo Hello World this is cool", result);
    // substitution with text before only
    result = StringUtil.substituteWithProperties("Y$ENV{TEST1}", "$ENV{", "}", props);
    Assert.assertEquals("YHello World", result);
    // substitution with text after only
    result = StringUtil.substituteWithProperties("$ENV{TEST1}Y", "$ENV{", "}", props);
    Assert.assertEquals("Hello WorldY", result);
    // key name does not include TRIMMING -- whitespace matters
    result = StringUtil.substituteWithProperties("$ENV{ TEST1}", "$ENV{", "}", props);
    Assert.assertEquals("whitespace matters", result);
    
    // substitution with empty string
    result = StringUtil.substituteWithProperties("", "$ENV{", "}", props);
    Assert.assertEquals("", result);
    // substitution with null
    result = StringUtil.substituteWithProperties(null, "$ENV{", "}", props);
    Assert.assertEquals(null, result);
    // substitution with multiple replacments
    result = StringUtil.substituteWithProperties("$ENV{TEST2}$ENV{TEST3}", "$ENV{", "}", props);
    Assert.assertEquals("HelloWorld", result);
    // substitution with multiple replacments
    result = StringUtil.substituteWithProperties("$ENV{TEST2} $ENV{TEST3}", "$ENV{", "}", props);
    Assert.assertEquals("Hello World", result);
    // substitution with multiple replacments and text before, after
    result = StringUtil.substituteWithProperties("Yo $ENV{TEST2} $ENV{TEST3} dude", "$ENV{", "}", props);
    Assert.assertEquals("Yo Hello World dude", result);
}