diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-01-23 21:46:20 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-01-23 22:35:31 +0100 |
commit | 078cff8c82b9b3f4bb31f6c014d0bb96f7a1b46a (patch) | |
tree | 922e24dcbb9851acc26d7bef40376f9dc3f786ce /sonar-testing-harness | |
parent | d8a9891950228b8b5d66803e5be1263b756fb9e8 (diff) | |
download | sonarqube-078cff8c82b9b3f4bb31f6c014d0bb96f7a1b46a.tar.gz sonarqube-078cff8c82b9b3f4bb31f6c014d0bb96f7a1b46a.zip |
Sanitize sonar-testing-harness
Diffstat (limited to 'sonar-testing-harness')
5 files changed, 36 insertions, 87 deletions
diff --git a/sonar-testing-harness/pom.xml b/sonar-testing-harness/pom.xml index dc9c9771a19..777d2790c72 100644 --- a/sonar-testing-harness/pom.xml +++ b/sonar-testing-harness/pom.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.codehaus.sonar</groupId> @@ -16,10 +17,6 @@ <artifactId>junit</artifactId> </dependency> <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - </dependency> - <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> </dependency> @@ -32,46 +29,22 @@ <artifactId>xmlunit</artifactId> </dependency> <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - </dependency> - <dependency> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-plugin-api</artifactId> <version>${project.version}</version> </dependency> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <exclusions> - <exclusion> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - </exclusion> - <exclusion> - <groupId>xerces</groupId> - <artifactId>xmlParserAPIs</artifactId> - </exclusion> - <exclusion> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-plugin-api</artifactId> <version>${project.version}</version> - <scope>compile</scope> <type>test-jar</type> </dependency> <dependency> - <groupId>org.reflections</groupId> - <artifactId>reflections</artifactId> + <!-- used only for org.sonar.test.channel classes --> + <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar-channel</artifactId> + <version>${project.version}</version> + <optional>true</optional> </dependency> <dependency> <groupId>com.google.code.findbugs</groupId> 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 55245b5f56b..525583533ac 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,28 +19,24 @@ */ package org.sonar.test; -import com.google.common.base.Charsets; -import com.google.common.io.Resources; +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 org.xml.sax.SAXException; import java.io.File; import java.io.IOException; import java.net.URL; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** * Utilities for unit tests - * + * * @since 2.2 */ public final class TestUtils { @@ -50,7 +46,7 @@ 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 */ @@ -73,7 +69,7 @@ public final class TestUtils { } try { - return Resources.toString(url, Charsets.UTF_8); + return IOUtils.toString(url, Charsets.UTF_8); } catch (IOException e) { throw new SonarException("Can not load the resource: " + path, e); } @@ -82,7 +78,7 @@ public final class TestUtils { /** * 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) { @@ -103,10 +99,10 @@ public final class TestUtils { /** * 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 ? + * @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); @@ -125,14 +121,6 @@ public final class TestUtils { return dir; } - /** - * Checks that a file or a directory is not null and exists. - */ - public static void assertExists(File file) { - assertNotNull(file); - assertThat(file.exists(), is(true)); - } - public static void assertSimilarXml(String expectedXml, String xml) throws Exception { Diff diff = isSimilarXml(expectedXml, xml); String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml; diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java index cb54d191b4c..71a2d11bc3a 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java @@ -19,8 +19,6 @@ */ package org.sonar.test.i18n; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; import org.apache.commons.io.IOUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; @@ -32,6 +30,7 @@ import java.io.InputStream; import java.util.Map; import java.util.Properties; import java.util.SortedMap; +import java.util.TreeMap; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -128,9 +127,8 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> { } } - @VisibleForTesting protected static SortedMap<String, String> retrieveMissingTranslations(InputStream bundle, InputStream referenceBundle) throws IOException { - SortedMap<String, String> missingKeys = Maps.newTreeMap(); + SortedMap<String, String> missingKeys = new TreeMap(); Properties bundleProps = loadProperties(bundle); Properties referenceProperties = loadProperties(referenceBundle); @@ -145,21 +143,18 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> { return missingKeys; } - @VisibleForTesting protected static Properties loadProperties(InputStream inputStream) throws IOException { Properties props = new Properties(); props.load(inputStream); return props; } - @VisibleForTesting protected static InputStream getBundleFileInputStream(String bundleName) { InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + bundleName); assertThat("File '" + bundleName + "' does not exist in '/org/sonar/l10n/'.", bundle, notNullValue()); return bundle; } - @VisibleForTesting protected static InputStream getDefaultBundleFileInputStream(String bundleName) { String defaultBundleName = extractDefaultBundleName(bundleName); InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + defaultBundleName); @@ -167,11 +162,10 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> { return bundle; } - @VisibleForTesting protected static String extractDefaultBundleName(String bundleName) { int firstUnderScoreIndex = bundleName.indexOf('_'); assertThat("The bundle '" + bundleName + "' is a default bundle (without locale), so it can't be compared.", firstUnderScoreIndex > 0, - is(true)); + is(true)); return bundleName.substring(0, firstUnderScoreIndex) + ".properties"; } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java index eaa66a73cf5..665cee1ab40 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java @@ -19,13 +19,13 @@ */ package org.sonar.test.i18n; -import com.google.common.collect.Maps; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.sonar.test.TestUtils; import java.io.File; import java.util.Collection; +import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertThat; @@ -38,7 +38,7 @@ public final class I18nMatchers { /** * Returns a matcher which checks that a translation bundle is up to date with the corresponding default one found in the classpath. - * + * * @return the matcher */ public static BundleSynchronizedMatcher isBundleUpToDate() { @@ -54,8 +54,8 @@ public final class I18nMatchers { fail("No bundle found in: " + BundleSynchronizedMatcher.L10N_PATH); } - Collection<File> bundles = FileUtils.listFiles(bundleFolder, new String[] {"properties"}, false); - Map<String, String> failedAssertionMessages = Maps.newHashMap(); + Collection<File> bundles = FileUtils.listFiles(bundleFolder, new String[]{"properties"}, false); + Map<String, String> failedAssertionMessages = new HashMap(); for (File bundle : bundles) { String bundleName = bundle.getName(); if (bundleName.indexOf('_') > 0) { 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 e9c492e9c7c..8e1737d737b 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,11 +19,7 @@ */ package org.sonar.test; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.sonar.test.TestUtils.assertExists; +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; @@ -39,36 +35,34 @@ public class TestUtilsTest { @Test public void testResource() { File file = getResource("org/sonar/test/TestUtilsTest/getResource/foo.txt"); - TestUtils.assertExists(file); + assertThat(file).exists(); file = getResource("/org/sonar/test/TestUtilsTest/getResource/foo.txt"); - TestUtils.assertExists(file); + assertThat(file).exists(); file = getResource(getClass(), "getResource/foo.txt"); - TestUtils.assertExists(file); + assertThat(file).exists(); } @Test public void testResourceNotFound() { File file = getResource("org/sonar/test/TestUtilsTest/unknown.txt"); - assertNull(file); + assertThat(file).isNull(); } @Test public void testTempDir() throws Exception { File dir = getTestTempDir(getClass(), "testTempDir"); - assertExists(dir); - assertThat(dir.isDirectory(), is(true)); - assertThat(dir.listFiles().length, is(0)); + assertThat(dir).exists().isDirectory(); + assertThat(dir.listFiles()).isEmpty(); FileUtils.writeStringToFile(new File(dir, "bar.txt"), "some text"); - assertThat(dir.listFiles().length, is(1)); + assertThat(dir.listFiles()).hasSize(1); // the directory is cleaned dir = getTestTempDir(getClass(), "testTempDir"); - TestUtils.assertExists(dir); - assertThat(dir.isDirectory(), is(true)); - assertThat(dir.listFiles().length, is(0)); + assertThat(dir).exists().isDirectory(); + assertThat(dir.listFiles()).isEmpty(); } @Test @@ -82,12 +76,12 @@ public class TestUtilsTest { assertSimilarXml("<foo> <bar /> </foo>", "<foo><bar/></foo>"); // attribute values are checked - assertFalse(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()); + assertThat(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()).isFalse(); // different xml - assertFalse(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()); + assertThat(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()).isFalse(); // order of nodes is important - assertFalse(isSimilarXml("<foo><bar id='1' /><bar id='2' /></foo>", "<foo><bar id='2' /><bar id='1' /></foo>").similar()); + assertThat(isSimilarXml("<foo><bar id='1' /><bar id='2' /></foo>", "<foo><bar id='2' /><bar id='1' /></foo>").similar()).isFalse(); } } |