### Question:
CompilableFile { public byte[] compile(final ThemeArchive.ThemeModifier modifier) { final LessCompiler lessCompiler = new LessCompiler(); lessCompiler.setEncoding("UTF-8"); File file = modifier.resolve(input); if (!Files.exists(file.toPath())) { LOGGER.warning(format("Theme compilation failure. File <%s> not found", file)); return new byte[0]; } try { final byte[] compilation = lessCompiler.compile(file).getBytes("UTF-8"); modifier.add(output, compilation); return compilation; } catch (final LessException | IOException e) { throw new LessCompilationException("Failed to compile " + input, e); } } CompilableFile(final String input, final String output); byte[] compile(final ThemeArchive.ThemeModifier modifier); static final CompilableFile[] ALWAYS_COMPILED_FILES; }### Answer:
@Test public void should_compile_less_into_css() throws Exception { final File lessStyle = directory.newFile("style.less"); FileUtils.writeStringToFile(lessStyle, "@myvar:1px;body{width:@myvar}"); given(modifier.resolve("style.less")).willReturn(lessStyle); final byte[] compilation = new CompilableFile("style.less", "style.css").compile(modifier); assertThat(new String(compilation, "UTF-8").replace("\r", "")).isEqualTo("body {\n width: 1px;\n}\n\n"); }
@Test public void should_add_compiled_file_to_compile_less_into_css() throws Exception { final File lessStyle = directory.newFile("style.less"); given(modifier.resolve("style.less")).willReturn(lessStyle); new CompilableFile("style.less", "style.css").compile(modifier); final byte[] emptyExpectedFile = System.lineSeparator().getBytes(); verify(modifier).add("style.css", emptyExpectedFile); }
@Test public void should_not_fail_when_file_is_missing() throws Exception { given(modifier.resolve("style.less")).willReturn(new File("style.less")); new CompilableFile("style.less", "style.css").compile(modifier); }
@Test(expected = LessCompilationException.class) public void should_throw_LessCompilationException_when_fail_to_compile_input_file() throws Exception { final File lessStyle = directory.newFile("style.less"); FileUtils.writeStringToFile(lessStyle, "not compilable content"); given(modifier.resolve("style.less")).willReturn(lessStyle); new CompilableFile("style.less", "style.css").compile(modifier); }