aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-testing-harness
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-testing-harness')
-rw-r--r--sonar-testing-harness/pom.xml4
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java52
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java45
3 files changed, 3 insertions, 98 deletions
diff --git a/sonar-testing-harness/pom.xml b/sonar-testing-harness/pom.xml
index ebab6e6459e..65d7a16745a 100644
--- a/sonar-testing-harness/pom.xml
+++ b/sonar-testing-harness/pom.xml
@@ -49,9 +49,5 @@
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
- <dependency>
- <groupId>xmlunit</groupId>
- <artifactId>xmlunit</artifactId>
- </dependency>
</dependencies>
</project>
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 3b4d68448ca..eedcee75337 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,22 +19,16 @@
*/
package org.sonar.test;
-import com.google.common.base.Throwables;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharUtils;
import org.apache.commons.lang.StringUtils;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
import org.sonar.api.utils.SonarException;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import static org.junit.Assert.assertTrue;
-
/**
* Utilities for unit tests
*
@@ -90,50 +84,4 @@ public final class TestUtils {
resourcePath += path;
return getResource(resourcePath);
}
-
- /**
- * Shortcut for getTestTempDir(baseClass, testName, true) : cleans the unit test directory
- */
- public static File getTestTempDir(Class baseClass, String testName) {
- return getTestTempDir(baseClass, testName, true);
- }
-
- /**
- * Create a temporary directory for unit tests.
- *
- * @param baseClass the unit test class
- * @param testName the test name
- * @param clean remove all the sub-directories and files ?
- */
- public static File getTestTempDir(Class baseClass, String testName, boolean clean) {
- File dir = new File("target/test-tmp/" + baseClass.getCanonicalName() + "/" + testName);
- if (clean && dir.exists()) {
- try {
- FileUtils.deleteDirectory(dir);
- } catch (IOException e) {
- throw new SonarException("Can not delete the directory " + dir, e);
- }
- }
- try {
- FileUtils.forceMkdir(dir);
- } catch (IOException e) {
- throw new SonarException("Can not create the directory " + dir, e);
- }
- return dir;
- }
-
- public static void assertSimilarXml(String expectedXml, String xml) {
- Diff diff = isSimilarXml(expectedXml, xml);
- String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
- assertTrue(message, diff.similar());
- }
-
- static Diff isSimilarXml(String expectedXml, String xml) {
- XMLUnit.setIgnoreWhitespace(true);
- try {
- return XMLUnit.compareXML(xml, expectedXml);
- } catch (Exception e) {
- throw Throwables.propagate(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 0f44c7443f7..54a0d903357 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
@@ -19,16 +19,12 @@
*/
package org.sonar.test;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.sonar.test.TestUtils.assertSimilarXml;
-import static org.sonar.test.TestUtils.getResource;
-import static org.sonar.test.TestUtils.getTestTempDir;
-import static org.sonar.test.TestUtils.isSimilarXml;
+import org.junit.Test;
import java.io.File;
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.sonar.test.TestUtils.getResource;
public class TestUtilsTest {
@@ -49,39 +45,4 @@ public class TestUtilsTest {
File file = getResource("org/sonar/test/TestUtilsTest/unknown.txt");
assertThat(file).isNull();
}
-
- @Test
- public void testTempDir() throws Exception {
- File dir = getTestTempDir(getClass(), "testTempDir");
- assertThat(dir).exists().isDirectory();
- assertThat(dir.listFiles()).isEmpty();
-
- FileUtils.writeStringToFile(new File(dir, "bar.txt"), "some text");
- assertThat(dir.listFiles()).hasSize(1);
-
- // the directory is cleaned
- dir = getTestTempDir(getClass(), "testTempDir");
- assertThat(dir).exists().isDirectory();
- assertThat(dir.listFiles()).isEmpty();
- }
-
- @Test
- public void testAssertSimilarXml() throws Exception {
- assertSimilarXml("<foo></foo>", "<foo />");
-
- // order of attributes
- assertSimilarXml("<foo><bar id='1' key='one' /></foo>", "<foo><bar key='one' id='1' /></foo>");
-
- // whitespaces are ignored
- assertSimilarXml("<foo> <bar /> </foo>", "<foo><bar/></foo>");
-
- // attribute values are checked
- assertThat(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()).isFalse();
-
- // different xml
- assertThat(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()).isFalse();
-
- // order of nodes is important
- assertThat(isSimilarXml("<foo><bar id='1' /><bar id='2' /></foo>", "<foo><bar id='2' /><bar id='1' /></foo>").similar()).isFalse();
- }
}