@Test public void testResolveWithEnvVarResolver() { assumeTrue("Environment variable not set as required", System.getenv().containsKey(TEST_ENV_VARIABLE_NAME)); assumeFalse("Environment variable unexpectedly set", System.getenv().containsKey(TEST_ENV_VARIABLE_NAME_NOT_SET)); assertEquals("Environment variable value not as expected", TEST_ENV_VARIABLE_VALUE, System.getenv(TEST_ENV_VARIABLE_NAME)); final Resolver envVarResolver = VariableExpansion.ENV_VAR_RESOLVER; assertNull("Expected resolve to return null as property not set", envVarResolver.resolve(TEST_ENV_VARIABLE_NAME_NOT_SET)); assertEquals("Resolved variable not as expected", TEST_ENV_VARIABLE_VALUE, envVarResolver.resolve(TEST_ENV_VARIABLE_NAME)); }
private static final String resolve(String var, Resolver resolver, Stack<String> stack) { if (stack.contains(var)) { throw new IllegalArgumentException(String.format("Recursively defined variable '%s', stack=%s", var, stack)); } String result = resolver.resolve(var); if (result == null) { throw new UnresolvedVariableException("Unable to resolve variable: " + var); } stack.push(var); try { return expand0(result, resolver, stack); } finally { stack.pop(); } }
VariableExpansion { private static final String resolve(String var, Resolver resolver, Stack<String> stack) { if (stack.contains(var)) { throw new IllegalArgumentException(String.format("Recursively defined variable '%s', stack=%s", var, stack)); } String result = resolver.resolve(var); if (result == null) { throw new UnresolvedVariableException("Unable to resolve variable: " + var); } stack.push(var); try { return expand0(result, resolver, stack); } finally { stack.pop(); } } }
VariableExpansion { private static final String resolve(String var, Resolver resolver, Stack<String> stack) { if (stack.contains(var)) { throw new IllegalArgumentException(String.format("Recursively defined variable '%s', stack=%s", var, stack)); } String result = resolver.resolve(var); if (result == null) { throw new UnresolvedVariableException("Unable to resolve variable: " + var); } stack.push(var); try { return expand0(result, resolver, stack); } finally { stack.pop(); } } private  VariableExpansion(); }
VariableExpansion { private static final String resolve(String var, Resolver resolver, Stack<String> stack) { if (stack.contains(var)) { throw new IllegalArgumentException(String.format("Recursively defined variable '%s', stack=%s", var, stack)); } String result = resolver.resolve(var); if (result == null) { throw new UnresolvedVariableException("Unable to resolve variable: " + var); } stack.push(var); try { return expand0(result, resolver, stack); } finally { stack.pop(); } } private  VariableExpansion(); static final String expand(String input, Resolver resolver); }
VariableExpansion { private static final String resolve(String var, Resolver resolver, Stack<String> stack) { if (stack.contains(var)) { throw new IllegalArgumentException(String.format("Recursively defined variable '%s', stack=%s", var, stack)); } String result = resolver.resolve(var); if (result == null) { throw new UnresolvedVariableException("Unable to resolve variable: " + var); } stack.push(var); try { return expand0(result, resolver, stack); } finally { stack.pop(); } } private  VariableExpansion(); static final String expand(String input, Resolver resolver); static final Resolver ENV_VAR_RESOLVER; static final Resolver SYS_PROP_RESOLVER; }