aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-04-08 10:12:04 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-04-08 10:18:12 +0200
commit5cfd5f674d24b304db1ded615ee371905593fd40 (patch)
tree7ce153fd26820d467ed1775ce5409ca15f71df99 /sonar-plugin-api/src/test
parent7c50d3b8c30dfb6898ed66daee5b04954f9ab5fc (diff)
downloadsonarqube-5cfd5f674d24b304db1ded615ee371905593fd40.tar.gz
sonarqube-5cfd5f674d24b304db1ded615ee371905593fd40.zip
Fix regression during local issue tracking on empty files
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java
index 93f3a8e57d7..9e06a3e9e5c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java
@@ -37,6 +37,7 @@ import java.nio.charset.Charset;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
public class FileMetadataTest {
@@ -224,6 +225,23 @@ public class FileMetadataTest {
}
@Test
+ public void dont_fail_on_empty_file() throws Exception {
+ File tempFile = temp.newFile();
+ FileUtils.write(tempFile, "", Charsets.UTF_8, true);
+
+ DefaultInputFile f = new DefaultInputFile("foo", tempFile.getName());
+ f.setModuleBaseDir(tempFile.getParentFile().toPath());
+ f.setCharset(Charsets.UTF_8);
+ FileMetadata.computeLineHashesForIssueTracking(f, new LineHashConsumer() {
+
+ @Override
+ public void consume(int lineIdx, @Nullable byte[] hash) {
+ fail("File is empty and should not report any line hash");
+ }
+ });
+ }
+
+ @Test
public void should_throw_if_file_does_not_exist() throws Exception {
File tempFolder = temp.newFolder();
File file = new File(tempFolder, "doesNotExist.txt");