### Question:
Environment { public static String resolveEnvVars(String input) throws EtiqetException { String res = null; if (!StringUtils.isNullOrEmpty(input)) { Pattern p = Pattern.compile("\\$\\{([\\w\\.]+)\\}|\\$([\\w\\.]+)"); Matcher m = p.matcher(input); StringBuffer sb = new StringBuffer(); resolveEnvVars(m, sb); res = sb.toString().replace("/", File.separator).trim(); } return res; } private  Environment(); static Boolean isEnvVarSet(String key); static String resolveEnvVars(String input); static InputStream fileResolveEnvVars(String path);  }### Answer:
@Test public void testResolveEnvVars() throws EtiqetException { String testString = "$etiqet.directory/extended/path/to/file.ext"; String result = resolveEnvVars(testString); assertFalse(result.contains("${etiqet.directory}")); String etiqetDirectory = System.getProperty("etiqet.directory"); String suffix = "/extended/path/to/file.ext".replaceAll("/", Matcher.quoteReplacement(File.separator)); assertEquals(etiqetDirectory + suffix, result); testString = "${etiqet.directory}"; result = resolveEnvVars(testString); assertFalse(result.contains("${etiqet.directory}")); assertEquals(etiqetDirectory, result); }
@Test public void testResolveEnvVarsException() { String testString = "${MADE_UP_ENV_VAR}/extended/path/to/file.ext"; try { resolveEnvVars(testString); } catch (Exception e) { assertTrue(e instanceof EnvironmentVariableNotFoundException); assertEquals("Environment variable not found: MADE_UP_ENV_VAR", e.getMessage()); } }