@Test public void testResolvesSingleExistingTemplate() throws IOException { templateProperties.setNames("whatever"); when(templateEngine.process(eq("whatever"), any(Context.class))) .thenReturn("success"); service.resolve(); Path out = Paths.get(projectDir, "build", "nginx.yaml"); assertThat(Files.exists(out), is(true)); boolean isPresent = Files.lines(out) .map(String::trim) .filter(line -> line.equalsIgnoreCase("success")) .findAny() .isPresent(); assertThat(isPresent, is(true)); }
public void resolve() throws IOException { Context context = new Context(); templateProperties.getNames().stream() .map(template -> { try { return templateEngine.process(template, context); } catch (RuntimeException e) { log.warn("Failed to process template: {}.", template, e); return ""; } }) .filter(result -> !result.isEmpty()) .findFirst() .ifPresent(result -> { String output = templateProperties.getOutput(); if (output.equalsIgnoreCase("console")) { System.out.println(result); } else { Path p = Paths.get(output); try { deleteIfExists(p); write(p, result.getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } } }); }
TemplateResolverService { public void resolve() throws IOException { Context context = new Context(); templateProperties.getNames().stream() .map(template -> { try { return templateEngine.process(template, context); } catch (RuntimeException e) { log.warn("Failed to process template: {}.", template, e); return ""; } }) .filter(result -> !result.isEmpty()) .findFirst() .ifPresent(result -> { String output = templateProperties.getOutput(); if (output.equalsIgnoreCase("console")) { System.out.println(result); } else { Path p = Paths.get(output); try { deleteIfExists(p); write(p, result.getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } } }); } }
TemplateResolverService { public void resolve() throws IOException { Context context = new Context(); templateProperties.getNames().stream() .map(template -> { try { return templateEngine.process(template, context); } catch (RuntimeException e) { log.warn("Failed to process template: {}.", template, e); return ""; } }) .filter(result -> !result.isEmpty()) .findFirst() .ifPresent(result -> { String output = templateProperties.getOutput(); if (output.equalsIgnoreCase("console")) { System.out.println(result); } else { Path p = Paths.get(output); try { deleteIfExists(p); write(p, result.getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } } }); }  }
TemplateResolverService { public void resolve() throws IOException { Context context = new Context(); templateProperties.getNames().stream() .map(template -> { try { return templateEngine.process(template, context); } catch (RuntimeException e) { log.warn("Failed to process template: {}.", template, e); return ""; } }) .filter(result -> !result.isEmpty()) .findFirst() .ifPresent(result -> { String output = templateProperties.getOutput(); if (output.equalsIgnoreCase("console")) { System.out.println(result); } else { Path p = Paths.get(output); try { deleteIfExists(p); write(p, result.getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } } }); }  void resolve(); }
TemplateResolverService { public void resolve() throws IOException { Context context = new Context(); templateProperties.getNames().stream() .map(template -> { try { return templateEngine.process(template, context); } catch (RuntimeException e) { log.warn("Failed to process template: {}.", template, e); return ""; } }) .filter(result -> !result.isEmpty()) .findFirst() .ifPresent(result -> { String output = templateProperties.getOutput(); if (output.equalsIgnoreCase("console")) { System.out.println(result); } else { Path p = Paths.get(output); try { deleteIfExists(p); write(p, result.getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } } }); }  void resolve();  }