]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2846 API: the i18n Hamcrest matcher should not fail if some keys are not define...
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 29 Sep 2011 16:05:09 +0000 (18:05 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 29 Sep 2011 16:05:09 +0000 (18:05 +0200)
sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java
sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java
sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys.properties [new file with mode: 0644]
sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys_fr.properties [new file with mode: 0644]

index 5ad959675618654cad95afe90c043dbf9e18bcb2..78876aab912e31cd4550ef1917fcadc3b6987129 100644 (file)
@@ -48,7 +48,7 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> {
   private String remote_file_path;
   private String bundleName;
   private SortedMap<String, String> missingKeys;
-  private SortedMap<String, String> nonExistingKeys;
+  private SortedMap<String, String> additionalKeys;
 
   public BundleSynchronizedMatcher(String sonarVersion) {
     this(sonarVersion, GITHUB_RAW_FILE_PATH);
@@ -65,12 +65,11 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> {
     }
     bundleName = (String) arg0;
 
-    // Get the bundle
     File bundle = getBundleFileFromClasspath(bundleName);
 
     // Find the default bundle name which should be compared to
     String defaultBundleName = extractDefaultBundleName(bundleName);
-    File defaultBundle = null;
+    File defaultBundle;
     if (isCoreBundle(defaultBundleName)) {
       defaultBundle = getBundleFileFromGithub(defaultBundleName);
     } else {
@@ -80,8 +79,8 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> {
     // and now let's compare
     try {
       missingKeys = retrieveMissingTranslations(bundle, defaultBundle);
-      nonExistingKeys = retrieveMissingTranslations(defaultBundle, bundle);
-      return missingKeys.isEmpty() && nonExistingKeys.isEmpty();
+      additionalKeys = retrieveMissingTranslations(defaultBundle, bundle);
+      return missingKeys.isEmpty();
     } catch (IOException e) {
       fail("An error occured while reading the bundles: " + e.getMessage());
       return false;
@@ -103,9 +102,9 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> {
   private StringBuilder prepareDetailsMessage(File dumpFile) {
     StringBuilder details = new StringBuilder("\n=======================\n'");
     details.append(bundleName);
-    details.append("' is not synchronized.");
+    details.append("' is not up-to-date.");
     print("\n\n Missing translations are:", missingKeys, details);
-    print("\n\nThe following translations do not exist in the reference bundle:", nonExistingKeys, details);
+    print("\n\nThe following translations do not exist in the reference bundle:", additionalKeys, details);
     details.append("\n\nSee report file located at: " + dumpFile.getAbsolutePath());
     details.append("\n=======================");
     return details;
index 6568ff16101ce0c7433f9fa453768fe4d68975d2..914184911fab94ea386bbcc233d898ff98ef8581 100644 (file)
  */
 package org.sonar.test.i18n;
 
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.sonar.test.i18n.I18nMatchers.isBundleUpToDate;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.test.TestUtils;
 
 import java.io.File;
-import java.util.Collection;
 import java.util.SortedMap;
 
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.test.TestUtils;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.sonar.test.i18n.I18nMatchers.isBundleUpToDate;
 
 public class BundleSynchronizedTest {
 
@@ -58,13 +53,11 @@ public class BundleSynchronizedTest {
     } catch (AssertionError e) {
       assertThat(e.getMessage(), containsString("Missing translations are:\nsecond.prop"));
     }
-    // unnecessary many keys
-    try {
-      assertThat("myPlugin_fr_QB.properties", isBundleUpToDate());
-      assertTrue(new File("target/l10n/myPlugin_fr_QB.properties.report.txt").exists());
-    } catch (AssertionError e) {
-      assertThat(e.getMessage(), containsString("The following translations do not exist in the reference bundle:\nfourth.prop"));
-    }
+  }
+
+  @Test
+  public void shouldNotFailIfNoMissingKeysButAdditionalKeys() {
+    assertThat("noMissingKeys_fr.properties", isBundleUpToDate());
   }
 
   @Test
diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys.properties
new file mode 100644 (file)
index 0000000..3fb9281
--- /dev/null
@@ -0,0 +1 @@
+foo=Foo
\ No newline at end of file
diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys_fr.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys_fr.properties
new file mode 100644 (file)
index 0000000..9df3201
--- /dev/null
@@ -0,0 +1,2 @@
+foo=Hein
+not_in_reference=Not in reference
\ No newline at end of file