@Test public void testAnalyseEmptySourceFiles() { File fakeFile = new File("fake.php"); ModuleFileSystem localFs = mock(ModuleFileSystem.class); when(fs.sourceDirs()).thenReturn(ImmutableList.of(new File("fake/directory/"))); when(fs.files(any(FileQuery.class))).thenReturn(ImmutableList.of(fakeFile, new File("fake"))); NoSonarAndCommentedOutLocSensor localSensor = new NoSonarAndCommentedOutLocSensor(localFs, noSonarFilter); localSensor.analyse(project, context); verify(context, never()) .saveMeasure( any(Resource.class), any(org.sonar.api.measures.Metric.class), any(Double.class)); }
@Test public void testAnalyse() { File phpFile = TestUtils.getResource("/Mail.php"); when(fs.sourceDirs()).thenReturn(ImmutableList.of(phpFile.getParentFile())); when(fs.files(any(FileQuery.class))) .thenReturn(ImmutableList.of(TestUtils.getResource("/Mail.php"))); org.sonar.api.resources.File sonarFile = new org.sonar.api.resources.File("Mail.php"); doReturn(sonarFile).when(sensor).getSonarResource(any(Project.class), any(File.class)); sensor.analyse(project, context); // Mail.php contains 9 commented oud code lines. verify(context).saveMeasure(sonarFile, CoreMetrics.COMMENTED_OUT_CODE_LINES, 9d); }