FromEnvironment extends ResolverImp { @Override public String resolve(String s) { if (s == null) { return null; } String result = s; log.trace("Resolving {} from environment variables", s); Matcher m = resolverPattern.matcher(s); while (m.matches()) { String key = m.group(1); log.trace("Resolve on {} ", key); String envValue = resolve(key, System.getenv()); String toReplace = "%env{" + key + "}"; result = result.replace(toReplace, envValue); m = resolverPattern.matcher(result); } return result; } FromEnvironment(); @Override String resolve(String s); @Override boolean canHandle(String value);  }
@Test public void testResolveString() { FromEnvironment resolver = new FromEnvironment(); assertNotEquals("%env{PATH}", resolver.resolve("%env{PATH}")); assertNotEquals("%env{PATH}%env{PATH}", resolver.resolve("%env{PATH}%env{PATH}")); assertEquals("hello", resolver.resolve("hello")); assertEquals("NOT_A_ENVVAR", resolver.resolve("%env{NOT_A_ENVVAR}")); assertNull(resolver.resolve(null)); }