diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-14 14:35:07 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-14 14:36:11 +0200 |
commit | d3dabdf2d3a0cee75abd0559b4a3147938cc5f0c (patch) | |
tree | 6794dc46061f3a5516d8445d9a46fc92cf9ba884 | |
parent | bb004b10dbe983c8042713de7ffb91429419f6ab (diff) | |
download | sonarqube-d3dabdf2d3a0cee75abd0559b4a3147938cc5f0c.tar.gz sonarqube-d3dabdf2d3a0cee75abd0559b4a3147938cc5f0c.zip |
SONAR-6253 Publish data for test files
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java | 3 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java | 17 |
2 files changed, 18 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java b/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java index 9abeedcab43..5fe13a1c89a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/BatchResource.java @@ -19,6 +19,7 @@ */ package org.sonar.batch.index; +import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.fs.InputPath; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Qualifiers; @@ -87,7 +88,7 @@ public class BatchResource { } public boolean isFile() { - return Qualifiers.isFile(r); + return Qualifiers.isFile(r) || StringUtils.equals(Qualifiers.UNIT_TEST_FILE, r.getQualifier()); } public boolean isDir() { diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java index e9b379a58e2..42108b08d86 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java @@ -28,6 +28,7 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; +import org.sonar.api.resources.Qualifiers; import org.sonar.batch.index.ResourceCache; import org.sonar.batch.protocol.output.BatchReportWriter; @@ -48,11 +49,14 @@ public class SourcePublisherTest { private BatchReportWriter writer; + private org.sonar.api.resources.File sampleFile; + @Before public void prepare() throws IOException { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); ResourceCache resourceCache = new ResourceCache(); - org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"); + sampleFile = org.sonar.api.resources.File.create("src/Foo.php"); + sampleFile.setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2)); File baseDir = temp.newFolder(); sourceFile = new File(baseDir, "src/Foo.php"); @@ -83,6 +87,17 @@ public class SourcePublisherTest { } @Test + public void publishTestSource() throws Exception { + FileUtils.write(sourceFile, "1\n2\n3\n4\n", Charsets.ISO_8859_1); + sampleFile.setQualifier(Qualifiers.UNIT_TEST_FILE); + + publisher.publish(writer); + + File out = writer.getSourceFile(2); + assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("1\n2\n3\n4\n"); + } + + @Test public void publishSourceWithLastLineNotEmpty() throws Exception { FileUtils.write(sourceFile, "1\n2\n3\n4\n5", Charsets.ISO_8859_1); |