diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-09-02 18:03:38 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-09-02 18:03:38 +0200 |
commit | 7df9484047b3d1d58d5b142e4042728a01512026 (patch) | |
tree | 189ad52ef4583615e7c87cf886128b10cd6f0732 /sonar-testing-harness | |
parent | f0559fe73cd8d29a5f505c5a80c0c6784b97430c (diff) | |
download | sonarqube-7df9484047b3d1d58d5b142e4042728a01512026.tar.gz sonarqube-7df9484047b3d1d58d5b142e4042728a01512026.zip |
SONAR-2693 Improve unit tests for I18n Harmcrest matcher
Diffstat (limited to 'sonar-testing-harness')
3 files changed, 41 insertions, 7 deletions
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 1fd44ecfa6b..18351b9c70b 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 @@ -28,6 +28,7 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -35,6 +36,7 @@ import java.util.Collection; import java.util.Properties; import java.util.Set; +import org.apache.commons.io.IOUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.sonar.test.TestUtils; @@ -102,16 +104,35 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> { } } if ( !nonExistingKeys.isEmpty()) { - details.append("\n\nAlso, the following keys do not exist in the default bundle:"); + details.append("\n\nThe following keys do not exist in the default bundle:"); for (String key : nonExistingKeys) { details.append("\n\t- " + key); } } details.append("\n\n======================="); + printReport(details.toString()); + description.appendText(details.toString()); } + private void printReport(String details) { + File dumpFile = new File("target/l10n/" + bundleName + ".report.txt"); + if (dumpFile.exists()) { + dumpFile.delete(); + } + dumpFile.getParentFile().mkdirs(); + FileWriter writer = null; + try { + writer = new FileWriter(dumpFile); + writer.write(details); + } catch (IOException e) { + System.out.println("Unable to write the report to 'target/l10n/" + bundleName + ".report.txt'."); + } finally { + IOUtils.closeQuietly(writer); + } + } + protected Collection<String> retrieveMissingKeys(File bundle, File defaultBundle) throws IOException { Collection<String> missingKeys = Lists.newArrayList(); diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java index 0bac5a9047b..73d6e310689 100644 --- a/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java +++ b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java @@ -31,17 +31,17 @@ import java.io.File; import java.util.Collection; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.sonar.test.TestUtils; public class BundleSynchronizedTest { + private static final String GITHUB_RAW_FILE_PATH = "https://raw.github.com/SonarSource/sonar/master/sonar-testing-harness/src/test/resources/org/sonar/l10n/"; private BundleSynchronizedMatcher matcher; @Before public void test() throws Exception { - matcher = new BundleSynchronizedMatcher("https://raw.github.com/SonarSource/sonar/master/sonar-testing-harness/src/test/resources/org/sonar/l10n/"); + matcher = new BundleSynchronizedMatcher(); } @Test @@ -49,25 +49,34 @@ public class BundleSynchronizedTest { public void testBundlesInsideSonarPlugin() { // synchronized bundle assertThat("myPlugin_fr_CA.properties", isBundleSynchronized()); + assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists()); // missing keys try { assertThat("myPlugin_fr.properties", isBundleSynchronized()); + assertTrue(new File("target/l10n/myPlugin_fr.properties.report.txt").exists()); } catch (AssertionError e) { assertThat(e.getMessage(), containsString("Missing keys are:\n\t- second.prop")); } // unnecessary many keys try { assertThat("myPlugin_fr_QB.properties", isBundleSynchronized()); + assertTrue(new File("target/l10n/myPlugin_fr_QB.properties.report.txt").exists()); } catch (AssertionError e) { - assertThat(e.getMessage(), containsString("Also, the following keys do not exist in the default bundle:\n\t- fourth.prop")); + assertThat(e.getMessage(), containsString("The following keys do not exist in the default bundle:\n\t- fourth.prop")); } } @Test - @Ignore // The case of a Sonar Language Pack that translates the Core bundles public void testBundlesOfLanguagePack() { - assertThat("core_fr.properties", isBundleSynchronized()); + // synchronized bundle + assertThat("core_fr_CA.properties", new BundleSynchronizedMatcher(GITHUB_RAW_FILE_PATH)); + // missing keys + try { + assertThat("core_fr.properties", new BundleSynchronizedMatcher(GITHUB_RAW_FILE_PATH)); + } catch (AssertionError e) { + assertThat(e.getMessage(), containsString("Missing keys are:\n\t- second.prop")); + } } @Test @@ -81,8 +90,8 @@ public class BundleSynchronizedTest { } @Test - @Ignore public void testGetBundleFileFromGithub() throws Exception { + matcher = new BundleSynchronizedMatcher(GITHUB_RAW_FILE_PATH); matcher.getBundleFileFromGithub("core.properties"); assertTrue(new File("target/l10n/download/core.properties").exists()); } diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties new file mode 100644 index 00000000000..d182159860d --- /dev/null +++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties @@ -0,0 +1,4 @@ +## -------- Test file for the BundleSynchronizedMatcher -------- ## +first.prop = This is my first property +second.prop = This is my second property +third.prop = This is my third property
\ No newline at end of file |