From efd5716474747b6064e3934d5fe3fe35ebca900d Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 11 Feb 2013 15:52:39 +0100 Subject: SONAR-2291 Fix unit test on Windows --- .../test/java/org/sonar/home/cache/FileHashesTest.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'sonar-home') 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 e7d7ed98d76..c2cd589602a 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 @@ -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 -- cgit v1.2.3