You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Mattias J <ma...@expertsystem.se> on 2005/05/14 18:05:31 UTC

Directory dissapeared from SVN

I have made some changes to the i18n sandbox project and tried to create a 
patch for it to submit, although I noticed the patch did not contain 
everything I expected. At first I thought I had done something wrong, but 
after several tries I realized the i18n package has dissapeared from the 
test source dir in SVN; see 
http://svn.apache.org/repos/asf/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/

I have not seen any commit removing this directory (which would also be 
rather surprising), so I'm wondering has happened???

Thanks in advance,
   Mattias Jiderhamn


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


Re: [sandbox/i18n] Somebody please re-add

Posted by James Mitchell <jm...@apache.org>.
done.



--
James Mitchell
Software Engineer / Open Source Evangelist
Consulting / Mentoring / Freelance
EdgeTech, Inc.
http://www.edgetechservices.net/
678.910.8017
AIM:   jmitchtx
Yahoo: jmitchtx
MSN:   jmitchell@apache.org




----- Original Message ----- 
From: "Mattias J" <ma...@expertsystem.se>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Wednesday, May 18, 2005 2:54 AM
Subject: [sandbox/i18n] Somebody please re-add


Daniel Florey seems to be unavailable at the time, so is there somebody
else with sandbox access that would be so kind to re-add the i18n test
cases that were added/modified in rev 167900 and accidentally removed in
rev 168590?

The diff is inlined below, but I will probably have to e-mail you a diff
file off list, to make sure wrapping and line breaks are intact.



Index: src/test/org/apache/commons/i18n/MessageManagerTest.java
===================================================================
--- src/test/org/apache/commons/i18n/MessageManagerTest.java (revision 0)
+++ src/test/org/apache/commons/i18n/MessageManagerTest.java (revision 0)
@@ -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
Index: src/test/org/apache/commons/i18n/MockProviderTestBase.java
===================================================================
--- src/test/org/apache/commons/i18n/MockProviderTestBase.java (revision 0)
+++ src/test/org/apache/commons/i18n/MockProviderTestBase.java (revision 0)
@@ -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);
+    }
+}
Index: src/test/org/apache/commons/i18n/LocalizedBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedBundleTest.java (revision 0)
+++ src/test/org/apache/commons/i18n/LocalizedBundleTest.java (revision 0)
@@ -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"));
+    }
+}
Index: src/test/org/apache/commons/i18n/LocalizedErrorTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedErrorTest.java (revision 0)
+++ src/test/org/apache/commons/i18n/LocalizedErrorTest.java (revision 0)
@@ -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());
+    }
+}
Index: src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java
===================================================================
--- src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java
(revision 0)
+++ src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java
(revision 0)
@@ -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"));
+    }
+}
Index: src/test/org/apache/commons/i18n/XMLMessageProviderTest.java
===================================================================
--- src/test/org/apache/commons/i18n/XMLMessageProviderTest.java (revision 
0)
+++ src/test/org/apache/commons/i18n/XMLMessageProviderTest.java (revision 
0)
@@ -0,0 +1,187 @@
+/*
+*
+* ====================================================================
+*
+* Copyright 2004 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;
+
+import org.apache.commons.i18n.bundles.MessageBundle;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Daniel Florey
+ *
+ */
+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() {
+        MessageBundle testMessage = new MessageBundle("helloWorld");
+
+        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.
+     */
+    public XMLMessageProviderTest(String testName) {
+        super(testName);
+    }
+}
Index: 
src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java
===================================================================
--- src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java
(revision 0)
+++ src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java
(revision 0)
@@ -0,0 +1,168 @@
+/*
+*
+* ====================================================================
+*
+* Copyright 2004 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;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.i18n.bundles.MessageBundle;
+
+/**
+ * @author Daniel Florey
+ *
+ */
+public class ResourceBundleMessageProviderTest extends TestCase {
+    public ResourceBundleMessageProviderTest(String testName) {
+        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() {
+        MessageBundle testMessage = new MessageBundle("helloWorld");
+
+        try {
+            testMessage.getTitle(Locale.GERMAN);
+            fail("ResourceBundle not installed, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", 
mnfex.getMessage());
+        }
+
+        ResourceBundleMessageProvider.install("messageBundle");
+
+        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 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());
+        }
+    }
+}
\ No newline at end of file
Index: src/test/org/apache/commons/i18n/MyListResourceBundle.java
===================================================================
--- src/test/org/apache/commons/i18n/MyListResourceBundle.java (revision 0)
+++ src/test/org/apache/commons/i18n/MyListResourceBundle.java (revision 0)
@@ -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
+    };
+}
Index: src/test/org/apache/commons/i18n/LocalizedExceptionTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedExceptionTest.java (revision 
0)
+++ src/test/org/apache/commons/i18n/LocalizedExceptionTest.java (revision 
0)
@@ -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());
+    }
+}
Index: src/test/org/apache/commons/i18n/I18nTestSuite.java
===================================================================
--- src/test/org/apache/commons/i18n/I18nTestSuite.java (revision 0)
+++ src/test/org/apache/commons/i18n/I18nTestSuite.java (revision 0)
@@ -0,0 +1,38 @@
+/*
+*
+* ====================================================================
+*
+* Copyright 2004 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.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Daniel Florey
+ *
+ */
+public class I18nTestSuite extends TestSuite {
+    public static void main(java.lang.String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+
+    public static Test suite() {
+        TestSuite suite = new
TestSuite(ResourceBundleMessageProviderTest.class);
+        return suite;
+    }
+}
Index: src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java
(revision 0)
+++ src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java
(revision 0)
@@ -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());
+    }
+}
Index: src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java (revision 
0)
+++ src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java (revision 
0)
@@ -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
Index: src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java
(revision 0)
+++ src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java
(revision 0)
@@ -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"));
+    }
+}
Index: src/test/org/apache/commons/i18n/bundles/TextBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/bundles/TextBundleTest.java (revision 
0)
+++ src/test/org/apache/commons/i18n/bundles/TextBundleTest.java (revision 
0)
@@ -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"));
+    }
+}


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




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


