@Test public void testShouldNotRunOnJavaProject() { when(fs.files(any(FileQuery.class))).thenReturn(ImmutableList.<java.io.File>of()); assertThat(sensor.shouldExecuteOnProject(null)).isFalse(); when(fs.files(any(FileQuery.class))).thenReturn(ImmutableList.of(new java.io.File("file.php"))); assertThat(sensor.shouldExecuteOnProject(null)).isTrue(); }
@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); }
@Before public void init() throws ScmException { when(moduleFileSystem.baseDir()).thenReturn(projectBaseDir); when(changeLog.getChangeLog()).thenReturn(changeLogSet); when(changeLogSet.getChangeSets()).thenReturn(changeSets); when(scmFacade.getChangeLog(projectBaseDir, datefrom.toDate(), dateTo.toDate())) .thenReturn(changeLog); when(fileExclusions.sourceExclusions()).thenReturn(new String[0]); when(fileExclusions.sourceInclusions()).thenReturn(new String[0]); }
@Override public void decorate(Resource resource, DecoratorContext context) { if (!ResourceUtils.isPersistable(resource)) { return; } File path = null; if (ResourceUtils.isProject(resource)) { path = fs.baseDir(); } else if (resource.getPath() != null) { path = new File(fs.baseDir(), resource.getPath()); } ResourceNode resourceNode = new ResourceNode(resource, path, fs.sourceCharset()); RESOURCE_BY_KEY.put(resource.getEffectiveKey(), resourceNode); for (DecoratorContext childContext : context.getChildren()) { Resource child = childContext.getResource(); ResourceNode childNode = RESOURCE_BY_KEY.get(child.getEffectiveKey()); if (childNode != null) { resourceNode.addChild(childNode); } } }