diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-11-30 18:09:03 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-11-30 18:09:03 +0100 |
commit | 45bf3e6974a3c664d920fc34783dabb1268a6039 (patch) | |
tree | f92154fa09ea45be577d2879886e0fc93d93a7a4 /sonar-testing-harness | |
parent | 7aa79a9d7cd5cfb25c479a53349adf1e86a7ee22 (diff) | |
download | sonarqube-45bf3e6974a3c664d920fc34783dabb1268a6039.tar.gz sonarqube-45bf3e6974a3c664d920fc34783dabb1268a6039.zip |
Shared elasticsearch instance for server tests
Diffstat (limited to 'sonar-testing-harness')
-rw-r--r-- | sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java | 12 | ||||
-rw-r--r-- | sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java index c8522ec3ed8..31e9e24cfef 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java @@ -90,4 +90,16 @@ public final class TestUtils { } return ok; } + + public static File newTempDir(String prefix) { + try { + // Technique to create a temp directory from a temp file + File f = File.createTempFile(prefix, ""); + f.delete(); + f.mkdir(); + return f; + } catch (Exception e) { + throw new IllegalStateException("Fail to create temp dir", e); + } + } } diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java index f06d434441c..f8c28887553 100644 --- a/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java +++ b/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java @@ -60,6 +60,18 @@ public class TestUtilsTest { } } + @Test + public void newTempDir() throws Exception { + File dir1 = TestUtils.newTempDir("foo"); + assertThat(dir1).exists().isDirectory(); + assertThat(dir1.listFiles()).isEmpty(); + + File dir2 = TestUtils.newTempDir("foo"); + assertThat(dir2).exists().isDirectory(); + assertThat(dir2.listFiles()).isEmpty(); + assertThat(dir2.getCanonicalPath()).isNotEqualTo(dir1.getCanonicalPath()); + } + public static class OnlyPrivateConstructors { private OnlyPrivateConstructors() { } |