sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1408024 - in /sis/branches/JDK7: sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java
Date Sun, 11 Nov 2012 15:07:36 GMT
Author: desruisseaux
Date: Sun Nov 11 15:07:35 2012
New Revision: 1408024

URL: http://svn.apache.org/viewvc?rev=1408024&view=rev
Log:
Still trying to understand why the build on Jenkins sometime pickup the wrong resource.

Modified:
    sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java

Modified: sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java?rev=1408024&r1=1408023&r2=1408024&view=diff
==============================================================================
--- sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
(original)
+++ sis/branches/JDK7/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
Sun Nov 11 15:07:35 2012
@@ -349,8 +349,7 @@ class IndexedResourceCompiler implements
         final String[] keys = resources.keySet().toArray(new String[resources.size()]);
         Arrays.sort(keys, this);
         int freeID = 0;
-        for (int i=0; i<keys.length; i++) {
-            final String key = keys[i];
+        for (final String key : keys) {
             if (!allocatedIDs.containsValue(key)) {
                 Integer ID;
                 do {
@@ -495,10 +494,10 @@ search: for (int i=0; i<buffer.length();
                   .append(KEY_MARGIN).append('}').append(lineSeparator);
             final Map.Entry<?,?>[] entries = allocatedIDs.entrySet().toArray(new Map.Entry<?,?>[allocatedIDs.size()]);
             Arrays.sort(entries, this);
-            for (int i=0; i<entries.length; i++) {
+            for (final Map.Entry<?,?> entry : entries) {
                 buffer.append(lineSeparator);
-                final String key = (String) entries[i].getValue();
-                final String ID  = entries[i].getKey().toString();
+                final String key = (String) entry.getValue();
+                final String ID  = entry.getKey().toString();
                 String message = (String) resources.get(key);
                 if (message != null) {
                     message = message.replace('\t', ' ');

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java?rev=1408024&r1=1408023&r2=1408024&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java
(original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/resources/IndexedResourceBundleTest.java
Sun Nov 11 15:07:35 2012
@@ -17,6 +17,7 @@
 package org.apache.sis.util.resources;
 
 import java.io.IOException;
+import java.io.PrintStream;
 import java.util.Locale;
 import java.util.Enumeration;
 import java.util.logging.Level;
@@ -27,6 +28,7 @@ import org.apache.sis.test.DependsOnMeth
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
+import org.junit.After;
 
 import static org.junit.Assert.*;
 
@@ -41,6 +43,13 @@ import static org.junit.Assert.*;
 @DependsOn(org.apache.sis.util.ArraysTest.class)
 public final strictfp class IndexedResourceBundleTest extends TestCase {
     /**
+     * The resource bundle in process of being tested. Shall be reset to {@code null} after
every
+     * test. If non-null, then {@link #dumpResourcesOnError()} will consider that the test
failed
+     * and will dump the resource bundle content to the standard error stream.
+     */
+    private IndexedResourceBundle testing;
+
+    /**
      * Tests the {@link Errors#getResources(Locale)} method on different locales.
      */
     @Test
@@ -80,7 +89,8 @@ public final strictfp class IndexedResou
     @Test
     @DependsOnMethod("testGetResources")
     public void testGetKeys() {
-        final Enumeration<String> e=Errors.getResources(Locale.ENGLISH).getKeys();
+        testing = Errors.getResources(Locale.ENGLISH);
+        final Enumeration<String> e = testing.getKeys();
         int count = 0;
         boolean foundNullArgument_1 = false;
         while (e.hasMoreElements()) {
@@ -92,6 +102,7 @@ public final strictfp class IndexedResou
         }
         assertTrue("foundNullArgument_1:", foundNullArgument_1);
         assertTrue("count > 5", count > 5);
+        testing = null;
     }
 
     /**
@@ -103,8 +114,9 @@ public final strictfp class IndexedResou
         final Errors english = Errors.getResources(Locale.ENGLISH);
         final Errors french  = Errors.getResources(Locale.FRENCH);
 
-        assertEquals("Argument ‘{0}’ shall not be null.",     english.getString(Errors.Keys.NullArgument_1));
-        assertEquals("L’argument ‘{0}’ ne doit pas être nul.", french.getString(Errors.Keys.NullArgument_1));
+        assertEquals("Argument ‘{0}’ shall not be null.",      (testing = english).getString(Errors.Keys.NullArgument_1));
+        assertEquals("L’argument ‘{0}’ ne doit pas être nul.", (testing
= french) .getString(Errors.Keys.NullArgument_1));
+        testing = null;
     }
 
     /**
@@ -116,8 +128,9 @@ public final strictfp class IndexedResou
         final Errors english = Errors.getResources(Locale.ENGLISH);
         final Errors french  = Errors.getResources(Locale.FRENCH);
 
-        assertEquals("Argument ‘{0}’ shall not be null.",     english.getString("NullArgument_1"));
-        assertEquals("L’argument ‘{0}’ ne doit pas être nul.", french.getString("NullArgument_1"));
+        assertEquals("Argument ‘{0}’ shall not be null.",      (testing = english).getString("NullArgument_1"));
+        assertEquals("L’argument ‘{0}’ ne doit pas être nul.", (testing
= french) .getString("NullArgument_1"));
+        testing = null;
     }
 
     /**
@@ -126,10 +139,11 @@ public final strictfp class IndexedResou
     @Test
     @DependsOnMethod("testGetString")
     public void testGetStringWithParameter() {
-        assertEquals("Argument ‘CRS’ shall not be null.",
-                Errors.getResources(Locale.ENGLISH).getString(Errors.Keys.NullArgument_1,
"CRS"));
-        assertEquals("L’argument ‘CRS’ ne doit pas être nul.",
-                Errors.getResources(Locale.FRENCH).getString(Errors.Keys.NullArgument_1,
"CRS"));
+        testing = Errors.getResources(Locale.ENGLISH);
+        assertEquals("Argument ‘CRS’ shall not be null.", testing.getString(Errors.Keys.NullArgument_1,
"CRS"));
+        testing = Errors.getResources(Locale.FRENCH);
+        assertEquals("L’argument ‘CRS’ ne doit pas être nul.", testing.getString(Errors.Keys.NullArgument_1,
"CRS"));
+        testing = null;
     }
 
     /**
@@ -153,12 +167,31 @@ public final strictfp class IndexedResou
     @Test
     @DependsOnMethod("testGetResources")
     public void testGetLogRecord() {
-        final IndexedResourceBundle resources = Errors.getResources(Locale.ENGLISH);
-        final LogRecord record = resources.getLogRecord(Level.FINE, Errors.Keys.NullArgument_1,
"CRS");
+        testing = Errors.getResources(Locale.ENGLISH);
+        final LogRecord record = testing.getLogRecord(Level.FINE, Errors.Keys.NullArgument_1,
"CRS");
         assertEquals("NullArgument_1", record.getMessage());
 
         final SimpleFormatter formatter = new SimpleFormatter();
         final String message = formatter.format(record);
         assertTrue(message.contains("Argument ‘CRS’ shall not be null."));
+        testing = null;
+    }
+
+    /**
+     * If a test failed, lists the resource bundle content to the
+     * {@linkplain System#err standard error stream}.
+     *
+     * @throws IOException Should never happen.
+     */
+    @After
+    public void dumpResourcesOnError() throws IOException {
+        if (testing != null) {
+            final PrintStream err = System.err;
+            err.print("Error while testing IndexedResourceBundle for locale ");
+            err.print(testing.getLocale());
+            err.println(". Bundle content is:");
+            testing.list(err);
+            err.flush();
+        }
     }
 }



Mime
View raw message