JaCoCoSensor implements Sensor { boolean shouldExecuteOnProject() { File report = pathResolver.relativeFile(fileSystem.baseDir(), configuration.getReportPath()); boolean foundReport = report.exists() && report.isFile(); boolean shouldExecute = configuration.shouldExecuteOnProject(foundReport); if (!foundReport && shouldExecute) { JaCoCoExtensions.logger().info("JaCoCoSensor: JaCoCo report not found."); } return shouldExecute; } JaCoCoSensor(JaCoCoConfiguration configuration, GroovyFileSystem fileSystem, PathResolver pathResolver, Settings settings); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context);  }
@Test public void should_Execute_On_Project_only_if_exec_exists() { when(configuration.getReportPath()).thenReturn("ut.exec"); when(pathResolver.relativeFile(any(File.class), eq("ut.exec"))).thenReturn(jacocoExecutionData); assertThat(sensor.shouldExecuteOnProject()).isTrue(); when(pathResolver.relativeFile(any(File.class), eq("ut.exec"))).thenReturn(jacocoExecutionData.getParentFile()); assertThat(sensor.shouldExecuteOnProject()).isFalse(); File outputDir = TestUtils.getResource(JaCoCoSensorTest.class, "."); File fakeExecFile = new File(outputDir, "ut.not.found.exec"); when(pathResolver.relativeFile(any(File.class), eq("ut.exec"))).thenReturn(fakeExecFile); assertThat(sensor.shouldExecuteOnProject()).isFalse(); when(pathResolver.relativeFile(any(File.class), eq("ut.exec"))).thenReturn(fakeExecFile); when(configuration.shouldExecuteOnProject(false)).thenReturn(true); assertThat(sensor.shouldExecuteOnProject()).isTrue(); }