diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-20 17:25:28 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-20 17:25:28 +0100 |
commit | 23176256275964c2c5587ac87fd4ce2d50d4fab1 (patch) | |
tree | 93a798f700683e08433c0359b51dfb95d71e4910 /sonar-batch | |
parent | 78c84a41ecaff34417d76dc71e52e4703b253b71 (diff) | |
download | sonarqube-23176256275964c2c5587ac87fd4ce2d50d4fab1.tar.gz sonarqube-23176256275964c2c5587ac87fd4ce2d50d4fab1.zip |
SONAR-926 Add test on file hash
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java | 4 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java index 28e7825ac96..54f7c0e02d9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java @@ -64,14 +64,14 @@ class FileMetadata { if (c == LINE_FEED) { // Ignore i = reader.read(); - lines++; continue; } } if (c == CARRIAGE_RETURN) { afterCR = true; c = LINE_FEED; - } else if (c == LINE_FEED) { + } + if (c == LINE_FEED) { lines++; } md5Digest.update(charToBytesUTF(c)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java index 5af76f92bb1..deb08c8917b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java @@ -121,4 +121,23 @@ public class FileMetadataTest { FileMetadata.INSTANCE.read(file, Charsets.UTF_8); } + + @Test + public void line_feed_is_included_into_hash() throws Exception { + File file1 = temp.newFile(); + FileUtils.write(file1, "foo\nbar\n", Charsets.UTF_8, true); + + // same as file1, except an additional return carriage + File file1a = temp.newFile(); + FileUtils.write(file1a, "foo\r\nbar\n", Charsets.UTF_8, true); + + File file2 = temp.newFile(); + FileUtils.write(file2, "foo\nbar", Charsets.UTF_8, true); + + String hash1 = FileMetadata.INSTANCE.read(file1, Charsets.UTF_8).hash; + String hash1a = FileMetadata.INSTANCE.read(file1a, Charsets.UTF_8).hash; + String hash2 = FileMetadata.INSTANCE.read(file2, Charsets.UTF_8).hash; + assertThat(hash1).isEqualTo(hash1a); + assertThat(hash1).isNotEqualTo(hash2); + } } |