[sandbox/i18n] Somebody please re-add

Posted by Mattias J <ma...@expertsystem.se>.
Daniel Florey seems to be unavailable at the time, so is there somebody 
else with sandbox access that would be so kind to re-add the i18n test 
cases that were added/modified in rev 167900 and accidentally removed in 
rev 168590?

The diff is inlined below, but I will probably have to e-mail you a diff 
file off list, to make sure wrapping and line breaks are intact.



Index: src/test/org/apache/commons/i18n/MessageManagerTest.java
===================================================================
--- src/test/org/apache/commons/i18n/MessageManagerTest.java	(revision 0)
+++ src/test/org/apache/commons/i18n/MessageManagerTest.java	(revision 0)
@@ -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
Index: src/test/org/apache/commons/i18n/MockProviderTestBase.java
===================================================================
--- src/test/org/apache/commons/i18n/MockProviderTestBase.java	(revision 0)
+++ src/test/org/apache/commons/i18n/MockProviderTestBase.java	(revision 0)
@@ -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);
+    }
+}
Index: src/test/org/apache/commons/i18n/LocalizedBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedBundleTest.java	(revision 0)
+++ src/test/org/apache/commons/i18n/LocalizedBundleTest.java	(revision 0)
@@ -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"));
+    }
+}
Index: src/test/org/apache/commons/i18n/LocalizedErrorTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedErrorTest.java	(revision 0)
+++ src/test/org/apache/commons/i18n/LocalizedErrorTest.java	(revision 0)
@@ -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());
+    }
+}
Index: src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java
===================================================================
--- src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java 
(revision 0)
+++ src/test/org/apache/commons/i18n/MessageNotFoundExceptionTest.java 
(revision 0)
@@ -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"));
+    }
+}
Index: src/test/org/apache/commons/i18n/XMLMessageProviderTest.java
===================================================================
--- src/test/org/apache/commons/i18n/XMLMessageProviderTest.java	(revision 0)
+++ src/test/org/apache/commons/i18n/XMLMessageProviderTest.java	(revision 0)
@@ -0,0 +1,187 @@
+/*
+*
+* ====================================================================
+*
+* Copyright 2004 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;
+
+import org.apache.commons.i18n.bundles.MessageBundle;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Daniel Florey
+ *
+ */
+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() {
+        MessageBundle testMessage = new MessageBundle("helloWorld");
+
+        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.
+     */
+    public XMLMessageProviderTest(String testName) {
+        super(testName);
+    }
+}
Index: src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java
===================================================================
--- src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java 
(revision 0)
+++ src/test/org/apache/commons/i18n/ResourceBundleMessageProviderTest.java 
(revision 0)
@@ -0,0 +1,168 @@
+/*
+*
+* ====================================================================
+*
+* Copyright 2004 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;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.i18n.bundles.MessageBundle;
+
+/**
+ * @author Daniel Florey
+ *
+ */
+public class ResourceBundleMessageProviderTest extends TestCase {
+    public ResourceBundleMessageProviderTest(String testName) {
+        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() {
+        MessageBundle testMessage = new MessageBundle("helloWorld");
+
+        try {
+            testMessage.getTitle(Locale.GERMAN);
+            fail("ResourceBundle not installed, should throw exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("No MessageProvider registered", mnfex.getMessage());
+        }
+
+        ResourceBundleMessageProvider.install("messageBundle");
+
+        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 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());
+        }
+    }
+}
\ No newline at end of file
Index: src/test/org/apache/commons/i18n/MyListResourceBundle.java
===================================================================
--- src/test/org/apache/commons/i18n/MyListResourceBundle.java	(revision 0)
+++ src/test/org/apache/commons/i18n/MyListResourceBundle.java	(revision 0)
@@ -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
+    };
+}
Index: src/test/org/apache/commons/i18n/LocalizedExceptionTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedExceptionTest.java	(revision 0)
+++ src/test/org/apache/commons/i18n/LocalizedExceptionTest.java	(revision 0)
@@ -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());
+    }
+}
Index: src/test/org/apache/commons/i18n/I18nTestSuite.java
===================================================================
--- src/test/org/apache/commons/i18n/I18nTestSuite.java	(revision 0)
+++ src/test/org/apache/commons/i18n/I18nTestSuite.java	(revision 0)
@@ -0,0 +1,38 @@
+/*
+*
+* ====================================================================
+*
+* Copyright 2004 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.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Daniel Florey
+ *
+ */
+public class I18nTestSuite extends TestSuite {
+    public static void main(java.lang.String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+
+    public static Test suite() {
+        TestSuite suite = new 
TestSuite(ResourceBundleMessageProviderTest.class);
+        return suite;
+    }
+}
Index: src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java
===================================================================
--- src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java 
(revision 0)
+++ src/test/org/apache/commons/i18n/LocalizedRuntimeExceptionTest.java 
(revision 0)
@@ -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());
+    }
+}
Index: src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java	(revision 0)
+++ src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java	(revision 0)
@@ -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
Index: src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java 
(revision 0)
+++ src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java 
(revision 0)
@@ -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"));
+    }
+}
Index: src/test/org/apache/commons/i18n/bundles/TextBundleTest.java
===================================================================
--- src/test/org/apache/commons/i18n/bundles/TextBundleTest.java	(revision 0)
+++ src/test/org/apache/commons/i18n/bundles/TextBundleTest.java	(revision 0)
@@ -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"));
+    }
+}


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


