Template { public String process(String str) { StringBuilder sb = new StringBuilder(); for (String line : str.split("\r?\n")) { if (line.startsWith("#include ")) { String resource = line.substring(9); String resourceStr = load(resource); sb.append(resourceStr); } else { sb.append(line).append('\n'); } } return sb.toString(); } Template(); String process(String str); String load(String filename); Template add(Function<String, String> fn); Template addInclude(Class<?> clazz);  }
@Test public void testProcess() { Function<String, String> func = (String resource) -> { switch (resource) { case "file2": return FILE2; default: throw new RuntimeException("unknown resource"); } }; String out = new Template() .add(func) .process(FILE1); assertEquals(RESULT, out); }