You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by df...@apache.org on 2005/05/03 13:53:01 UTC

svn commit: r167900 - in /jakarta/commons/sandbox/i18n/trunk/src/test: ./ org/apache/commons/i18n/ org/apache/commons/i18n/bundles/

Author: dflorey
Date: Tue May  3 04:53:01 2005
New Revision: 167900

URL: http://svn.apache.org/viewcvs?rev=167900&view=rev
Log: (empty)

Added:
    jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle2.properties
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedErrorTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedExceptionTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageManagerTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MockProviderTestBase.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MyListResourceBundle.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/TextBundleTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/variantTestMessages.xml
Modified:
    jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle.properties
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/XMLMessageProviderTest.java
    jakarta/commons/sandbox/i18n/trunk/src/test/testMessages.xml

Modified: jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle.properties?rev=167900&r1=167899&r2=167900&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle.properties (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle.properties Tue May  3 04:53:01 2005
@@ -1,3 +1,4 @@
 # Example for using message bundles using a flat properties-file
 helloWorld.title=Hello World
-helloWorld.text=I wish you a merry christmas!
\ No newline at end of file
+helloWorld.text=I wish you a merry christmas!
+helloWorld.notTranslated=This entry is not translated to any other languages
\ No newline at end of file

Added: jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle2.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle2.properties?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle2.properties (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/messageBundle2.properties Tue May  3 04:53:01 2005
@@ -0,0 +1,2 @@
+# Example 2 for using message bundles using a flat properties-file
+onlyInSecond.title=This message exists in another resource bundle
\ No newline at end of file

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import java.util.Locale;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class LocalizedBundleTest extends MockProviderTestBase {
+    public void testConstructors() {
+        LocalizedBundle lb = new LocalizedBundle("dummyId1");
+        assertEquals("Id set", "dummyId1", lb.getId());
+        assertNotNull("Arguments not null", lb.getArguments());
+        assertEquals("No arguments", 0, lb.getArguments().length);
+
+        String[] arguments = new String[]{"arg1", "arg2"};
+        LocalizedBundle lbArgs = new LocalizedBundle("dummyId2", arguments);
+        assertEquals("Id set", "dummyId2", lbArgs.getId());
+        assertNotNull("Arguments not null", lbArgs.getArguments());
+        assertEquals("No of arguments", 2, lbArgs.getArguments().length);
+        assertEquals("Arguments", arguments, lbArgs.getArguments());
+    }
+
+    public void testGetEntry() {
+        LocalizedBundle lb = new LocalizedBundle("dummyId1");
+        LocalizedBundle lbArgs = new LocalizedBundle("dummyId2", new String[] {"arg1", "arg2"});
+
+        // Test errors
+        try {
+            lb.getEntry("dummyEntry", Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "No MessageProvider registered", mnfex.getMessage());
+        }
+        try {
+            lbArgs.getEntry("dummyEntry", Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "No MessageProvider registered", mnfex.getMessage());
+        }
+
+        // Test default texts
+        assertEquals("Default text", "defaultText", lb.getEntry("dummyEntry", Locale.US, "defaultText"));
+        assertEquals("Default text with arguments", "defaultText with arg1 arg2", lbArgs.getEntry("dummyEntry",
+                        Locale.US, "defaultText with {0} {1}"));
+
+        addMockProvider(); // Add mock provider
+
+        assertEquals("Default text not used", "Id=dummyId1 Entry=dummyEntry Locale=en_US",
+                lb.getEntry("dummyEntry", Locale.US, "defaltText"));
+
+        assertEquals("Normal lookup", "Id=dummyId1 Entry=entry Locale=en_US", lb.getEntry("entry", Locale.US));
+        assertEquals("Arguments missing", "Id=dummyId1 Entry=entry {0} Locale=en_US",
+                lb.getEntry("entry {0}", Locale.US));
+        assertEquals("Argument", "Id=dummyId2 Entry=entry arg1 arg2 Locale=en_US",
+                lbArgs.getEntry("entry {0} {1}", Locale.US));
+        assertEquals("Arguments and default", "Id=dummyId2 Entry=entry arg1 arg2 Locale=en_US",
+                lbArgs.getEntry("entry {0} {1}", Locale.US, "defaultText"));
+    }
+}

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedErrorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedErrorTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedErrorTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedErrorTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import org.apache.commons.i18n.bundles.ErrorBundle;
+
+import java.util.Locale;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class LocalizedErrorTest extends MockProviderTestBase {
+    public void testLocalizedErrorWithCause() {
+        Throwable cause = new Exception("foo");
+        ErrorBundle errorBundle = new ErrorBundle("errorMessageId");
+        LocalizedError le = new LocalizedError(errorBundle, cause);
+        assertEquals("Cause", cause, le.getCause());
+        assertEquals("Error bundle", errorBundle, le.getErrorMessage());
+        assertEquals("Error message", cause.getMessage(), le.getMessage());
+
+        addMockProvider(); // Add mock provider
+
+        LocalizedError le2 = new LocalizedError(errorBundle, cause);
+        assertEquals("Cause", cause, le2.getCause());
+        assertEquals("Error bundle", errorBundle, le2.getErrorMessage());
+        assertEquals("Error message", getMockString("errorMessageId", ErrorBundle.SUMMARY, Locale.getDefault()),
+                le2.getMessage());
+    }
+
+
+    public void testLocalizedErrorWithoutCause() {
+        ErrorBundle errorBundle = new ErrorBundle("errorMessageId");
+        LocalizedError le = new LocalizedError(errorBundle);
+        assertNull("Cause", le.getCause());
+        assertEquals("Error bundle", errorBundle, le.getErrorMessage());
+        assertEquals("Error message",
+                "Message bundle with key errorMessageId does not contain an entry with key summary", le.getMessage());
+
+        addMockProvider(); // Add mock provider
+
+        LocalizedError le2 = new LocalizedError(errorBundle);
+        assertNull("Cause", le.getCause());
+        assertEquals("Error bundle", errorBundle, le2.getErrorMessage());
+        assertEquals("Error message", getMockString("errorMessageId", ErrorBundle.SUMMARY, Locale.getDefault()),
+                le2.getMessage());
+    }
+}

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedExceptionTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedExceptionTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedExceptionTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedExceptionTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import org.apache.commons.i18n.bundles.ErrorBundle;
+
+import java.util.Locale;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class LocalizedExceptionTest extends MockProviderTestBase {
+    public void testLocalizedErrorWithCause() {
+        Throwable cause = new Exception("foo");
+        ErrorBundle errorBundle = new ErrorBundle("errorMessageId");
+        LocalizedException le = new LocalizedException(errorBundle, cause);
+        assertEquals("Cause", cause, le.getCause());
+        assertEquals("Error bundle", errorBundle, le.getErrorMessage());
+        assertEquals("Error message", cause.getMessage(), le.getMessage());
+
+        addMockProvider(); // Add mock provider
+
+        LocalizedException le2 = new LocalizedException(errorBundle, cause);
+        assertEquals("Cause", cause, le2.getCause());
+        assertEquals("Error bundle", errorBundle, le2.getErrorMessage());
+        assertEquals("Error message", getMockString("errorMessageId", ErrorBundle.SUMMARY, Locale.getDefault()),
+                le2.getMessage());
+    }
+
+
+    public void testLocalizedErrorWithoutCause() {
+        ErrorBundle errorBundle = new ErrorBundle("errorMessageId");
+        LocalizedException le = new LocalizedException(errorBundle);
+        assertNull("Cause", le.getCause());
+        assertEquals("Error bundle", errorBundle, le.getErrorMessage());
+        assertEquals("Error message",
+                "Message bundle with key errorMessageId does not contain an entry with key summary", le.getMessage());
+
+        addMockProvider(); // Add mock provider
+
+        LocalizedException le2 = new LocalizedException(errorBundle);
+        assertNull("Cause", le.getCause());
+        assertEquals("Error bundle", errorBundle, le2.getErrorMessage());
+        assertEquals("Error message", getMockString("errorMessageId", ErrorBundle.SUMMARY, Locale.getDefault()),
+                le2.getMessage());
+    }
+}

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import org.apache.commons.i18n.bundles.ErrorBundle;
+
+import java.util.Locale;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class LocalizedRuntimeExceptionTest extends MockProviderTestBase {
+    public void testLocalizedErrorWithCause() {
+        Throwable cause = new Exception("foo");
+        ErrorBundle errorBundle = new ErrorBundle("errorMessageId");
+        LocalizedRuntimeException le = new LocalizedRuntimeException(errorBundle, cause);
+        assertEquals("Cause", cause, le.getCause());
+        assertEquals("Error bundle", errorBundle, le.getErrorMessage());
+        assertEquals("Error message", cause.getMessage(), le.getMessage());
+
+        addMockProvider(); // Add mock provider
+
+        LocalizedRuntimeException le2 = new LocalizedRuntimeException(errorBundle, cause);
+        assertEquals("Cause", cause, le2.getCause());
+        assertEquals("Error bundle", errorBundle, le2.getErrorMessage());
+        assertEquals("Error message", getMockString("errorMessageId", ErrorBundle.SUMMARY, Locale.getDefault()),
+                le2.getMessage());
+    }
+
+
+    public void testLocalizedErrorWithoutCause() {
+        ErrorBundle errorBundle = new ErrorBundle("errorMessageId");
+        LocalizedRuntimeException le = new LocalizedRuntimeException(errorBundle);
+        assertNull("Cause", le.getCause());
+        assertEquals("Error bundle", errorBundle, le.getErrorMessage());
+        assertEquals("Error message",
+                "Message bundle with key errorMessageId does not contain an entry with key summary", le.getMessage());
+
+        addMockProvider(); // Add mock provider
+
+        LocalizedRuntimeException le2 = new LocalizedRuntimeException(errorBundle);
+        assertNull("Cause", le.getCause());
+        assertEquals("Error bundle", errorBundle, le2.getErrorMessage());
+        assertEquals("Error message", getMockString("errorMessageId", ErrorBundle.SUMMARY, Locale.getDefault()),
+                le2.getMessage());
+    }
+}

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageManagerTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageManagerTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageManagerTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageManagerTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class MessageManagerTest extends MockProviderTestBase {
+
+    /** Dummy to add to constructor to coverage report */
+    public void testDummy() {
+        new MessageManager();
+    }
+
+    public void testGetText() {
+        assertEquals("Default text used", "defaultText",
+                MessageManager.getText("dummyId", "dummyEntry", null, Locale.US, "defaultText"));
+        assertEquals("Default text with arguments", "defaultText with value",
+                MessageManager.getText("dummyId", "dummyEntry", new String[] {"with value"},
+                        Locale.US, "defaultText {0}"));
+        try {
+            MessageManager.getText("dummyId", "dummyEntry", null, Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "No MessageProvider registered", mnfex.getMessage());
+        }
+
+        addThrowingMockProvider(); // Add mock provider always throwing exceptions
+
+        try {
+            MessageManager.getText("dummyId", "dummyEntry", null, Locale.US);
+            fail("Mock provider should throw Exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "Mock exception from getText()", mnfex.getMessage());
+        }
+
+        addMockProvider(); // Add mock provider
+
+        assertEquals("Throwing mock not used", "Id=dummyId Entry=dummyEntry Locale=en_US",
+                MessageManager.getText("dummyId", "dummyEntry", null, Locale.US, "defaultText"));
+
+        removeThrowingMockProvider(); // Removing throwing mock and keep only normal mock
+
+        assertEquals("Default text not used", "Id=dummyId Entry=dummyEntry Locale=en_US",
+                MessageManager.getText("dummyId", "dummyEntry", null, Locale.US, "defaultText"));
+
+        assertEquals("Normal lookup", "Id=id Entry=entry Locale=en_US",
+                MessageManager.getText("id", "entry", null, Locale.US));
+        assertEquals("Single argument",
+                "Id=id Entry=entry value1 Locale=en_US",
+                MessageManager.getText("id", "entry {0}", new String[] {"value1"}, Locale.US));
+        assertEquals("Multiple arguments",
+                "Id=id Entry=entry value0: value1 Locale=en_US",
+                MessageManager.getText("id", "entry {0}: {1}", new String[] {"value0", "value1"},Locale.US));
+
+        assertEquals("Single argument and default",
+                "Id=id Entry=entry value1 Locale=en_US",
+                MessageManager.getText("id", "entry {0}", new String[] {"value1"},Locale.US, "defaultText"));
+    }
+
+    public void testGetEntries() {
+        try {
+            MessageManager.getEntries("dummyId", Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "No MessageProvider registered", mnfex.getMessage());
+        }
+
+        addThrowingMockProvider(); // Add mock provider always throwing exceptions
+
+        try {
+            MessageManager.getEntries("dummyId", Locale.US);
+            fail("Mock provider should throw Exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "Mock exception from getEntries()", mnfex.getMessage());
+        }
+
+        addMockProvider(); // Add mock provider
+
+        Map entries = MessageManager.getEntries("dummyId", Locale.US);
+        assertEquals("No of entries", 2, entries.size());
+        assertEquals("Entry 1 match", "Id=dummyId Entry=entry1 Locale=en_US", entries.get("entry1"));
+        assertEquals("Entry 2 match", "Id=dummyId Entry=entry2 Locale=en_US", entries.get("entry2"));
+
+        removeThrowingMockProvider(); // Removing throwing mock and keep only normal mock
+
+        addMockProvider(); // Add mock provider
+
+        entries = MessageManager.getEntries("dummyId", Locale.US);
+        assertEquals("No of entries", 2, entries.size());
+        assertEquals("Entry 1 match", "Id=dummyId Entry=entry1 Locale=en_US", entries.get("entry1"));
+        assertEquals("Entry 2 match", "Id=dummyId Entry=entry2 Locale=en_US", entries.get("entry2"));
+    }
+}
\ No newline at end of file

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import junit.framework.TestCase;
+
+/**
+ * Meaningless test class for with the only purpose of making the
+ * coverage report look better...
+ * @author Mattias Jiderhamn
+ */
+public class MessageNotFoundExceptionTest extends TestCase {
+    public void testConstruction() {
+        new MessageNotFoundException("");
+        new MessageNotFoundException("foo", new Exception("bar"));
+    }
+}

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MockProviderTestBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MockProviderTestBase.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MockProviderTestBase.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MockProviderTestBase.java Tue May  3 04:53:01 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+import java.text.MessageFormat;
+
+/**
+ * The <code>MockProviderTestBase</code> class serves as a base class for test cases using a mock
+ * <code>MessageProvider</code>. After every test, it will remove the mock message provider to prepare
+ * for other tests.
+ * @author Mattias Jiderhamn
+ */
+public abstract class MockProviderTestBase extends TestCase {
+    /**
+     * Mock message provider that returns a string made up of the arguments passed to it.
+     */
+    final private MessageProvider mockMessageProvider = new MessageProvider() {
+        public String getText(String id, String entry, Locale locale) throws MessageNotFoundException {
+            return MockProviderTestBase.getMockString(id, entry, locale);
+        }
+
+        public Map getEntries(String id, Locale locale) throws MessageNotFoundException {
+            Map output = new HashMap();
+            output.put("entry1", MockProviderTestBase.getMockString(id,"entry1",locale));
+            output.put("entry2", MockProviderTestBase.getMockString(id,"entry2",locale));
+            return output;
+        }
+    };
+
+    public void tearDown() {
+        /* Remove mock provider after each test, to allow for MessageNotFoundExceptions */
+        MessageManager.removeMessageProvider("mock");
+        removeThrowingMockProvider();
+    }
+
+    /**
+     * Add mock provider to <code>MessageManager</code>.
+     */
+    protected void addMockProvider() {
+        MessageManager.addMessageProvider("mock", mockMessageProvider);
+    }
+
+    /**
+     * Add provider that always throws error to <code>MessageManager</code>.
+     */
+    protected void addThrowingMockProvider() {
+        MessageManager.addMessageProvider("throwingMock", new MessageProvider() {
+            public String getText(String id, String entry, Locale locale) throws MessageNotFoundException {
+                throw new MessageNotFoundException("Mock exception from getText()");
+            }
+
+            public Map getEntries(String id, Locale locale) throws MessageNotFoundException {
+                throw new MessageNotFoundException("Mock exception from getEntries()");
+            }
+        });
+    }
+
+    protected void removeThrowingMockProvider() {
+        MessageManager.removeMessageProvider("throwingMock");
+    }
+
+    ////////////////////////////////////////////////////////////////////////
+    // Utility methods
+    ////////////////////////////////////////////////////////////////////////
+
+    public static String getMockString(String id, String entry, Locale locale) throws MessageNotFoundException {
+        return "Id=" + id + " Entry=" + entry + " Locale=" + locale + "";
+    }
+
+    public static String getFormattedMockString(String id, String entry, String[] arguments, Locale locale) {
+        return MessageFormat.format(getMockString(id, entry, locale), arguments);
+    }
+}

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MyListResourceBundle.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MyListResourceBundle.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MyListResourceBundle.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MyListResourceBundle.java Tue May  3 04:53:01 2005
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n;
+
+import java.util.ListResourceBundle;
+
+/**
+ * ListResourceBundle implementation used to test ClassCastException in
+ * <code>ResourceBundleMessageProvider</code>
+ * @author Mattias Jiderhamn
+ */
+public class MyListResourceBundle extends ListResourceBundle {
+    public Object[][] getContents() {
+        return contents;
+    }
+
+    static final Object[][] contents = {
+        {"helloWorld.title", "listResourceValue"},
+        {"helloWorld.text", new Integer(1)} // Should cause ClassCastException
+    };
+}

Modified: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java?rev=167900&r1=167899&r2=167900&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java Tue May  3 04:53:01 2005
@@ -35,23 +35,134 @@
         super(testName);
     }
 
+    public void setUp() {
+        /* Make sure en_US is the default Locale for tests */
+        Locale.setDefault(Locale.US);
+    }
+
+    public void tearDown() {
+        /* Uninstall resource bundles after every test */
+        ResourceBundleMessageProvider.uninstall("messageBundle");
+        ResourceBundleMessageProvider.uninstall("messageBundle2");
+        ResourceBundleMessageProvider.uninstall("nonExistentBundle");
+        ResourceBundleMessageProvider.uninstall("org.apache.commons.i18n.MyListResourceBundle");
+    }
+
     public void testInstallResourceBundle() {
-        System.out.println("INSTALL RESOURCE BUNDLE");
-        ResourceBundleMessageProvider.install("messageBundle");
         MessageBundle testMessage = new MessageBundle("helloWorld");
-        Locale locale = Locale.GERMAN;
-        assertEquals(testMessage.getTitle(locale), "Hallo Welt");
-    }
-    
-    public void testGetEntries() {
+
+        try {
+            testMessage.getTitle(Locale.GERMAN);
+            fail("ResourceBundle not installed, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+
         ResourceBundleMessageProvider.install("messageBundle");
-        Map entries = new ResourceBundleMessageProvider().getEntries("helloWorld", Locale.GERMAN);
-        assertTrue(entries.size() == 2 );
+
+        assertEquals("Hallo Welt", testMessage.getTitle(Locale.GERMAN));
+
+        ResourceBundleMessageProvider.update("messageBundle");
+
+        assertEquals("OK after update", "Hallo Welt", testMessage.getTitle(Locale.GERMAN));
+
+        ResourceBundleMessageProvider.uninstall("messageBundle");
+
+        try {
+            testMessage.getTitle(Locale.GERMAN);
+            fail("ResourceBundle uinstalled, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
     }
-    
-    public void testFallbackToDefaultLocale() {
-        ResourceBundleMessageProvider.install("messageBundle");
-        Map entries = new ResourceBundleMessageProvider().getEntries("helloWorld", Locale.GERMAN);
-        assertTrue(entries.size() == 2 );
+
+    public void testGetText() {
+        ResourceBundleMessageProvider rbmp = new ResourceBundleMessageProvider("messageBundle");
+
+        assertEquals("Default locale", "Hello World", rbmp.getText("helloWorld", "title", Locale.US));
+        assertEquals("Additional locale", "Hallo Welt", rbmp.getText("helloWorld", "title", Locale.GERMAN));
+        assertEquals("Fallback locale", "Hello World", rbmp.getText("helloWorld", "title", Locale.FRENCH));
+        assertEquals("Fallback when only in default", "This entry is not translated to any other languages",
+                rbmp.getText("helloWorld", "notTranslated", Locale.GERMAN));
+
+        // Test with list resource bundle
+//        ResourceBundleMessageProvider.uninstall("messageBundle"); // Remove
+//        ResourceBundleMessageProvider.install("org.apache.commons.i18n.MyListResourceBundle"); // Install ListResourceBundle
+        ResourceBundleMessageProvider listResourceBundleProvider =
+                new ResourceBundleMessageProvider("org.apache.commons.i18n.MyListResourceBundle"); // Install ListResourceBundle
+        assertEquals("Value from ListResourceBundle", "listResourceValue", listResourceBundleProvider.getText("helloWorld", "title", Locale.US));
+        try {
+            String s = listResourceBundleProvider.getText("helloWorld", "text", Locale.US);
+            fail("Entry should not be found, since it is numeric. Found text: " + s);
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No message entries found for bundle with key helloWorld", mnfex.getMessage());
+        }
+
+        try {
+            rbmp.getText("nonExistentId", "nonExistentEntry", Locale.US);
+            fail("ID does not exist, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No message entries found for bundle with key nonExistentId", mnfex.getMessage());
+        }
+
+        try {
+            rbmp.getText("helloWorld", "nonExistentEntry", Locale.US);
+            fail("Entry does not exist, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No message entries found for bundle with key helloWorld", mnfex.getMessage());
+        }
+
+        // Test unexisting bundle which should throw MissingResourceException
+        ResourceBundleMessageProvider.install("nonExistentBundle"); // Install non-existent bundle
+        ResourceBundleMessageProvider.update("messageBundle"); // Place last in list
+        rbmp.getText("helloWorld", "title", Locale.US); // Should not throw Exception
+
+        ResourceBundleMessageProvider nonExistentBundleProvider = new ResourceBundleMessageProvider("nonExistentBundle");
+        try {
+            nonExistentBundleProvider.getText("fooBar", "text", Locale.GERMAN);
+            fail("Bundle does not exist and should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No message entries found for bundle with key fooBar", mnfex.getMessage());
+        }
+    }
+
+    public void testGetEntries() {
+//        ResourceBundleMessageProvider.install("messageBundle");
+        Map usEntries = new ResourceBundleMessageProvider("messageBundle").getEntries("helloWorld", Locale.US);
+        assertEquals("Default locale, no of entries", 3, usEntries.size());
+        assertEquals("Default locale, titel", "Hello World", usEntries.get("title"));
+        assertEquals("Default locale, text", "I wish you a merry christmas!", usEntries.get("text"));
+        assertEquals("This entry is not translated to any other languages", usEntries.get("notTranslated"));
+
+        Map germanEntries = new ResourceBundleMessageProvider("messageBundle").getEntries("helloWorld", Locale.GERMAN);
+        assertEquals("No of entries", 3, germanEntries.size());
+        assertEquals("Hallo Welt", germanEntries.get("title"));
+        assertEquals("Ich wünsche Dir alles Gute und ein frohes Fest!", germanEntries.get("text"));
+        assertEquals("This entry is not translated to any other languages", germanEntries.get("notTranslated"));
+
+        Map frenchEntries = new ResourceBundleMessageProvider("messageBundle").getEntries("helloWorld", Locale.FRENCH);
+        assertEquals("Fallback locale, no of entries", 3, frenchEntries.size());
+        assertEquals("Fallback locale, titel", "Hello World", frenchEntries.get("title"));
+        assertEquals("Fallback locale, text", "I wish you a merry christmas!", frenchEntries.get("text"));
+        assertEquals("This entry is not translated to any other languages", frenchEntries.get("notTranslated"));
+
+
+        // Test unexisting bundle which should throw MissingResourceException
+//        ResourceBundleMessageProvider.install("nonExistentBundle"); // Install non-existent bundle
+//        ResourceBundleMessageProvider.update("messageBundle"); // Place last in list
+        ResourceBundleMessageProvider nonExistentBundleProvider = new ResourceBundleMessageProvider("nonExistentBundle");
+        try {
+            nonExistentBundleProvider.getEntries("fooBar", Locale.GERMAN);
+            fail("Bundle does not exist and should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No message entries found for bundle with key fooBar", mnfex.getMessage());
+        }
     }
 }

Modified: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/XMLMessageProviderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/XMLMessageProviderTest.java?rev=167900&r1=167899&r2=167900&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/XMLMessageProviderTest.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/XMLMessageProviderTest.java Tue May  3 04:53:01 2005
@@ -20,6 +20,7 @@
 package org.apache.commons.i18n;
 
 import java.util.Locale;
+import java.util.Map;
 
 import org.apache.commons.i18n.bundles.MessageBundle;
 
@@ -30,18 +31,155 @@
  *
  */
 public class XMLMessageProviderTest extends TestCase {
+
+    public void setUp() {
+        /* Make sure en_US is the default Locale for tests */
+        Locale.setDefault(Locale.US);
+    }
+
+    public void tearDown() {
+        /* Uninstall resource bundles after every test */
+        XMLMessageProvider.uninstall("org.apache.commons-i18n.test");
+        XMLMessageProvider.uninstall("org.apache.commons-i18n.error");
+        XMLMessageProvider.uninstall("org.apache.commons-i18n.variants");
+    }
+
     public void testInstallResourceBundle() {
-        System.out.println("INSTALL RESOURCE BUNDLE");
-        XMLMessageProvider.install("org.apache.commons-i18n.test", 
-                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
         MessageBundle testMessage = new MessageBundle("helloWorld");
-        Locale locale = Locale.GERMAN;
-        assertEquals(testMessage.getTitle(locale), "Hallo Welt");
+
+        try {
+            testMessage.getTitle(Locale.GERMAN);
+            fail("XML file not installed, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+
+        XMLMessageProvider.install("org.apache.commons-i18n.test",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+
+        assertEquals("Hallo Welt", testMessage.getTitle(Locale.GERMAN));
+
+        XMLMessageProvider.update("org.apache.commons-i18n.test",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+
+        assertEquals("OK after update", "Hallo Welt", testMessage.getTitle(Locale.GERMAN));
+
+        XMLMessageProvider.uninstall("org.apache.commons-i18n.test");
+
+        try {
+            testMessage.getTitle(Locale.GERMAN);
+            fail("XML file uinstalled, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+
+        // Try to parse non-XML file
+        XMLMessageProvider.install("org.apache.commons-i18n.error",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("messageBundle.properties"));
     }
     
+    public void testGetText() {
+//        XMLMessageProvider.install("org.apache.commons-i18n.test",
+//                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+        XMLMessageProvider xmlmp = new XMLMessageProvider("org.apache.commons-i18n.test",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+
+        assertEquals("Default locale", "hello world", xmlmp.getText("helloWorld", "title", Locale.US));
+        assertEquals("Default locale", "hello world", xmlmp.getText("helloWorld", "title", Locale.UK));
+        assertEquals("Additional locale", "Hallo Welt", xmlmp.getText("helloWorld", "title", Locale.GERMAN));
+        assertEquals("Language and country using parent", "Hallo Welt", xmlmp.getText("helloWorld", "title",
+                new Locale("de", "CH")));
+        assertEquals("Language, country and variant using parent", "Hallo Welt", xmlmp.getText("helloWorld", "title",
+                new Locale("de", "CH", "foo")));
+        assertEquals("Fallback locale", "hello world", xmlmp.getText("helloWorld", "title", Locale.JAPANESE));
+        // TODO: Wait for Daniels reply on whether this is intended
+        // assertEquals("Fallback when only in default", "This entry is not translated to any other languages",
+        //         xmlmp.getText("helloWorld", "notTranslated", Locale.GERMAN));
+
+//        ResourceBundleMessageProvider.install("messageBundle2"); // Install another bundle
+//        assertEquals("This message exists in another resource bundle", xmlmp.getText("onlyInSecond", "title", Locale.US));
+
+        try {
+            xmlmp.getText("nonExistentId", "nonExistentEntry", Locale.US);
+            fail("ID does not exist, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Message with key nonExistentId not found", mnfex.getMessage());
+        }
+
+        // TODO: Wait for Daniels reply on whether this is intended
+        /*
+        try {
+            String s = xmlmp.getText("helloWorld", "nonExistentEntry", Locale.US);
+            fail("Entry does not exist, should throw exception. Entry was: '" + s + "'");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No message entries found for bundle with key helloWorld", mnfex.getMessage());
+        }
+        */
+    }
+
+    public void testGetTextVariants() {
+//        XMLMessageProvider.install("org.apache.commons-i18n.variants",
+//                Thread.currentThread().getContextClassLoader().getResourceAsStream("variantTestMessages.xml"));
+        XMLMessageProvider xmlmp = new XMLMessageProvider("org.apache.commons-i18n.variants",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("variantTestMessages.xml"));
+
+        assertEquals("hello world", xmlmp.getText("variants", "theKey", Locale.ENGLISH));
+        assertEquals("Botswana", "Hello Botswana", xmlmp.getText("variants", "theKey", new Locale("", "BW")));
+        assertEquals("Awrite warld", xmlmp.getText("variants", "theKey", new Locale("en", "GB", "scottish")));
+        assertEquals("Ga, ga, ga", xmlmp.getText("variants", "theKey", new Locale("en", "", "baby")));
+    }
+
+    public void testGetEntries() {
+//        XMLMessageProvider.install("org.apache.commons-i18n.test",
+//                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+        Map usEntries = new XMLMessageProvider("org.apache.commons-i18n.test",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml")).
+                    getEntries("helloWorld", Locale.US);
+        assertEquals("Default locale, no of entries", 5, usEntries.size());
+        assertEquals("Default locale, titel", "hello world", usEntries.get("title"));
+        assertEquals("Default locale, text", "hello world, we are in {0}.", usEntries.get("text"));
+        assertEquals("Default locale, text",
+                "sample summary to test english messages. Country = {0}, language = {1} and variant = {2}.",
+                usEntries.get("summary"));
+        assertEquals("Default locale, text",
+                "sample deatils to test english messages. Country = {0}, language = {1} and variant = {2}.",
+                usEntries.get("details"));
+        assertEquals("This entry is not translated to any other languages (XML)", usEntries.get("notTranslated"));
+
+        Map germanEntries = new XMLMessageProvider("org.apache.commons-i18n.test",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml")).
+                    getEntries("helloWorld", Locale.GERMAN);
+        assertEquals("No of entries", 4, germanEntries.size());
+        assertEquals("Hallo Welt", germanEntries.get("title"));
+        assertEquals("Wir sind in {0}.", germanEntries.get("text"));
+        assertEquals("sample summary to test german messages. Country = {0}, language = {1} and variant = {2}.",
+                germanEntries.get("summary"));
+        assertEquals("sample deatils to test german messages. Country = {0}, language = {1} and variant = {2}.",
+                germanEntries.get("details"));
+//        assertEquals("This entry is not translated to any other languages", germanEntries.get("notTranslated"));
+
+        Map japaneseEntries = new XMLMessageProvider("org.apache.commons-i18n.test",
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml")).
+                    getEntries("helloWorld", Locale.JAPANESE);
+        assertEquals("Fallback locale, no of entries", 5, japaneseEntries.size());
+
+        assertEquals("Fallback locale, titel", "hello world", usEntries.get("title"));
+        assertEquals("Fallback locale, text", "hello world, we are in {0}.", japaneseEntries.get("text"));
+        assertEquals("Fallback locale, text",
+                "sample summary to test english messages. Country = {0}, language = {1} and variant = {2}.",
+                japaneseEntries.get("summary"));
+        assertEquals("Fallback locale, text",
+                "sample deatils to test english messages. Country = {0}, language = {1} and variant = {2}.",
+                japaneseEntries.get("details"));
+        assertEquals("This entry is not translated to any other languages (XML)", japaneseEntries.get("notTranslated"));
+    }
+
     /**
      * Constructor for MessageManagerTest.
-     * @param arg0
      */
     public XMLMessageProviderTest(String testName) {
         super(testName);

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n.bundles;
+
+import org.apache.commons.i18n.MockProviderTestBase;
+import org.apache.commons.i18n.MessageNotFoundException;
+
+import java.util.Locale;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class ErrorBundleTest extends MockProviderTestBase {
+    public void testWithoutArguments() {
+        ErrorBundle eb = new ErrorBundle("dummyId");
+        try {
+            eb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText", eb.getText(Locale.US, "defaultText"));
+
+        addMockProvider();
+
+        assertEquals("Normal use", getMockString("dummyId", ErrorBundle.TEXT, Locale.US), eb.getText(Locale.US));
+        assertEquals("Normal use", getMockString("dummyId", ErrorBundle.TITLE, Locale.US), eb.getTitle(Locale.US));
+        assertEquals("Normal use", getMockString("dummyId", ErrorBundle.SUMMARY, Locale.US), eb.getSummary(Locale.US));
+        assertEquals("Normal use", getMockString("dummyId", ErrorBundle.DETAILS, Locale.US), eb.getDetails(Locale.US));
+        assertEquals("Default not used", getMockString("dummyId", ErrorBundle.TEXT, Locale.US),
+                eb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyId", ErrorBundle.TITLE, Locale.US),
+                eb.getTitle(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyId", ErrorBundle.SUMMARY, Locale.US),
+                eb.getSummary(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyId", ErrorBundle.DETAILS, Locale.US),
+                eb.getDetails(Locale.US, "defaultText"));
+    }
+
+    public void testWithArguments() {
+        String[] arguments = new String[]{"arg1", "arg2"};
+        ErrorBundle eb = new ErrorBundle("dummyId", arguments);
+        try {
+            eb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText arg1 arg2", eb.getText(Locale.US, "defaultText {0} {1}"));
+
+        addMockProvider();
+
+        assertEquals("Normal use", getFormattedMockString("dummyId", ErrorBundle.TEXT, arguments, Locale.US),
+                eb.getText(Locale.US));
+        assertEquals("Normal use", getFormattedMockString("dummyId", ErrorBundle.TITLE, arguments, Locale.US),
+                eb.getTitle(Locale.US));
+        assertEquals("Normal use", getFormattedMockString("dummyId", ErrorBundle.SUMMARY, arguments, Locale.US),
+                eb.getSummary(Locale.US));
+        assertEquals("Normal use", getFormattedMockString("dummyId", ErrorBundle.DETAILS, arguments, Locale.US),
+                eb.getDetails(Locale.US));
+        assertEquals("Default not used", getFormattedMockString("dummyId", ErrorBundle.TEXT, arguments, Locale.US),
+                eb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used", getFormattedMockString("dummyId", ErrorBundle.TITLE, arguments, Locale.US),
+                eb.getTitle(Locale.US, "defaultText"));
+        assertEquals("Default not used", getFormattedMockString("dummyId", ErrorBundle.SUMMARY, arguments, Locale.US),
+                eb.getSummary(Locale.US, "defaultText"));
+        assertEquals("Default not used", getFormattedMockString("dummyId", ErrorBundle.DETAILS, arguments, Locale.US),
+                eb.getDetails(Locale.US, "defaultText"));
+    }
+}
\ No newline at end of file

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n.bundles;
+
+import org.apache.commons.i18n.MockProviderTestBase;
+import org.apache.commons.i18n.MessageNotFoundException;
+
+import java.util.Locale;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class MessageBundleTest extends MockProviderTestBase {
+    public void testWithoutArguments() {
+        MessageBundle mb = new MessageBundle("dummyId");
+        try {
+            mb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText", mb.getText(Locale.US, "defaultText"));
+
+        addMockProvider();
+
+        assertEquals("Normal use", getMockString("dummyId", MessageBundle.TEXT, Locale.US), mb.getText(Locale.US));
+        assertEquals("Normal use", getMockString("dummyId", MessageBundle.TITLE, Locale.US), mb.getTitle(Locale.US));
+        assertEquals("Default not used", getMockString("dummyId", MessageBundle.TEXT, Locale.US),
+                mb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyId", MessageBundle.TITLE, Locale.US),
+                mb.getTitle(Locale.US, "defaultText"));
+    }
+
+    public void testWithArguments() {
+        String[] arguments = new String[]{"arg1", "arg2"};
+        MessageBundle mb = new MessageBundle("dummyId", arguments);
+        try {
+            mb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText arg1 arg2", mb.getText(Locale.US, "defaultText {0} {1}"));
+
+        addMockProvider();
+
+        assertEquals("Normal use", getFormattedMockString("dummyId", MessageBundle.TEXT, arguments, Locale.US),
+                mb.getText(Locale.US));
+        assertEquals("Normal use", getFormattedMockString("dummyId", MessageBundle.TITLE, arguments, Locale.US),
+                mb.getTitle(Locale.US));
+        assertEquals("Default not used", getFormattedMockString("dummyId", MessageBundle.TEXT, arguments, Locale.US),
+                mb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used", getFormattedMockString("dummyId", MessageBundle.TITLE, arguments, Locale.US),
+                mb.getTitle(Locale.US, "defaultText"));
+    }
+}

Added: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/TextBundleTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/TextBundleTest.java?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/TextBundleTest.java (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/TextBundleTest.java Tue May  3 04:53:01 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.commons.i18n.bundles;
+
+import org.apache.commons.i18n.MockProviderTestBase;
+import org.apache.commons.i18n.MessageNotFoundException;
+
+import java.util.Locale;
+
+/**
+ * @author Mattias Jiderhamn
+ */
+public class TextBundleTest extends MockProviderTestBase {
+    public void testWithoutArguments() {
+        TextBundle textBundle = new TextBundle("dummyId");
+        try {
+            textBundle.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText", textBundle.getText(Locale.US, "defaultText"));
+
+        addMockProvider();
+
+        assertEquals("Normal use", getMockString("dummyId", TextBundle.TEXT, Locale.US), textBundle.getText(Locale.US));
+        assertEquals("Default not used", getMockString("dummyId", TextBundle.TEXT, Locale.US),
+                textBundle.getText(Locale.US, "defaultText"));
+    }
+
+    public void testWithArguments() {
+        String[] arguments = new String[]{"arg1", "arg2"};
+        TextBundle textBundle = new TextBundle("dummyId", arguments);
+        try {
+            textBundle.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText arg1 arg2", textBundle.getText(Locale.US, "defaultText {0} {1}"));
+
+        addMockProvider();
+
+        assertEquals("Normal use", getFormattedMockString("dummyId", TextBundle.TEXT, arguments, Locale.US),
+                textBundle.getText(Locale.US));
+        assertEquals("Default not used", getFormattedMockString("dummyId", TextBundle.TEXT, arguments, Locale.US),
+                textBundle.getText(Locale.US, "defaultText"));
+    }
+}

Modified: jakarta/commons/sandbox/i18n/trunk/src/test/testMessages.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/testMessages.xml?rev=167900&r1=167899&r2=167900&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/testMessages.xml (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/testMessages.xml Tue May  3 04:53:01 2005
@@ -7,7 +7,15 @@
 			<entry key="text">hello world, we are in {0}.</entry>
 			<entry key="summary">sample summary to test english messages. Country = {0}, language = {1} and variant = {2}.</entry>
 			<entry key="details">sample deatils to test english messages. Country = {0}, language = {1} and variant = {2}.</entry>
+            <entry key="notTranslated">This entry is not translated to any other languages (XML)</entry>
 		</locale>
+        <!-- For Scottish translations, see http://www.whoohoo.co.uk/main.asp?pageid=scottie&topic=translator -->
+        <!--locale language="en" country="GB" variant="scottish">
+            <entry key="title">Awrite warld</entry>
+            <entry key="text">Awrite warld, we ur in {0}.</entry>
+            <entry key="summary">sample summary tae test english messages. Coontry = {0}, language = {1} and variant = {2}.</entry>
+            <entry key="details">sample deatils tae test english messages. Coontry = {0}, language = {1} and variant = {2}.</entry>
+        </locale-->
 		<locale language="pt" country="br">
 			<entry key="title">olo mundo</entry>
 			<entry key="text">hello mundo, nós estamos no {0}.</entry>

Added: jakarta/commons/sandbox/i18n/trunk/src/test/variantTestMessages.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/variantTestMessages.xml?rev=167900&view=auto
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/variantTestMessages.xml (added)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/variantTestMessages.xml Tue May  3 04:53:01 2005
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="iso-8859-1" ?>
+<messages>
+	<message id="variants">
+		<locale language="en">
+			<entry key="theKey">hello world</entry>
+		</locale>
+        <!-- For Scottish translations, see http://www.whoohoo.co.uk/main.asp?pageid=scottie&topic=translator -->
+        <locale language="en" country="GB" variant="scottish">
+            <entry key="theKey">Awrite warld</entry>
+        </locale>
+        <locale country="BW">
+            <entry key="theKey">Hello Botswana</entry>
+        </locale>
+        <locale language="en" variant="baby">
+            <entry key="theKey">Ga, ga, ga</entry>
+        </locale>
+	</message>
+</messages>
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[i18n] Missing check-in

Posted by Mattias J <mj...@expertsystem.se>.
Thanks for checking in the unit tests.
Although, you checked in the tests running against the refactored code, 
without checking in the refactoring. The test cases does not compile 
against the code in the repository. Please commit also the following patch 
(which I will also try to attach):




Index: src/java/org/apache/commons/i18n/MessageManager.java
===================================================================
--- src/java/org/apache/commons/i18n/MessageManager.java	(revision 168095)
+++ src/java/org/apache/commons/i18n/MessageManager.java	(arbetskopia)
@@ -20,12 +20,7 @@
  package org.apache.commons.i18n;

  import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
+import java.util.*;

  /**
   * The <code>MessageManager</code> provides methods for retrieving localized
@@ -46,7 +41,7 @@
   * <p>
   * You can call {@link 
MessageManager#getText(String,String,Object[],Locale) getText} directly,
   * but if you do so, you have to ensure that the given entry key really
- * exists and to deal with the {@link MessageNotFound} exception that will
+ * exists and to deal with the {@link MessageNotFoundException} exception 
that will
   * be thrown if you try to access a not existing entry.</p>
   *
   */
@@ -61,28 +56,33 @@

      public static final ResourceBundle INTERNAL_MESSAGES = 
ResourceBundle.getBundle("messages", Locale.getDefault());

-    private static List messageProviders = new ArrayList();
+    private static Map messageProviders = new LinkedHashMap();

-    static {
-        // Add default message providers
-        messageProviders.add(new XMLMessageProvider());
-        messageProviders.add(new ResourceBundleMessageProvider());
-    }
-
      /**
       * Add a custom <code>{@link MessageProvider}</code> to the
       * <code>MessageManager</code>. It will be incorporated in later calls of
       * the {@link MessageManager#getText(String,String,Object[],Locale) 
getText}
       * or {@link #getEntries(String,Locale) getEntries}methods.
-     *
+     *
+     * @param providerId Id of the provider used for uninstallation and
+     *          qualified naming.
       * @param messageProvider
       *            The <code>MessageProvider</code> to be added.
       */
-    public static void addMessageProvider(MessageProvider messageProvider) {
-        messageProviders.add(messageProvider);
+    public static void addMessageProvider(String providerId, 
MessageProvider messageProvider) {
+        messageProviders.put(providerId, messageProvider);
      }

      /**
+     * Remove custom <code>{@link MessageProvider}</code> from the
+     * <code>MessageManager</code>. Used for tearing down unit tests.
+     *
+     * @param providerId The ID of the provider to remove.
+     */
+    static void removeMessageProvider(String providerId) {
+        messageProviders.remove(providerId);
+    }
+    /**
       * Iterates over all registered message providers in order to find 
the given
       * entry in the requested message bundle.
       *
@@ -104,8 +104,10 @@
       */
      public static String getText(String id, String entry, Object[] arguments,
              Locale locale) throws MessageNotFoundException {
+        if(messageProviders.isEmpty())
+            throw new MessageNotFoundException("No MessageProvider 
registered");
          MessageNotFoundException exception = null;
-        for (Iterator i = messageProviders.iterator(); i.hasNext();) {
+        for (Iterator i = messageProviders.values().iterator(); 
i.hasNext();) {
              try {
                  String text = ((MessageProvider) i.next()).getText(id, entry,
                          locale);
@@ -140,10 +142,9 @@
      public static String getText(String id, String entry, Object[] arguments,
              Locale locale, String defaultText) {
          try {
-            String text = getText(id, entry, arguments, locale);
-            return MessageFormat.format(text, arguments);
+            return getText(id, entry, arguments, locale);
          } catch (MessageNotFoundException e) {
-            return defaultText;
+            return MessageFormat.format(defaultText, arguments);
          }
      }

@@ -155,12 +156,12 @@
       */
      public static Map getEntries(String id, Locale locale)
              throws MessageNotFoundException {
+        if(messageProviders.isEmpty())
+            throw new MessageNotFoundException("No MessageProvider 
registered");
          MessageNotFoundException exception = null;
-        for (Iterator i = messageProviders.iterator(); i.hasNext();) {
+        for (Iterator i = messageProviders.values().iterator(); 
i.hasNext();) {
              try {
-                Map entries = ((MessageProvider) i.next()).getEntries(id,
-                        locale);
-                return entries;
+                return ((MessageProvider) i.next()).getEntries(id, locale);
              } catch (MessageNotFoundException e) {
                  exception = e;
              }
Index: src/java/org/apache/commons/i18n/XMLMessageProvider.java
===================================================================
--- src/java/org/apache/commons/i18n/XMLMessageProvider.java	(revision 168095)
+++ src/java/org/apache/commons/i18n/XMLMessageProvider.java	(arbetskopia)
@@ -21,9 +21,7 @@

  import java.io.InputStream;
  import java.text.MessageFormat;
-import java.util.Collection;
  import java.util.HashMap;
-import java.util.Iterator;
  import java.util.Locale;
  import java.util.Map;
  import java.util.logging.Level;
@@ -41,13 +39,32 @@
   *
   */
  public class XMLMessageProvider implements MessageProvider {
-    private static Logger logger = 
Logger.getLogger(XMLMessageProvider.class.getName());
+    private static final Logger logger = 
Logger.getLogger(XMLMessageProvider.class.getName());

      private static SAXParserFactory factory = SAXParserFactory.newInstance();

-    private static Map installedMessages = new HashMap();
-    private static Map messages = new HashMap();
-
+    private final String id;
+
+    private Map messages = new HashMap();
+
+    public XMLMessageProvider(String id, InputStream inputStream) {
+        this.id = id;
+        try {
+            Map applicationMessages = new HashMap();
+            SAXParser parser = factory.newSAXParser();
+            ConfigurationHandler handler = new ConfigurationHandler();
+            parser.parse(new InputSource(inputStream), handler);
+            Map parsedMessages = handler.getMessages();
+            applicationMessages.putAll(parsedMessages);
+            messages.putAll(applicationMessages);
+        } catch (Exception exception) {
+            logger.log(Level.SEVERE,
+                    MessageFormat.format(
+ 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.MESSAGE_PARSING_ERROR),
+                    new String[] { id }), exception);
+        }
+    }
+
      /* (non-Javadoc)
       * @see 
org.apache.commons.i18n.MessageProvider#getText(java.lang.String, 
java.lang.String, java.util.Locale)
       */
@@ -72,33 +89,14 @@
       * @param inputStream providing the messages in the required XML format
       */
      public static void install(String id, InputStream inputStream) {
-        try {
-            Map applicationMessages = new HashMap();
-            SAXParser parser = factory.newSAXParser();
-            ConfigurationHandler handler = new ConfigurationHandler();
-            parser.parse(new InputSource(inputStream), handler);
-            Map parsedMessages = handler.getMessages();
-            applicationMessages.putAll(parsedMessages);
-            messages.putAll(applicationMessages);
-            installedMessages.put(id, applicationMessages.keySet());
-        } catch (Exception exception) {
-            logger.log(Level.SEVERE,
-                    MessageFormat.format(
- 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.MESSAGE_PARSING_ERROR),
-                    new String[] { id }), exception);
-        }
+        MessageManager.addMessageProvider(id, new XMLMessageProvider(id, 
inputStream));
      }

      /**
       * @param id unique identifier for the messages to uninstall
       */
      public static void uninstall(String id) {
-        Collection messageKeys = (Collection)installedMessages.get(id);
-        for ( Iterator i = messageKeys.iterator(); i.hasNext(); ) {
-            String messageKey = (String)i.next();
-            messages.remove(messageKey);
-        }
-        installedMessages.remove(id);
+        MessageManager.removeMessageProvider(id);
      }

      /**
@@ -110,7 +108,7 @@
          install(id, inputStream);
      }

-    private static Message findMessage(String id, Locale locale) {
+    private Message findMessage(String id, Locale locale) {
          Message message = lookupMessage(id, locale);
          if (message == null) {
              message = lookupMessage(id, Locale.getDefault());
@@ -122,13 +120,8 @@
          return message;
      }

-    private static Message lookupMessage(String id, Locale locale) {
-        StringBuffer keyBuffer = new StringBuffer(64);
-        keyBuffer.append(id);
-        if (locale.getLanguage() != null) keyBuffer.append("_" + 
locale.getLanguage());
-        if (locale.getCountry() != null) keyBuffer.append("_" + 
locale.getCountry());
-        if (locale.getVariant() != null) keyBuffer.append("_" + 
locale.getVariant());
-        String key = keyBuffer.toString();
+    private Message lookupMessage(String id, Locale locale) {
+        String key = id + '_' + locale.toString();
          if (messages.containsKey(key)) return (Message)messages.get(key);
          while (key.lastIndexOf('_') > 0) {
              key = key.substring(0, key.lastIndexOf('_'));
@@ -137,7 +130,7 @@
          return null;
      }

-    static class ConfigurationHandler extends DefaultHandler {
+    class ConfigurationHandler extends DefaultHandler {
          private String id, key;
          private Message message;
          private StringBuffer cData;
@@ -178,7 +171,8 @@
      }

      static class Message {
-        private String id, language, country, variant;
+        private final String id;
+        private String language, country, variant;
          private Map entries = new HashMap();

          public Message(String id) {
@@ -210,12 +204,9 @@
          }

          public String getKey() {
-            StringBuffer key = new StringBuffer(64);
-            key.append(id);
-            if (language != null) key.append("_" + language);
-            if (country != null) key.append("_" + country);
-            if (variant != null) key.append("_" + variant);
-            return key.toString();
+            return id + '_' + new Locale((language != null) ? language : "",
+                    (country != null) ? country : "",
+                    (variant != null) ? variant : "").toString();
          }
      }
  }
\ No newline at end of file
Index: src/java/org/apache/commons/i18n/LocalizedBundle.java
===================================================================
--- src/java/org/apache/commons/i18n/LocalizedBundle.java	(revision 168095)
+++ src/java/org/apache/commons/i18n/LocalizedBundle.java	(arbetskopia)
@@ -37,11 +37,10 @@
   * the key of the desired message entry.</p>
   * This class should not be used directly in order to retrieve entries of 
a message bundle. It is recommended
   * to subclass the <code>LocalizedBundle</code> class in order to define 
a specific localized bundle.
- * @see TextBundle, MessageBundle, ErrorBundle
+ * @see org.apache.commons.i18n.bundles.TextBundle, MessageBundle, ErrorBundle
   */
  public class LocalizedBundle implements Serializable {
      public final static String ID = "id";
-    public final static String ARGUMENTS = "arguments";

      protected String id;
      protected Object[] arguments;
@@ -97,7 +96,7 @@
       * @param defaultText the text to be returned if no entry was found 
for the given key
       * @return returns the text of the desired message entry for the 
given locale
       */
-    public String getEntry(String key, String defaultText, Locale locale) {
+    public String getEntry(String key, Locale locale, String defaultText) {
          return MessageManager.getText(id, key, arguments, locale, 
defaultText);
      }
  }
\ No newline at end of file
Index: src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
===================================================================
--- src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java 
(revision 168095)
+++ src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java 
(arbetskopia)
@@ -20,11 +20,8 @@
  package org.apache.commons.i18n;

  import java.text.MessageFormat;
-import java.util.ArrayList;
  import java.util.Enumeration;
  import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  import java.util.MissingResourceException;
@@ -40,35 +37,33 @@
  public class ResourceBundleMessageProvider implements MessageProvider {
      private static Logger logger = 
Logger.getLogger(ResourceBundleMessageProvider.class.getName());

-    private static List installedResourceBundles = new ArrayList();
+    private final String baseName;

+    public ResourceBundleMessageProvider(String baseName) {
+        this.baseName = baseName;
+    }
+
      /* (non-Javadoc)
       * @see 
org.apache.commons.i18n.MessageProvider#getText(java.lang.String, 
java.lang.String, java.util.Locale)
       */
      public String getText(String id, String entry, Locale locale) throws 
MessageNotFoundException {
-        for ( Iterator i = installedResourceBundles.iterator(); 
i.hasNext(); ) {
-            String baseName = (String)i.next();
-            try {
-                ResourceBundle resourceBundle = 
ResourceBundle.getBundle(baseName, locale);
-                try {
-                    return resourceBundle.getString(id+"."+entry);
-                } catch ( ClassCastException e ) {
-                    // ignore all entries that are not of type String
-                } catch ( MissingResourceException e ) {
-                    // skip resource bundle if it is not containing the 
desired entry
-                }
-            } catch ( MissingResourceException e ) {
-                logger.log(
-                        Level.WARNING,
-                        MessageFormat.format(
- 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.RESOURCE_BUNDLE_NOT_FOUND),
-                                new String[] { baseName }));
-                i.remove();
-            }
+        // TODO: Revise try/catch
+        try {
+            ResourceBundle resourceBundle = 
ResourceBundle.getBundle(baseName, locale);
+             return resourceBundle.getString(id+"."+entry);
+        } catch ( ClassCastException e ) {
+            // ignore all entries that are not of type String
          }
+        catch ( MissingResourceException e ) {
+            logger.log(
+                    Level.WARNING,
+                    MessageFormat.format(
+ 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.RESOURCE_BUNDLE_NOT_FOUND),
+                            new String[] { baseName }));
+        }
          throw new MessageNotFoundException(MessageFormat.format(
- 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.NO_MESSAGE_ENTRIES_FOUND),
-                new String[] { id }));
+ 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.NO_MESSAGE_ENTRIES_FOUND),
+            new String[] { id }));
      }

      /* (non-Javadoc)
@@ -77,27 +72,25 @@
      public Map getEntries(String id, Locale locale) {
          String messageIdentifier = id+".";
          Map entries = null;
-        for ( Iterator i = installedResourceBundles.iterator(); 
i.hasNext(); ) {
-            String baseName = (String)i.next();
-            try {
-                ResourceBundle resourceBundle = 
ResourceBundle.getBundle(baseName, locale);
-                Enumeration keys = resourceBundle.getKeys();
-                while ( keys.hasMoreElements() ) {
-                    String key = (String)keys.nextElement();
-                    if ( key.startsWith(messageIdentifier) ) {
-                        if ( entries == null ) {
-                            entries = new HashMap();
-                        }
- 
entries.put(key.substring(messageIdentifier.length()), 
resourceBundle.getString(key));
+        try {
+            ResourceBundle resourceBundle = 
ResourceBundle.getBundle(baseName, locale);
+            Enumeration keys = resourceBundle.getKeys();
+            while ( keys.hasMoreElements() ) {
+                String key = (String)keys.nextElement();
+                if ( key.startsWith(messageIdentifier) ) {
+                    if ( entries == null ) {
+                        entries = new HashMap();
                      }
+                    entries.put(key.substring(messageIdentifier.length()), 
resourceBundle.getString(key));
                  }
-            } catch ( MissingResourceException e ) {
-                logger.log(
-                        Level.WARNING,
-                        MessageFormat.format(
- 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.RESOURCE_BUNDLE_NOT_FOUND),
-                                new String[] { baseName }));
              }
+        } catch ( MissingResourceException e ) {
+            logger.log(
+                    Level.WARNING,
+                    MessageFormat.format(
+ 
MessageManager.INTERNAL_MESSAGES.getString(MessageManager.RESOURCE_BUNDLE_NOT_FOUND),
+                            new String[] { baseName }));
+            // TODO: Consider uninstalling
          }
          if ( entries == null ) {
              throw new MessageNotFoundException(MessageFormat.format(
@@ -117,15 +110,15 @@
       *
       */
      public static void install(String baseName) {
-        if ( !installedResourceBundles.contains(baseName) )
-            installedResourceBundles.add(baseName);
+        MessageManager.addMessageProvider(baseName,
+                new ResourceBundleMessageProvider(baseName));
      }

      /**
       * @param baseName unique identifier for the resource bundle to uninstall
       */
      public static void uninstall(String baseName) {
-        installedResourceBundles.remove(baseName);
+        MessageManager.removeMessageProvider(baseName); // TODO: Consider 
checkning type
      }

      /**
Index: src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
===================================================================
--- src/java/org/apache/commons/i18n/bundles/ErrorBundle.java	(revision 168095)
+++ src/java/org/apache/commons/i18n/bundles/ErrorBundle.java	(arbetskopia)
@@ -64,11 +64,11 @@

      /**
       * @param locale The locale that is used to find the appropriate 
localized text
-     * @param defaultText The default text will be returned, if no entry 
with key <code>summary</code> could be found in the message bundle 
identified by the given message identifier
+     * @param defaultSummary The default text will be returned, if no 
entry with key <code>summary</code> could be found in the message bundle 
identified by the given message identifier
       * @return returns the localized message entry with the key 
<code>summary</code>
       */
      public String getSummary(Locale locale, String defaultSummary) {
-        return getEntry(SUMMARY, defaultSummary, locale);
+        return getEntry(SUMMARY, locale, defaultSummary);
      }


@@ -83,10 +83,10 @@

      /**
       * @param locale The locale that is used to find the appropriate 
localized text
-     * @param defaultText The default text will be returned, if no entry 
with key <code>details</code> could be found in the message bundle 
identified by the given message identifier
+     * @param defaultDetails The default text will be returned, if no 
entry with key <code>details</code> could be found in the message bundle 
identified by the given message identifier
       * @return returns the localized message entry with the key 
<code>details</code>
       */
      public String getDetails(Locale locale, String defaultDetails) {
-        return getEntry(DETAILS, defaultDetails, locale);
+        return getEntry(DETAILS, locale, defaultDetails);
      }
  }
\ No newline at end of file
Index: src/java/org/apache/commons/i18n/bundles/TextBundle.java
===================================================================
--- src/java/org/apache/commons/i18n/bundles/TextBundle.java	(revision 168095)
+++ src/java/org/apache/commons/i18n/bundles/TextBundle.java	(arbetskopia)
@@ -67,6 +67,6 @@
       * @return returns the localized message entry with the key 
<code>text</code>
       */
      public String getText(Locale locale, String defaultText) {
-        return getEntry(TEXT, defaultText, locale);
+        return getEntry(TEXT, locale, defaultText);
      }
  }
\ No newline at end of file
Index: src/java/org/apache/commons/i18n/bundles/MessageBundle.java
===================================================================
--- src/java/org/apache/commons/i18n/bundles/MessageBundle.java	(revision 
168095)
+++ src/java/org/apache/commons/i18n/bundles/MessageBundle.java	(arbetskopia)
@@ -62,10 +62,10 @@

      /**
       * @param locale The locale that is used to find the appropriate 
localized text
-     * @param defaultText The default text will be returned, if no entry 
with key <code>title</code> could be found in the message bundle identified 
by the given message identifier
+     * @param defaultTitle The default text will be returned, if no entry 
with key <code>title</code> could be found in the message bundle identified 
by the given message identifier
       * @return returns the localized message entry with the key 
<code>title</code>
       */
-    public String getTitle(Locale locale, String defaultSummary) {
-        return getEntry(TITLE, defaultSummary, locale);
+    public String getTitle(Locale locale, String defaultTitle) {
+        return getEntry(TITLE, locale, defaultTitle);
      }
  }
\ No newline at end of file