]> source.dussan.org Git - sonarqube.git/commitdiff
Improve quality 501/head
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 9 Sep 2015 09:38:12 +0000 (11:38 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 9 Sep 2015 09:57:38 +0000 (11:57 +0200)
sonar-batch/src/main/java/org/sonar/batch/analysis/package-info.java
sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java

index fb87cb6ffb3f0117692f66a126d936a31aa18a0e..e073bf0b8960d0d3b251c27599a5467516f71a12 100644 (file)
@@ -20,4 +20,4 @@
 @ParametersAreNonnullByDefault
 package org.sonar.batch.analysis;
 
-import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file
+import javax.annotation.ParametersAreNonnullByDefault;
index 63209e39bb5b6b94c663cb46c46ea2558af92fe9..e0677d42f4663d59553d34580cfe583433f6e81d 100644 (file)
@@ -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);
+  }
 }