LibSassCompiler { protected void generateSourceMap(final Output output) { final String sourceMap = output.getSourceMap(); if (StringUtils.isBlank(sourceMap)) { this.logger.info("No sourcemap file to generate"); return; } try { final File sourceMapFile = new File( this.options.getSourceMapFile()); this.logger .info("Write source map file " + sourceMapFile.getPath()); FileUtils.forceMkdir(sourceMapFile.getParentFile()); FileUtils.write(sourceMapFile, sourceMap, StandardCharsets.UTF_8); } catch (final IOException e) { this.logger.error("Error writing source map file", e); } } LibSassCompiler(final Logger logger,
            final PluginParametersProvider parametersProvider); void compileFile();  }
@Test public void generateSourceMap_Generation() throws IOException { final File sourceMapFile = this.folder.newFile(); Mockito.when(this.parametersProvider.getSourceMapUri()) .thenReturn(sourceMapFile.toURI()); final LibSassCompiler compiler = new LibSassCompiler(this.logger, this.parametersProvider); final Output output = new Output(null, "sourceMap"); compiler.generateSourceMap(output); Assert.assertTrue(StringUtils.isNotBlank(FileUtils .readFileToString(sourceMapFile, Charset.defaultCharset()))); Mockito.verify(this.logger, Mockito.never()).error(Mockito.anyString(), Mockito.any(IOException.class)); }
@Test public void generateSourceMap_No_SourceMap() throws IOException { final File sourceMapFile = this.folder.newFile(); Mockito.when(this.parametersProvider.getSourceMapUri()) .thenReturn(sourceMapFile.toURI()); final LibSassCompiler compiler = new LibSassCompiler(this.logger, this.parametersProvider); final Output output = new Output(null, null); compiler.generateSourceMap(output); Assert.assertTrue(StringUtils.isBlank(FileUtils .readFileToString(sourceMapFile, Charset.defaultCharset()))); Mockito.verify(this.logger, Mockito.never()).error(Mockito.anyString(), Mockito.any(IOException.class)); }
@Test public void generateSourceMap_IOException() throws IOException { final File sourceMapFile = new File(""); Mockito.when(this.parametersProvider.getSourceMapUri()) .thenReturn(sourceMapFile.toURI()); final LibSassCompiler compiler = new LibSassCompiler(this.logger, this.parametersProvider); final Output output = new Output(null, "sourceMap"); compiler.generateSourceMap(output); Mockito.verify(this.logger, Mockito.times(1)).error(Mockito.anyString(), Mockito.any(IOException.class)); }