commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dflo...@apache.org
Subject svn commit: r167900 - in /jakarta/commons/sandbox/i18n/trunk/src/test: ./ org/apache/commons/i18n/ org/apache/commons/i18n/bundles/
Date Tue, 03 May 2005 11:53:01 GMT
Author: dflorey
Date: Tue May  3 04:53:01 2005
New Revision: 167900

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



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


Mime
View raw message