From 1d99d78844ccc3efe9400b89d3bd73f1c1c0404a Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 9 Sep 2015 11:38:12 +0200 Subject: Improve quality --- .../test/java/org/sonar/home/cache/FileHashesTest.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'sonar-home/src') 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,10 +62,17 @@ 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 @@ -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); + } } -- cgit v1.2.3