JaCoCoOverallSensor implements Sensor { boolean shouldExecuteOnProject() { File baseDir = fileSystem.baseDir(); File reportUTs = pathResolver.relativeFile(baseDir, configuration.getReportPath()); File reportITs = pathResolver.relativeFile(baseDir, configuration.getItReportPath()); boolean foundOneReport = reportUTs.exists() || reportITs.exists(); boolean shouldExecute = configuration.shouldExecuteOnProject(foundOneReport); if (!foundOneReport && shouldExecute) { JaCoCoExtensions.logger().info("JaCoCoOverallSensor: JaCoCo reports not found."); } return shouldExecute; } 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 should_Execute_On_Project_only_if_at_least_one_exec_exists() { when(configuration.getItReportPath()).thenReturn("it.exec"); when(configuration.getReportPath()).thenReturn("ut.exec"); when(pathResolver.relativeFile(any(File.class), eq("it.exec"))).thenReturn(jacocoITData); when(pathResolver.relativeFile(any(File.class), eq("ut.exec"))).thenReturn(fakeExecFile()); assertThat(sensor.shouldExecuteOnProject()).isTrue(); when(pathResolver.relativeFile(any(File.class), eq("it.exec"))).thenReturn(fakeExecFile()); when(pathResolver.relativeFile(any(File.class), eq("ut.exec"))).thenReturn(jacocoUTData); assertThat(sensor.shouldExecuteOnProject()).isTrue(); when(pathResolver.relativeFile(any(File.class), eq("it.exec"))).thenReturn(fakeExecFile()); when(pathResolver.relativeFile(any(File.class), eq("ut.exec"))).thenReturn(fakeExecFile()); assertThat(sensor.shouldExecuteOnProject()).isFalse(); when(configuration.shouldExecuteOnProject(false)).thenReturn(true); assertThat(sensor.shouldExecuteOnProject()).isTrue(); }