### Question:
RotateLogListener extends SimpleLogListener implements Configurable, Destroyable { protected String fileNameFromPattern(String inFileName, String patternCodes) { String[] computedValues; String[] codes = patternCodes.split(","); computedValues = new String[codes.length]; for (int i = 0; i < codes.length; i++) { if (codes[i].equals("h")) { try { computedValues[i] = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { computedValues[i] = "#h"; } } else if (codes[i].startsWith("e")) { try { String envVar = codes[i].substring(2, codes[i].length()-1); computedValues[i] = System.getenv(envVar); } catch (Exception e) { computedValues[i] = "#e"; } } } return String.format(inFileName, (Object[]) computedValues); } RotateLogListener(); void setConfiguration(Configuration cfg); synchronized LogEvent log(LogEvent ev); void logRotate(); synchronized void logRotate(boolean isStartup); void destroy(); static final int CHECK_INTERVAL; static final long DEFAULT_MAXSIZE; }### Answer:
@Test public void testEnvironmentCodeParsing() { Map<String, String> env = System.getenv(); RotateLogListener listener = new RotateLogListener(); Map.Entry<String, String> entry = env.entrySet().iterator().next(); String replaced = listener.fileNameFromPattern("%s-log", "e{" + entry.getKey() + "}"); assertEquals(entry.getValue() + "-log", replaced); }