@Test public void testExecute() throws IOException { SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); ctxTester.fileSystem().setWorkDir(folder.getRoot().toPath()); File baseFile = folder.newFile("sample2.sql"); File resFile = folder.newFile("Coverage.opencoverxml"); FileUtils.write(resFile, "<CoverageSession xmlns:xsd=\"http: + " <Modules><Module>" + "<Classes>\r\n" + "<Class>\r\n" + "<Summary/>\r\n" + "<FullName>sample2</FullName><Methods> \r\n" + "<Method>\r\n" + "<Summary />\r\n" + "<SequencePoints>\r\n" + " <SequencePoint vc=\"1\" uspid=\"1\" ordinal=\"1\" offset=\"112\" sl=\"1\" sc=\"2\" el=\"8\" ec=\"59\" />\r\n" + " <SequencePoint vc=\"0\" uspid=\"2\" ordinal=\"2\" offset=\"178\" sl=\"2\" sc=\"2\" el=\"10\" ec=\"22\" />\r\n" + " <SequencePoint vc=\"0\" uspid=\"3\" ordinal=\"3\" offset=\"204\" sl=\"3\" sc=\"4\" el=\"11\" ec=\"12\" />\r\n" + " <SequencePoint vc=\"0\" uspid=\"4\" ordinal=\"4\" offset=\"219\" sl=\"4\" sc=\"2\" el=\"13\" ec=\"10\" />\r\n" + " </SequencePoints>\r\n" + " </Method>\r\n" + "</Methods>\r\n" + "</Class></Classes>\r\n" + " </Module></Modules>" + "</CoverageSession>", Charset.defaultCharset()); FileUtils.copyURLToFile(getClass().getResource("/tsql/sample2.sql"), baseFile); String contents = new String(Files.readAllBytes(baseFile.toPath())); DefaultInputFile ti = new TestInputFileBuilder("test", folder.getRoot(), baseFile).initMetadata(contents) .setLanguage(Constants.languageKey).setContents(contents).build(); ctxTester.fileSystem().add(ti); SqlCoverCoverageSensor s = new SqlCoverCoverageSensor(); s.execute(ctxTester); Assert.assertEquals(1, (int) ctxTester.lineHits("test:sample2.sql", 1)); Assert.assertEquals(0, (int) ctxTester.lineHits("test:sample2.sql", 2)); }
@Override public void execute(final SensorContext context) { final String coverageFile = context.config().get(Constants.TSQL_SQLCOVER_PATH) .orElse(Constants.TSQL_SQLCOVER_PATH_DEFAULT).toLowerCase(); final String baseDir = context.fileSystem().baseDir().getAbsolutePath(); try { if (Files.exists(Paths.get(coverageFile))) { readCoverageReport(context, Paths.get(coverageFile)); return; } Files.walk(Paths.get(baseDir)).filter( p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(coverageFile)) .forEach(p -> { readCoverageReport(context, p); }); } catch (Exception e) { LOGGER.warn("Unexpected error", e); } }
SqlCoverCoverageSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final String coverageFile = context.config().get(Constants.TSQL_SQLCOVER_PATH) .orElse(Constants.TSQL_SQLCOVER_PATH_DEFAULT).toLowerCase(); final String baseDir = context.fileSystem().baseDir().getAbsolutePath(); try { if (Files.exists(Paths.get(coverageFile))) { readCoverageReport(context, Paths.get(coverageFile)); return; } Files.walk(Paths.get(baseDir)).filter( p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(coverageFile)) .forEach(p -> { readCoverageReport(context, p); }); } catch (Exception e) { LOGGER.warn("Unexpected error", e); } } }
SqlCoverCoverageSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final String coverageFile = context.config().get(Constants.TSQL_SQLCOVER_PATH) .orElse(Constants.TSQL_SQLCOVER_PATH_DEFAULT).toLowerCase(); final String baseDir = context.fileSystem().baseDir().getAbsolutePath(); try { if (Files.exists(Paths.get(coverageFile))) { readCoverageReport(context, Paths.get(coverageFile)); return; } Files.walk(Paths.get(baseDir)).filter( p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(coverageFile)) .forEach(p -> { readCoverageReport(context, p); }); } catch (Exception e) { LOGGER.warn("Unexpected error", e); } }  }
SqlCoverCoverageSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final String coverageFile = context.config().get(Constants.TSQL_SQLCOVER_PATH) .orElse(Constants.TSQL_SQLCOVER_PATH_DEFAULT).toLowerCase(); final String baseDir = context.fileSystem().baseDir().getAbsolutePath(); try { if (Files.exists(Paths.get(coverageFile))) { readCoverageReport(context, Paths.get(coverageFile)); return; } Files.walk(Paths.get(baseDir)).filter( p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(coverageFile)) .forEach(p -> { readCoverageReport(context, p); }); } catch (Exception e) { LOGGER.warn("Unexpected error", e); } }  @Override void describe(SensorDescriptor descriptor); @Override void execute(final SensorContext context); }
SqlCoverCoverageSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final String coverageFile = context.config().get(Constants.TSQL_SQLCOVER_PATH) .orElse(Constants.TSQL_SQLCOVER_PATH_DEFAULT).toLowerCase(); final String baseDir = context.fileSystem().baseDir().getAbsolutePath(); try { if (Files.exists(Paths.get(coverageFile))) { readCoverageReport(context, Paths.get(coverageFile)); return; } Files.walk(Paths.get(baseDir)).filter( p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(coverageFile)) .forEach(p -> { readCoverageReport(context, p); }); } catch (Exception e) { LOGGER.warn("Unexpected error", e); } }  @Override void describe(SensorDescriptor descriptor); @Override void execute(final SensorContext context);  }