aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-10-11 14:24:20 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-10-11 14:25:15 +0200
commit401abbe560aa06d5e3a4668f14cd0c646eea40af (patch)
treec730ae08a939fd7168b873255123b1cc08f15152 /plugins
parent8dc4c5a4b9b200324f3ad135fae77c432e88b891 (diff)
downloadsonarqube-401abbe560aa06d5e3a4668f14cd0c646eea40af.tar.gz
sonarqube-401abbe560aa06d5e3a4668f14cd0c646eea40af.zip
Fix SourceScannerTest in order to use existing files
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java2
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java24
2 files changed, 16 insertions, 10 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java
index 0f3f06e185b..986271f1bd5 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java
@@ -106,7 +106,7 @@ public final class SourceScanner implements Sensor {
* This method is necessary because Java resources are not treated as every other resource...
*/
private String resolveComponent(File inputFile, List<File> sourceDirs, Project project, boolean isTest) {
- Resource resource = null;
+ Resource resource;
if (Java.KEY.equals(project.getLanguageKey()) && Java.isJavaFile(inputFile)) {
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java
index 10e62084d0c..02a169b7f67 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java
@@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -71,6 +72,9 @@ public class SourceScannerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
@Before
public void init() {
MockitoAnnotations.initMocks(this);
@@ -154,16 +158,17 @@ public class SourceScannerTest {
}
@Test
- public void shouldAnalyseOtherProject() throws IOException {
- File sourceFile = new File("Foo.php");
- File testFile = new File("FooTest.php");
+ public void shouldAnalyseOtherProject() throws Exception {
+ File rootDir = temp.newFolder();
+ File sourceFile = new File(rootDir, "Foo.php");
+ File testFile = new File(rootDir, "FooTest.php");
when(project.getLanguageKey()).thenReturn("php");
when(fileSystem.files(Mockito.isA(FileQuery.class)))
.thenReturn(Arrays.asList(sourceFile))
.thenReturn(Arrays.asList(testFile));
- when(fileSystem.sourceDirs()).thenReturn(ImmutableList.of(new File("")));
- when(fileSystem.testDirs()).thenReturn(ImmutableList.of(new File("")));
+ when(fileSystem.sourceDirs()).thenReturn(ImmutableList.of(rootDir));
+ when(fileSystem.testDirs()).thenReturn(ImmutableList.of(rootDir));
when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true);
scanner.analyse(project, null);
@@ -178,16 +183,17 @@ public class SourceScannerTest {
@Test
public void shouldAnalyseJavaProjectWithNonJavaFile() throws IOException {
- File sourceFile = new File("src/main/java/Foo.java");
- File otherFile = new File("other.js");
+ File rootDir = temp.newFolder();
+ File sourceFile = new File(rootDir, "src/main/java/Foo.java");
+ File otherFile = new File(rootDir, "other.js");
when(project.getLanguageKey()).thenReturn("java");
List<File> empty = Collections.emptyList();
when(fileSystem.files(Mockito.isA(FileQuery.class)))
.thenReturn(Arrays.asList(sourceFile, otherFile))
.thenReturn(empty);
- when(fileSystem.sourceDirs()).thenReturn(ImmutableList.of(new File("src/main/java"), new File("")));
- when(fileSystem.testDirs()).thenReturn(ImmutableList.of(new File("src/test/java")));
+ when(fileSystem.sourceDirs()).thenReturn(ImmutableList.of(new File(rootDir, "src/main/java"), rootDir));
+ when(fileSystem.testDirs()).thenReturn(ImmutableList.of(new File(rootDir, "src/test/java")));
when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true);
scanner.analyse(project, null);