import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.security.SecureRandom;
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
@Test
public void test_md5_hash() {
assertThat(hash("sonar")).isEqualTo("d85e336d61f5344395c42126fac239bc");
}
@Test
- public void fail_if_file_does_not_exist() {
+ public void fail_if_file_does_not_exist() throws IOException {
+ File file = temp.newFile("does_not_exist");
+ FileUtils.forceDelete(file);
+
thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Fail to compute hash of: /does/not/exist");
+ thrown.expectMessage("Fail to compute hash of: " + file.getAbsolutePath());
+
- new FileHashes().of(new File("/does/not/exist"));
+ new FileHashes().of(file);
}
@Test