aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-home/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-09-09 11:38:12 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-09-09 11:57:38 +0200
commit1d99d78844ccc3efe9400b89d3bd73f1c1c0404a (patch)
tree31edd074744833c1d479674757e0e5d17712fd87 /sonar-home/src/test
parent49ef17cd091692c3831bdea6759a673d0c9cad64 (diff)
downloadsonarqube-1d99d78844ccc3efe9400b89d3bd73f1c1c0404a.tar.gz
sonarqube-1d99d78844ccc3efe9400b89d3bd73f1c1c0404a.zip
Improve quality
Diffstat (limited to 'sonar-home/src/test')
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java b/sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java
index 63209e39bb5..e0677d42f46 100644
--- a/sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java
+++ b/sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java
@@ -33,6 +33,8 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.security.SecureRandom;
import static org.assertj.core.api.Assertions.assertThat;
@@ -60,11 +62,18 @@ public class FileHashesTest {
String random = randomString();
assertThat(hash(random)).as(random).isEqualTo(
DigestUtils.md5Hex(random).toLowerCase()
- );
+ );
}
}
@Test
+ public void test_hash_file() throws IOException {
+ File f = temp.newFile();
+ Files.write(f.toPath(), "sonar".getBytes(StandardCharsets.UTF_8));
+ assertThat(hashFile(f)).isEqualTo("d85e336d61f5344395c42126fac239bc");
+ }
+
+ @Test
public void test_toHex() {
// lower-case
assertThat(FileHashes.toHex("aloa_bi_bop_a_loula".getBytes())).isEqualTo("616c6f615f62695f626f705f615f6c6f756c61");
@@ -74,7 +83,7 @@ public class FileHashesTest {
String random = randomString();
assertThat(FileHashes.toHex(random.getBytes())).as(random).isEqualTo(
Hex.encodeHexString(random.getBytes()).toLowerCase()
- );
+ );
}
}
@@ -86,7 +95,6 @@ public class FileHashesTest {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Fail to compute hash of: " + file.getAbsolutePath());
-
new FileHashes().of(file);
}
@@ -112,4 +120,8 @@ public class FileHashesTest {
IOUtils.closeQuietly(in);
}
}
+
+ private String hashFile(File f) {
+ return new FileHashes().of(f);
+ }
}