]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2291 Fix unit test on Windows
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 11 Feb 2013 14:52:39 +0000 (15:52 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 11 Feb 2013 14:52:39 +0000 (15:52 +0100)
sonar-home/src/test/java/org/sonar/home/cache/FileHashesTest.java

index e7d7ed98d76ec928fc8fd8f04ec816f2f121d277..c2cd589602abd35eaa55e21d1dfbbca4ee7439d8 100644 (file)
@@ -21,13 +21,16 @@ package org.sonar.home.cache;
 
 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;
@@ -45,6 +48,9 @@ public class FileHashesTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
   @Test
   public void test_md5_hash() {
     assertThat(hash("sonar")).isEqualTo("d85e336d61f5344395c42126fac239bc");
@@ -73,11 +79,15 @@ public class FileHashesTest {
   }
 
   @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