JaCoCoOverallSensor implements Sensor { @Override public void execute(SensorContext context) { File reportUTs = pathResolver.relativeFile(fileSystem.baseDir(), configuration.getReportPath()); File reportITs = pathResolver.relativeFile(fileSystem.baseDir(), configuration.getItReportPath()); if (shouldExecuteOnProject()) { File reportOverall = new File(context.fileSystem().workDir(), JACOCO_OVERALL); reportOverall.getParentFile().mkdirs(); JaCoCoReportMerger.mergeReports(reportOverall, reportUTs, reportITs); new OverallAnalyzer(reportOverall).analyse(context); } } JaCoCoOverallSensor(JaCoCoConfiguration configuration, GroovyFileSystem fileSystem, PathResolver pathResolver, Settings settings); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); static final String JACOCO_OVERALL; }
@Test public void test_read_execution_data_with_IT_and_UT() { setMocks(true, true); sensor.execute(context); int[] oneHitlines = {9, 10, 14, 15, 17, 21, 25, 29, 32, 33, 42, 47}; int[] zeroHitlines = {30, 38}; int[] conditionLines = {14, 29, 30}; int[] coveredConditions = {2, 1, 0}; verifyOverallMetrics(context, zeroHitlines, oneHitlines, conditionLines, coveredConditions); }
@Test public void test_read_execution_data_with_IT_and_UT_and_binaryDirs_being_absolute() { setMocks(true, true); settings.setProperty(GroovyPlugin.SONAR_GROOVY_BINARIES, jacocoUTData.getParentFile().getAbsolutePath()); sensor.execute(context); int[] oneHitlines = {9, 10, 14, 15, 17, 21, 25, 29, 32, 33, 42, 47}; int[] zeroHitlines = {30, 38}; int[] conditionLines = {14, 29, 30}; int[] coveredConditions = {2, 1, 0}; verifyOverallMetrics(context, zeroHitlines, oneHitlines, conditionLines, coveredConditions); }
@Test public void test_read_execution_data_with_only_UT() { setMocks(true, false); sensor.execute(context); int[] oneHitlines = {9, 10, 14, 15, 17, 21, 29, 32, 33, 42, 47}; int[] zeroHitlines = {25, 30, 38}; int[] conditionLines = {14, 29, 30}; int[] coveredConditions = {2, 1, 0}; verifyOverallMetrics(context, zeroHitlines, oneHitlines, conditionLines, coveredConditions); }
@Test public void test_read_execution_data_with_only_IT() { setMocks(false, true); sensor.execute(context); int[] oneHitlines = {9, 10, 25}; int[] zeroHitlines = {14, 15, 17, 21, 29, 30, 32, 33, 38, 42, 47}; int[] conditionLines = {14, 29, 30}; int[] coveredConditions = {0, 0, 0}; verifyOverallMetrics(context, zeroHitlines, oneHitlines, conditionLines, coveredConditions); }