### Question:
Expressions { public static String resolve(final Properties props, final String expression) { if (expression == null) return null; final StringBuilder builder = new StringBuilder(); final char[] chars = expression.toCharArray(); final int len = chars.length; int state = 0; int start = -1; int nameStart = -1; for (int i = 0; i < len; i++) { char ch = chars[i]; switch (state) { case INITIAL: { switch (ch) { case '$': { state = GOT_DOLLAR; continue; } default: { builder.append(ch); continue; } } } case GOT_DOLLAR: { switch (ch) { case '$': { builder.append(ch); state = INITIAL; continue; } case '{': { start = i + 1; nameStart = start; state = GOT_OPEN_BRACE; continue; } default: { builder.append('$').append(ch); state = INITIAL; continue; } } } case GOT_OPEN_BRACE: { switch (ch) { case ':': case '}': case ',': { final String name = expression.substring(nameStart, i).trim(); final String val; if (name.startsWith("env.")) { val = System.getenv(name.substring(4)); } else if (name.startsWith("sys.")) { val = System.getProperty(name.substring(4)); } else { val = props.getProperty(name); } if (val != null) { builder.append(val); state = ch == '}' ? INITIAL : RESOLVED; continue; } else if (ch == ',') { nameStart = i + 1; continue; } else if (ch == ':') { start = i + 1; state = DEFAULT; continue; } else { builder.append(expression.substring(start - 2, i + 1)); state = INITIAL; continue; } } default: { continue; } } } case RESOLVED: { if (ch == '}') { state = INITIAL; } continue; } case DEFAULT: { if (ch == '}') { state = INITIAL; builder.append(expression.substring(start, i)); } continue; } default: throw new IllegalStateException(); } } switch (state) { case GOT_DOLLAR: { builder.append('$'); break; } case DEFAULT: case GOT_OPEN_BRACE: { builder.append(expression.substring(start - 2)); break; } } return builder.toString(); }  static String resolve(final Properties props, final String expression);  }### Answer:
@Test public void testEnvironmentVariables() throws Exception { Assert.assertEquals("envValue", Expressions.resolve(PROPERTIES, "${env.JBOSS_LOGGING_TEST_VAR}")); Assert.assertEquals("defaultValue", Expressions.resolve(PROPERTIES, "${env.JBOSS_LOGGING_TEST_INVALID:defaultValue}")); }
@Test public void testSystemProperties() { Assert.assertEquals(System.getProperty("user.home"), Expressions.resolve(PROPERTIES, "${sys.user.home}")); Assert.assertEquals("sysValue", Expressions.resolve(PROPERTIES, "${sys.test.property}")); Assert.assertEquals("defaultValue", Expressions.resolve(PROPERTIES, "${sys.invalid.property:defaultValue}")); }
@Test public void testProperties() { Assert.assertEquals("test property value", Expressions.resolve(PROPERTIES, "${test.property}")); Assert.assertEquals("defaultValue", Expressions.resolve(PROPERTIES, "${invalid.property:defaultValue}")); }