Skip to content

Commit

Permalink
Improve quality
Browse files Browse the repository at this point in the history
  • Loading branch information
dbmeneses committed Sep 9, 2015
1 parent 49ef17c commit 1d99d78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
@ParametersAreNonnullByDefault
package org.sonar.batch.analysis;

import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
18 changes: 15 additions & 3 deletions sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
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;
Expand Down Expand Up @@ -60,10 +62,17 @@ public void test_md5_hash() {
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
Expand All @@ -74,7 +83,7 @@ public void test_toHex() {
String random = randomString();
assertThat(FileHashes.toHex(random.getBytes())).as(random).isEqualTo(
Hex.encodeHexString(random.getBytes()).toLowerCase()
);
);
}
}

Expand All @@ -86,7 +95,6 @@ public void fail_if_file_does_not_exist() throws IOException {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Fail to compute hash of: " + file.getAbsolutePath());


new FileHashes().of(file);
}

Expand All @@ -112,4 +120,8 @@ private String hash(String s) {
IOUtils.closeQuietly(in);
}
}

private String hashFile(File f) {
return new FileHashes().of(f);
}
}

0 comments on commit 1d99d78

Please sign in to comment.