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/src/main | |
parent | d8a9891950228b8b5d66803e5be1263b756fb9e8 (diff) | |
download | sonarqube-078cff8c82b9b3f4bb31f6c014d0bb96f7a1b46a.tar.gz sonarqube-078cff8c82b9b3f4bb31f6c014d0bb96f7a1b46a.zip |
Sanitize sonar-testing-harness
Diffstat (limited to 'sonar-testing-harness/src/main')
3 files changed, 16 insertions, 34 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 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) { |