### Question:
PmdSensor implements Sensor { @Override public boolean shouldExecuteOnProject(Project project) { return (hasFilesToCheck(Type.MAIN, PmdConstants.REPOSITORY_KEY)) || (hasFilesToCheck(Type.TEST, PmdConstants.TEST_REPOSITORY_KEY)) || (hasFilesToCheck(Type.MAIN, PmdConstants.XML_REPOSITORY_KEY)); } PmdSensor(RulesProfile profile, PmdExecutor executor, PmdViolationRecorder pmdViolationRecorder, FileSystem fs); @Override boolean shouldExecuteOnProject(Project project); @Override void analyse(Project project, SensorContext context); @Override String toString();  }### Answer:
@Test public void should_execute_on_project_without_main_files() { addOneJavaFile(Type.TEST); boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project); assertThat(shouldExecute).isTrue(); }
@Test public void should_execute_on_project_without_test_files() { addOneJavaFile(Type.MAIN); addOneXmlFile(Type.MAIN); boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project); assertThat(shouldExecute).isTrue(); }
@Test public void should_not_execute_on_project_without_any_files() { boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project); assertThat(shouldExecute).isFalse(); }
@Test public void should_not_execute_on_project_without_active_rules() { addOneJavaFile(Type.MAIN); addOneJavaFile(Type.TEST); when(profile.getActiveRulesByRepository(PmdConstants.REPOSITORY_KEY).isEmpty()).thenReturn(true); when(profile.getActiveRulesByRepository(PmdConstants.TEST_REPOSITORY_KEY).isEmpty()).thenReturn(true); boolean shouldExecute = pmdSensor.shouldExecuteOnProject(project); assertThat(shouldExecute).isFalse(); }