[i18n] Re: Directory dissapeared from SVN

Posted by Mattias J <ma...@expertsystem.se>.
Daniel, something strange must have happened here. First the latest tests 
but not the refactorings were checked in, so that the tests did not 
compile. Then the refactorings were checked in, and all the test classes 
were removed...?

Will you re-add the files so that I can create a diff, or should I just 
send you a ZIP will all the updated sources files?

At 2005-05-14 19:00, Martin Cooper wrote:
>According to the Subversion logs, this change was part of a patch that
>was supplied by you. Here's the relevant log entry:
>
>------------------------------------------------------------------------
>r168590 | dflorey | 2005-05-06 03:36:38 -0700 (Fri, 06 May 2005) | 1 line
>Changed paths:
>    M /jakarta/commons/sandbox/i18n/trunk/project.properties
>    M /jakarta/commons/sandbox/i18n/trunk/project.xml
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExceptionExample.java
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/LocalizedBundle.java
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/XMLMessageProvider.java
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
>    M 
> /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/TextBundle.java
>    D /jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n
>    D /jakarta/commons/sandbox/i18n/trunk/xdocs/downloads.xml
>    M /jakarta/commons/sandbox/i18n/trunk/xdocs/index.xml
>
>Incorporated changes proposed by Mattias J
>------------------------------------------------------------------------
>
>--
>Martin Cooper
>
>
>On 5/14/05, Mattias J <ma...@expertsystem.se> wrote:
> > I have made some changes to the i18n sandbox project and tried to create a
> > patch for it to submit, although I noticed the patch did not contain
> > everything I expected. At first I thought I had done something wrong, but
> > after several tries I realized the i18n package has dissapeared from the
> > test source dir in SVN; see
> > 
> http://svn.apache.org/repos/asf/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/
> >
> > I have not seen any commit removing this directory (which would also be
> > rather surprising), so I'm wondering has happened???


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


Re: Directory dissapeared from SVN

Posted by Martin Cooper <mf...@gmail.com>.
According to the Subversion logs, this change was part of a patch that
was supplied by you. Here's the relevant log entry:

------------------------------------------------------------------------
r168590 | dflorey | 2005-05-06 03:36:38 -0700 (Fri, 06 May 2005) | 1 line
Changed paths:
   M /jakarta/commons/sandbox/i18n/trunk/project.properties
   M /jakarta/commons/sandbox/i18n/trunk/project.xml
   M /jakarta/commons/sandbox/i18n/trunk/src/examples/org/apache/i18n/examples/LocalizedExceptionExample.java
   M /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/LocalizedBundle.java
   M /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
   M /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
   M /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/XMLMessageProvider.java
   M /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
   M /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
   M /jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/TextBundle.java
   D /jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n
   D /jakarta/commons/sandbox/i18n/trunk/xdocs/downloads.xml
   M /jakarta/commons/sandbox/i18n/trunk/xdocs/index.xml

Incorporated changes proposed by Mattias J
------------------------------------------------------------------------

--
Martin Cooper


On 5/14/05, Mattias J <ma...@expertsystem.se> wrote:
> I have made some changes to the i18n sandbox project and tried to create a
> patch for it to submit, although I noticed the patch did not contain
> everything I expected. At first I thought I had done something wrong, but
> after several tries I realized the i18n package has dissapeared from the
> test source dir in SVN; see
> http://svn.apache.org/repos/asf/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/
> 
> I have not seen any commit removing this directory (which would also be
> rather surprising), so I'm wondering has happened???
> 
> Thanks in advance,
>    Mattias Jiderhamn
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
>

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