diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-19 11:34:08 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-19 11:34:08 +0100 |
commit | ee8c7344ebc104411d623709d08a431b87c86cb7 (patch) | |
tree | c6d47468358d52cbe5e827bc4e2f1e56dddae395 /sonar-testing-harness/src | |
parent | 503a775e7ed95311b9d9bbd40a86449f72c23102 (diff) | |
download | sonarqube-ee8c7344ebc104411d623709d08a431b87c86cb7.tar.gz sonarqube-ee8c7344ebc104411d623709d08a431b87c86cb7.zip |
Clean-up TestUtils
The methods getResource() and newTempDir() are
rarely used and should be moved to the callers
Diffstat (limited to 'sonar-testing-harness/src')
3 files changed, 0 insertions, 80 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 037ac7c3d13..5e579a15ed7 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 @@ -19,13 +19,8 @@ */ package org.sonar.test; -import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; -import java.net.URL; -import java.nio.file.Files; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; /** * Utilities for unit tests @@ -38,39 +33,6 @@ public final class TestUtils { } /** - * Search for a test resource in the classpath. For example getResource("org/sonar/MyClass/foo.txt"); - * - * @param path the starting slash is optional - * @return the resource. Null if resource not found - */ - public static File getResource(String path) { - String resourcePath = path; - if (!resourcePath.startsWith("/")) { - resourcePath = "/" + resourcePath; - } - URL url = TestUtils.class.getResource(resourcePath); - if (url != null) { - return FileUtils.toFile(url); - } - return null; - } - - /** - * Search for a resource in the classpath. For example calling the method getResource(getClass(), "myTestName/foo.txt") from - * the class org.sonar.Foo loads the file $basedir/src/test/resources/org/sonar/Foo/myTestName/foo.txt - * - * @return the resource. Null if resource not found - */ - public static File getResource(Class baseClass, String path) { - String resourcePath = StringUtils.replaceChars(baseClass.getCanonicalName(), '.', '/'); - if (!path.startsWith("/")) { - resourcePath += "/"; - } - resourcePath += path; - return getResource(resourcePath); - } - - /** * Asserts that all constructors are private, usually for helper classes with * only static methods. If a constructor does not have any parameters, then * it's instantiated. @@ -90,12 +52,4 @@ public final class TestUtils { } return ok; } - - public static File newTempDir(String prefix) { - try { - return Files.createTempDirectory(prefix).toFile(); - } 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 d89f8858b35..88f6360a69a 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 @@ -21,33 +21,12 @@ package org.sonar.test; import org.junit.Test; -import java.io.File; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -import static org.sonar.test.TestUtils.getResource; public class TestUtilsTest { @Test - public void testResource() { - File file = getResource("org/sonar/test/TestUtilsTest/getResource/foo.txt"); - assertThat(file).exists(); - - file = getResource("/org/sonar/test/TestUtilsTest/getResource/foo.txt"); - assertThat(file).exists(); - - file = getResource(getClass(), "getResource/foo.txt"); - assertThat(file).exists(); - } - - @Test - public void testResourceNotFound() { - File file = getResource("org/sonar/test/TestUtilsTest/unknown.txt"); - assertThat(file).isNull(); - } - - @Test public void hasOnlyPrivateConstructors() { assertThat(TestUtils.hasOnlyPrivateConstructors(TestUtils.class)).isTrue(); assertThat(TestUtils.hasOnlyPrivateConstructors(OnlyPrivateConstructors.class)).isTrue(); @@ -60,18 +39,6 @@ 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() { } diff --git a/sonar-testing-harness/src/test/resources/org/sonar/test/TestUtilsTest/getResource/foo.txt b/sonar-testing-harness/src/test/resources/org/sonar/test/TestUtilsTest/getResource/foo.txt deleted file mode 100644 index 19102815663..00000000000 --- a/sonar-testing-harness/src/test/resources/org/sonar/test/TestUtilsTest/getResource/foo.txt +++ /dev/null @@ -1 +0,0 @@ -foo
\ No newline at end of file |