commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dflo...@apache.org
Subject svn commit: r171112 - in /jakarta/commons/sandbox/i18n/trunk/src: java/org/apache/commons/i18n/ java/org/apache/commons/i18n/bundles/ test/org/apache/commons/i18n/ test/org/apache/commons/i18n/bundles/
Date Fri, 20 May 2005 12:50:07 GMT
Author: dflorey
Date: Fri May 20 05:50:06 2005
New Revision: 171112

URL: http://svn.apache.org/viewcvs?rev=171112&view=rev
Log:
Applied patch from Mattias J to improve performance and enable identical message keys in different providers

Modified:
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/LocalizedBundle.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
    jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/TextBundle.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/I18nTestSuite.java
    jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.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/MockProviderTestBase.java
    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/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

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/LocalizedBundle.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/LocalizedBundle.java?rev=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/LocalizedBundle.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/LocalizedBundle.java Fri May 20 05:50:06 2005
@@ -42,16 +42,25 @@
 public class LocalizedBundle implements Serializable {
     public final static String ID = "id";
 
+    protected String providerId;
     protected String id;
     protected Object[] arguments;
 
+  /**
+   * @param providerId The name of the message provider (i.e. source) to use for the message
+   * @param messageId The messageId refers the corresponding bundle in the file containing
+   * the localized messages.
+   */
+  public LocalizedBundle(String providerId, String messageId) {
+      this(providerId, messageId, new Object[0]);
+  }
+
     /**
      * @param messageId The messageId refers the corresponding bundle in the file containing
      * the localized messages.
      */
     public LocalizedBundle(String messageId) {
-        this.id = messageId;
-        this.arguments = new Object[0];
+        this(messageId, new Object[0]);
     }
 
     /**
@@ -65,6 +74,19 @@
         this.arguments = arguments;
     }
 
+  /**
+   * @param providerId The name of the message provider (i.e. source) to use for the message
+   * @param messageId The messageId refers the corresponding bundle in the file containing
+   * the localized messages.
+   * @param arguments An array of objects containing arguments for the messages. These arguments
+   * are used to insert dynamic values into the localized messages.
+   */
+  public LocalizedBundle(String providerId, String messageId, Object[] arguments) {
+    this.providerId = providerId;
+    this.id = messageId;
+      this.arguments = arguments;
+  }
+
     /**
      * @return returns the id of this bundle
      */
@@ -78,7 +100,14 @@
     public Object[] getArguments() {
     	return arguments;
     }
-    
+
+    /**
+     * @return The name of the message provider (i.e. source) to use for the message  
+     */
+    public String getProviderId() {
+        return providerId;
+    }
+
     /**
      * @param key the key of the specific message entry in the message bundle
      * @param locale the locale for that this message should be rendered
@@ -87,7 +116,9 @@
      * in this bundle
      */
     public String getEntry(String key, Locale locale) throws MessageNotFoundException {
-        return MessageManager.getText(id, key, arguments, locale);
+        return providerId != null ?
+            MessageManager.getText(providerId, id, key, arguments, locale) :
+            MessageManager.getText(id, key, arguments, locale);
     }
 
     /**
@@ -97,6 +128,8 @@
      * @return returns the text of the desired message entry for the given locale  
      */
     public String getEntry(String key, Locale locale, String defaultText) {
-        return MessageManager.getText(id, key, arguments, locale, defaultText);
+        return providerId != null ?
+            MessageManager.getText(providerId, id, key, arguments, locale, defaultText) :
+            MessageManager.getText(id, key, arguments, locale, defaultText);
     }
 }

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java?rev=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/MessageManager.java Fri May 20 05:50:06 2005
@@ -74,6 +74,14 @@
     }
 
     /**
+     * Remove all <code>{@link MessageProvider}</code>s from the
+     * <code>MessageManager</code>. Used for tearing down unit tests.
+     */
+    static void clearMessageProviders() {
+        messageProviders.clear();
+    }
+
+    /**
      * Remove custom <code>{@link MessageProvider}</code> from the
      * <code>MessageManager</code>. Used for tearing down unit tests.
      *
@@ -82,6 +90,7 @@
     static void removeMessageProvider(String providerId) {
         messageProviders.remove(providerId);
     }
+
     /**
      * Iterates over all registered message providers in order to find the given
      * entry in the requested message bundle.
@@ -149,6 +158,64 @@
     }
 
     /**
+     * Tries to find the desired entry in the named message provider.
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param id
+     *            The identifier that will be used to retrieve the message
+     *            bundle
+     * @param entry
+     *            The desired message entry
+     * @param arguments
+     *            The dynamic parts of the message that will be evaluated using
+     *            the standard java text formatting abilities.
+     * @param locale
+     *            The locale in which the message will be printed
+     * @exception MessageNotFoundException
+     *                Will be thrown if the requested message provider cannot be found or
+     *                no message bundle can be found for the given id or if the desired
+     *                message entry is missing in the retrieved bundle
+     * @return The localized text
+     */
+    public static String getText(String providerId, String id, String entry, Object[] arguments,
+            Locale locale) throws MessageNotFoundException {
+        MessageProvider provider = (MessageProvider) messageProviders.get(providerId);
+        if(provider == null)
+            throw new MessageNotFoundException("Provider '" + providerId + "' not installed");
+        String text = provider.getText(id, entry, locale);
+        return MessageFormat.format(text, arguments);
+    }
+
+    /**
+     * Iterates over all registered message providers in order to find the given
+     * entry in the requested message bundle.
+     *
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param id
+     *            The identifier that will be used to retrieve the message
+     *            bundle
+     * @param entry
+     *            The desired message entry
+     * @param arguments
+     *            The dynamic parts of the message that will be evaluated using
+     *            the standard java text formatting abilities.
+     * @param locale
+     *            The locale in which the message will be printed
+     * @param defaultText
+     *            If no message bundle or message entry could be found for the
+     *            specified parameters, the default text will be returned.
+     * @return The localized text or the default text if the message could not
+     *         be found
+     */
+    public static String getText(String providerId, String id, String entry, Object[] arguments,
+            Locale locale, String defaultText) {
+        try {
+            return getText(providerId, id, entry, arguments, locale);
+        } catch (MessageNotFoundException e) {
+            return MessageFormat.format(defaultText, arguments);
+        }
+    }
+
+    /**
      * Returns a map containing all available message entries for the given
      * locale. The map contains keys of type {@link String}containing the keys
      * of the available message entries and values of type {@link String}
@@ -168,4 +235,18 @@
         }
         throw exception;
     }
+
+  /**
+   * Returns a map containing all available message entries for the given
+   * locale. The map contains keys of type {@link String}containing the keys
+   * of the available message entries and values of type {@link String}
+   * containing the localized message entries.
+   */
+  public static Map getEntries(String providerId, String id, Locale locale)
+          throws MessageNotFoundException {
+      MessageProvider provider = (MessageProvider) messageProviders.get(providerId);
+      if(provider == null)
+          throw new MessageNotFoundException("Provider '" + providerId + "' not installed");
+      return provider.getEntries(id, locale);
+  }
 }

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java?rev=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/ResourceBundleMessageProvider.java Fri May 20 05:50:06 2005
@@ -47,12 +47,9 @@
      * @see org.apache.commons.i18n.MessageProvider#getText(java.lang.String, java.lang.String, java.util.Locale)
      */
     public String getText(String id, String entry, Locale locale) throws MessageNotFoundException {
-        // TODO: Revise try/catch
         try {
             ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName, locale);
-             return resourceBundle.getString(id+"."+entry);
-        } catch ( ClassCastException e ) {
-            // ignore all entries that are not of type String
+             return resourceBundle.getObject(id+"."+entry).toString();
         }
         catch ( MissingResourceException e ) {
             logger.log(

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java?rev=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/ErrorBundle.java Fri May 20 05:50:06 2005
@@ -45,12 +45,30 @@
     }
 
     /**
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param messageId Unique message id that identifies the message
+     */
+    public ErrorBundle(String providerId, String messageId) {
+        super(providerId, messageId);
+    }
+
+    /**
      * @param messageId Unique message id that identifies the message 
      * @param arguments An array of objects conaining the values that should be
      * inserted into the localized message.  
      */
     public ErrorBundle(String messageId, Object[] arguments) {
         super(messageId, arguments);
+    }
+
+    /**
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param messageId Unique message id that identifies the message
+     * @param arguments An array of objects conaining the values that should be
+     * inserted into the localized message.
+     */
+    public ErrorBundle(String providerId, String messageId, Object[] arguments) {
+        super(providerId, messageId, arguments);
     }
 
     /**

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java?rev=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/MessageBundle.java Fri May 20 05:50:06 2005
@@ -42,6 +42,14 @@
     }
 
     /**
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param messageId Unique message id that identifies the message
+     */
+    public MessageBundle(String providerId, String messageId) {
+        super(providerId, messageId);
+    }
+
+    /**
      * @param messageId Unique message id that identifies the message 
      * @param arguments An array of objects conaining the values that should be
      * inserted into the localized message.  
@@ -50,6 +58,15 @@
         super(messageId, arguments);
     }
 
+    /**
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param messageId Unique message id that identifies the message
+     * @param arguments An array of objects conaining the values that should be
+     * inserted into the localized message.
+     */
+    public MessageBundle(String providerId, String messageId, Object[] arguments) {
+        super(providerId, messageId, arguments);
+    }
 
     /**
      * @param locale The locale that is used to find the appropriate localized text 

Modified: jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/TextBundle.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/TextBundle.java?rev=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/TextBundle.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/java/org/apache/commons/i18n/bundles/TextBundle.java Fri May 20 05:50:06 2005
@@ -44,12 +44,30 @@
     }
 
     /**
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param messageId Unique message id that identifies the message
+     */
+    public TextBundle(String providerId, String messageId) {
+        super(providerId, messageId);
+    }
+
+    /**
      * @param messageId Unique message id that identifies the message 
      * @param arguments An array of objects conaining the values that should be
      * inserted into the localized message.  
      */
     public TextBundle(String messageId, Object[] arguments) {
         super(messageId, arguments);
+    }
+
+    /**
+     * @param providerId The name of the message provider (i.e. source) to use for the message
+     * @param messageId Unique message id that identifies the message
+     * @param arguments An array of objects conaining the values that should be
+     * inserted into the localized message.
+     */
+    public TextBundle(String providerId, String messageId, Object[] arguments) {
+        super(providerId, messageId, arguments);
     }
 
     /**

Modified: jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/I18nTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/I18nTestSuite.java?rev=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/I18nTestSuite.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/I18nTestSuite.java Fri May 20 05:50:06 2005
@@ -2,7 +2,7 @@
 *
 * ====================================================================
 *
-* Copyright 2004 The Apache Software Foundation
+* 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.

Modified: 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=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/LocalizedBundleTest.java Fri May 20 05:50:06 2005
@@ -24,21 +24,38 @@
 public class LocalizedBundleTest extends MockProviderTestBase {
     public void testConstructors() {
         LocalizedBundle lb = new LocalizedBundle("dummyId1");
+        assertNull("No provider", lb.getProviderId());
         assertEquals("Id set", "dummyId1", lb.getId());
         assertNotNull("Arguments not null", lb.getArguments());
         assertEquals("No arguments", 0, lb.getArguments().length);
 
+        LocalizedBundle lbProvider = new LocalizedBundle("dummyProvider2", "dummyId2");
+        assertEquals("Provider set", "dummyProvider2", lbProvider.getProviderId());
+        assertEquals("Id set", "dummyId2", lbProvider.getId());
+        assertNotNull("Arguments not null", lbProvider.getArguments());
+        assertEquals("No arguments", 0, lbProvider.getArguments().length);
+
         String[] arguments = new String[]{"arg1", "arg2"};
-        LocalizedBundle lbArgs = new LocalizedBundle("dummyId2", arguments);
-        assertEquals("Id set", "dummyId2", lbArgs.getId());
+        LocalizedBundle lbArgs = new LocalizedBundle("dummyId3", arguments);
+        assertNull("No provider", lbArgs.getProviderId());
+        assertEquals("Id set", "dummyId3", lbArgs.getId());
         assertNotNull("Arguments not null", lbArgs.getArguments());
         assertEquals("No of arguments", 2, lbArgs.getArguments().length);
         assertEquals("Arguments", arguments, lbArgs.getArguments());
+
+        LocalizedBundle lbProviderArgs = new LocalizedBundle("dummyProvider4", "dummyId4", arguments);
+        assertEquals("Provider set", "dummyProvider4", lbProviderArgs.getProviderId());
+        assertEquals("Id set", "dummyId4", lbProviderArgs.getId());
+        assertNotNull("Arguments not null", lbProviderArgs.getArguments());
+        assertEquals("No of arguments", 2, lbProviderArgs.getArguments().length);
+        assertEquals("Arguments", arguments, lbProviderArgs.getArguments());
     }
 
     public void testGetEntry() {
         LocalizedBundle lb = new LocalizedBundle("dummyId1");
-        LocalizedBundle lbArgs = new LocalizedBundle("dummyId2", new String[] {"arg1", "arg2"});
+        LocalizedBundle lbProvider = new LocalizedBundle("dummyProvider2", "dummyId2");
+        LocalizedBundle lbArgs = new LocalizedBundle("dummyId3", new String[] {"arg1", "arg2"});
+        LocalizedBundle lbProviderArgs = new LocalizedBundle("dummyProvider4", "dummyId4", new String[] {"arg1", "arg2"});
 
         // Test errors
         try {
@@ -63,15 +80,53 @@
 
         addMockProvider(); // Add mock provider
 
-        assertEquals("Default text not used", "Id=dummyId1 Entry=dummyEntry Locale=en_US",
+        assertEquals("Default text not used", getMockString("dummyId1", "dummyEntry", Locale.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",
+        assertEquals("Normal lookup", getMockString("dummyId1", "entry", Locale.US), lb.getEntry("entry", Locale.US));
+        assertEquals("Arguments missing", "Source=mock 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",
+        assertEquals("Argument", "Source=mock Id=dummyId3 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",
+        assertEquals("Arguments and default", "Source=mock Id=dummyId3 Entry=entry arg1 arg2 Locale=en_US",
                 lbArgs.getEntry("entry {0} {1}", Locale.US, "defaultText"));
+
+        // Named provider not found
+        try {
+            lbProvider.getEntry("dummyEntry", Locale.US);
+            fail("Unknown provider should throw Exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "Provider 'dummyProvider2' not installed", mnfex.getMessage());
+        }
+
+        try {
+            lbProviderArgs.getEntry("dummyEntry", Locale.US);
+            fail("Unknown provider should throw Exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "Provider 'dummyProvider4' not installed", mnfex.getMessage());
+        }
+
+        assertEquals("Default text", "defaultText", lbProvider.getEntry("dummyEntry", Locale.US, "defaultText"));
+        assertEquals("Default text", "defaultText", lbProviderArgs.getEntry("dummyEntry", Locale.US, "defaultText"));
+
+        // Named provider found
+        addMockProvider("dummyProvider2");
+        addMockProvider("dummyProvider4");
+
+        assertEquals("Named provider: Default text not used",
+                getMockString("dummyProvider2", "dummyId2", "dummyEntry", Locale.US),
+                lbProvider.getEntry("dummyEntry", Locale.US, "defaltText"));
+
+        assertEquals("Named provider: Normal lookup", getMockString("dummyProvider2", "dummyId2", "entry", Locale.US),
+                lbProvider.getEntry("entry", Locale.US));
+        assertEquals("Named provider: Arguments missing", "Source=dummyProvider2 Id=dummyId2 Entry=entry {0} Locale=en_US",
+                lbProvider.getEntry("entry {0}", Locale.US));
+        assertEquals("Named provider: Argument", "Source=dummyProvider4 Id=dummyId4 Entry=entry arg1 arg2 Locale=en_US",
+                lbProviderArgs.getEntry("entry {0} {1}", Locale.US));
+        assertEquals("Named provider: Arguments and default",
+                "Source=dummyProvider4 Id=dummyId4 Entry=entry arg1 arg2 Locale=en_US",
+                lbProviderArgs.getEntry("entry {0} {1}", Locale.US, "defaultText"));
     }
 }

Modified: 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=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageManagerTest.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MessageManagerTest.java Fri May 20 05:50:06 2005
@@ -55,26 +55,48 @@
 
         addMockProvider(); // Add mock provider
 
-        assertEquals("Throwing mock not used", "Id=dummyId Entry=dummyEntry Locale=en_US",
+        assertEquals("Throwing mock not used", "Source=mock 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",
+        assertEquals("Default text not used", "Source=mock 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",
+        assertEquals("Normal lookup", "Source=mock 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",
+                "Source=mock 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",
+                "Source=mock 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",
+                "Source=mock Id=id Entry=entry value1 Locale=en_US",
                 MessageManager.getText("id", "entry {0}", new String[] {"value1"},Locale.US, "defaultText"));
+
+        // Named provider not found
+        try {
+            MessageManager.getText("mockProvider2", "dummyId", "dummyEntry", null, Locale.US);
+            fail("Unknown provider should throw Exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "Provider 'mockProvider2' not installed", mnfex.getMessage());
+        }
+
+        assertEquals("Default text used", "defaultText",
+                MessageManager.getText("mockProvider2", "dummyId", "dummyEntry", null, Locale.US, "defaultText"));
+
+
+        // Named provider found
+        addMockProvider("mockProvider2");
+
+        assertEquals("Default text not used, qualified lookup", "Source=mockProvider2 Id=dummyId Entry=dummyEntry Locale=en_US",
+                MessageManager.getText("mockProvider2", "dummyId", "dummyEntry", null, Locale.US, "defaultText"));
+
+        assertEquals("Normal qualified lookup", "Source=mockProvider2 Id=id Entry=entry Locale=en_US",
+                MessageManager.getText("mockProvider2", "id", "entry", null, Locale.US));
     }
 
     public void testGetEntries() {
@@ -100,8 +122,8 @@
 
         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"));
+        assertEquals("Entry 1 match", "Source=mock Id=dummyId Entry=entry1 Locale=en_US", entries.get("entry1"));
+        assertEquals("Entry 2 match", "Source=mock Id=dummyId Entry=entry2 Locale=en_US", entries.get("entry2"));
 
         removeThrowingMockProvider(); // Removing throwing mock and keep only normal mock
 
@@ -109,7 +131,24 @@
 
         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"));
+        assertEquals("Entry 1 match", "Source=mock Id=dummyId Entry=entry1 Locale=en_US", entries.get("entry1"));
+        assertEquals("Entry 2 match", "Source=mock Id=dummyId Entry=entry2 Locale=en_US", entries.get("entry2"));
+
+        // Named provider not found
+        try {
+            MessageManager.getEntries("mockProvider2", "dummyId", Locale.US);
+            fail("Unknown provider should throw Exception");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Error text", "Provider 'mockProvider2' not installed", mnfex.getMessage());
+        }
+
+        // Named provider found
+        addMockProvider("mockProvider2");
+
+        entries = MessageManager.getEntries("mockProvider2", "dummyId", Locale.US);
+        assertEquals("No of entries", 2, entries.size());
+        assertEquals("Entry 1 match", "Source=mockProvider2 Id=dummyId Entry=entry1 Locale=en_US", entries.get("entry1"));
+        assertEquals("Entry 2 match", "Source=mockProvider2 Id=dummyId Entry=entry2 Locale=en_US", entries.get("entry2"));
     }
 }

Modified: 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=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MockProviderTestBase.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/MockProviderTestBase.java Fri May 20 05:50:06 2005
@@ -30,33 +30,38 @@
  * @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();
+        MessageManager.clearMessageProviders();
     }
 
     /**
      * Add mock provider to <code>MessageManager</code>.
      */
     protected void addMockProvider() {
-        MessageManager.addMessageProvider("mock", mockMessageProvider);
+        addMockProvider("mock");
+    }
+
+    /**
+     * Add mock provider to <code>MessageManager</code>.
+     */
+    protected void addMockProvider(final String providerId) {
+         //  Mock message provider that returns a string made up of the arguments passed to it.
+        MessageProvider mockMessageProvider = new MessageProvider() {
+            public String getText(String id, String entry, Locale locale) throws MessageNotFoundException {
+                return MockProviderTestBase.getMockString(providerId, id, entry, locale);
+            }
+
+            public Map getEntries(String id, Locale locale) throws MessageNotFoundException {
+                Map output = new HashMap();
+                output.put("entry1", MockProviderTestBase.getMockString(providerId,id,"entry1",locale));
+                output.put("entry2", MockProviderTestBase.getMockString(providerId,id,"entry2",locale));
+                return output;
+            }
+        };
+
+        MessageManager.addMessageProvider(providerId, mockMessageProvider);
     }
 
     /**
@@ -82,8 +87,17 @@
     // Utility methods
     ////////////////////////////////////////////////////////////////////////
 
+    public static String getMockString(String providerId, String id, String entry, Locale locale) throws MessageNotFoundException {
+        return ((providerId != null) ? "Source=" + providerId + " " : "") +
+                "Id=" + id + " Entry=" + entry + " Locale=" + locale + "";
+    }
+
     public static String getMockString(String id, String entry, Locale locale) throws MessageNotFoundException {
-        return "Id=" + id + " Entry=" + entry + " Locale=" + locale + "";
+        return getMockString("mock", id, entry, locale);
+    }
+
+    public static String getFormattedMockString(String providerId, String id, String entry, String[] arguments, Locale locale) {
+        return MessageFormat.format(getMockString(providerId, id, entry, locale), arguments);
     }
 
     public static String getFormattedMockString(String id, String entry, String[] arguments, Locale locale) {

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=171112&r1=171111&r2=171112&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 Fri May 20 05:50:06 2005
@@ -2,7 +2,7 @@
 *
 * ====================================================================
 *
-* Copyright 2004 The Apache Software Foundation
+* 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.
@@ -45,7 +45,7 @@
         ResourceBundleMessageProvider.uninstall("messageBundle");
         ResourceBundleMessageProvider.uninstall("messageBundle2");
         ResourceBundleMessageProvider.uninstall("nonExistentBundle");
- ResourceBundleMessageProvider.uninstall("org.apache.commons.i18n.MyListResourceBundle");
+        ResourceBundleMessageProvider.uninstall("org.apache.commons.i18n.MyListResourceBundle");
     }
 
     public void testInstallResourceBundle() {
@@ -89,17 +89,11 @@
 
         // Test with list resource bundle
 //        ResourceBundleMessageProvider.uninstall("messageBundle"); // Remove
-// ResourceBundleMessageProvider.install("org.apache.commons.i18n.MyListResourceBundle"); // Install ListResourceBundle
+//        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());
-        }
+        assertEquals("Value from ListResourceBundle", "1", listResourceBundleProvider.getText("helloWorld", "text", Locale.US));
 
         try {
             rbmp.getText("nonExistentId", "nonExistentEntry", Locale.US);
@@ -143,7 +137,7 @@
         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("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);

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=171112&r1=171111&r2=171112&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 Fri May 20 05:50:06 2005
@@ -2,7 +2,7 @@
 *
 * ====================================================================
 *
-* Copyright 2004 The Apache Software Foundation
+* 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.
@@ -56,12 +56,12 @@
         }
 
         XMLMessageProvider.install("org.apache.commons-i18n.test",
- Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+                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"));
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
 
         assertEquals("OK after update", "Hallo Welt", testMessage.getTitle(Locale.GERMAN));
 
@@ -77,14 +77,14 @@
 
         // Try to parse non-XML file
         XMLMessageProvider.install("org.apache.commons-i18n.error",
- Thread.currentThread().getContextClassLoader().getResourceAsStream("messageBundle.properties"));
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("messageBundle.properties"));
     }
-
+    
     public void testGetText() {
 //        XMLMessageProvider.install("org.apache.commons-i18n.test",
-// Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+//                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
         XMLMessageProvider xmlmp = new XMLMessageProvider("org.apache.commons-i18n.test",
- Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+                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));
@@ -123,9 +123,9 @@
 
     public void testGetTextVariants() {
 //        XMLMessageProvider.install("org.apache.commons-i18n.variants",
-// Thread.currentThread().getContextClassLoader().getResourceAsStream("variantTestMessages.xml"));
+//                Thread.currentThread().getContextClassLoader().getResourceAsStream("variantTestMessages.xml"));
         XMLMessageProvider xmlmp = new XMLMessageProvider("org.apache.commons-i18n.variants",
- Thread.currentThread().getContextClassLoader().getResourceAsStream("variantTestMessages.xml"));
+                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")));
@@ -135,9 +135,9 @@
 
     public void testGetEntries() {
 //        XMLMessageProvider.install("org.apache.commons-i18n.test",
-// Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
+//                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml"));
         Map usEntries = new XMLMessageProvider("org.apache.commons-i18n.test",
- Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml")).
+                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"));
@@ -151,7 +151,7 @@
         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")).
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml")).
                     getEntries("helloWorld", Locale.GERMAN);
         assertEquals("No of entries", 4, germanEntries.size());
         assertEquals("Hallo Welt", germanEntries.get("title"));
@@ -163,7 +163,7 @@
 //        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")).
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("testMessages.xml")).
                     getEntries("helloWorld", Locale.JAPANESE);
         assertEquals("Fallback locale, no of entries", 5, japaneseEntries.size());
 

Modified: 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=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/ErrorBundleTest.java Fri May 20 05:50:06 2005
@@ -52,6 +52,38 @@
                 eb.getDetails(Locale.US, "defaultText"));
     }
 
+    public void testWithProvider() {
+        addMockProvider(); // Add wrong provider
+        ErrorBundle eb = new ErrorBundle("dummyProvider", "dummyId");
+        try {
+            eb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Provider 'dummyProvider' not installed", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText", eb.getText(Locale.US, "defaultText"));
+
+        addMockProvider("dummyProvider");
+
+        assertEquals("Normal use", getMockString("dummyProvider", "dummyId", ErrorBundle.TEXT, Locale.US),
+                eb.getText(Locale.US));
+        assertEquals("Normal use", getMockString("dummyProvider", "dummyId", ErrorBundle.TITLE, Locale.US),
+                eb.getTitle(Locale.US));
+        assertEquals("Normal use", getMockString("dummyProvider", "dummyId", ErrorBundle.SUMMARY, Locale.US),
+                eb.getSummary(Locale.US));
+        assertEquals("Normal use", getMockString("dummyProvider", "dummyId", ErrorBundle.DETAILS, Locale.US),
+                eb.getDetails(Locale.US));
+        assertEquals("Default not used", getMockString("dummyProvider", "dummyId", ErrorBundle.TEXT, Locale.US),
+                eb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyProvider", "dummyId", ErrorBundle.TITLE, Locale.US),
+                eb.getTitle(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyProvider", "dummyId", ErrorBundle.SUMMARY, Locale.US),
+                eb.getSummary(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyProvider", "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);
@@ -81,6 +113,47 @@
         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"));
+    }
+
+    public void testWithProviderAndArguments() {
+        addMockProvider(); // Add wrong provider
+        String[] arguments = new String[]{"arg1", "arg2"};
+        ErrorBundle eb = new ErrorBundle("dummyProvider", "dummyId", arguments);
+        try {
+            eb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Provider 'dummyProvider' not installed", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText arg1 arg2", eb.getText(Locale.US, "defaultText {0} {1}"));
+
+        addMockProvider("dummyProvider");
+
+        assertEquals("Normal use",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.TEXT, arguments, Locale.US),
+                eb.getText(Locale.US));
+        assertEquals("Normal use",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.TITLE, arguments, Locale.US),
+                eb.getTitle(Locale.US));
+        assertEquals("Normal use",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.SUMMARY, arguments, Locale.US),
+                eb.getSummary(Locale.US));
+        assertEquals("Normal use",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.DETAILS, arguments, Locale.US),
+                eb.getDetails(Locale.US));
+        assertEquals("Default not used",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.TEXT, arguments, Locale.US),
+                eb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.TITLE, arguments, Locale.US),
+                eb.getTitle(Locale.US, "defaultText"));
+        assertEquals("Default not used",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.SUMMARY, arguments, Locale.US),
+                eb.getSummary(Locale.US, "defaultText"));
+        assertEquals("Default not used",
+                getFormattedMockString("dummyProvider", "dummyId", ErrorBundle.DETAILS, arguments, Locale.US),
                 eb.getDetails(Locale.US, "defaultText"));
     }
 }

Modified: 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=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/MessageBundleTest.java Fri May 20 05:50:06 2005
@@ -46,6 +46,30 @@
                 mb.getTitle(Locale.US, "defaultText"));
     }
 
+    public void testWithProvider() {
+        addMockProvider(); // Add wrong provider
+        MessageBundle mb = new MessageBundle("dummyProvider", "dummyId");
+        try {
+            mb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Provider 'dummyProvider' not installed", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText", mb.getText(Locale.US, "defaultText"));
+
+        addMockProvider("dummyProvider");
+
+        assertEquals("Normal use", getMockString("dummyProvider", "dummyId", MessageBundle.TEXT, Locale.US),
+                mb.getText(Locale.US));
+        assertEquals("Normal use", getMockString("dummyProvider", "dummyId", MessageBundle.TITLE, Locale.US),
+                mb.getTitle(Locale.US));
+        assertEquals("Default not used", getMockString("dummyProvider", "dummyId", MessageBundle.TEXT, Locale.US),
+                mb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used", getMockString("dummyProvider", "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);
@@ -67,6 +91,35 @@
         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"));
+    }
+
+    public void testWithProviderAndArguments() {
+        addMockProvider(); // Add wrong provider
+        String[] arguments = new String[]{"arg1", "arg2"};
+        MessageBundle mb = new MessageBundle("dummyProvider", "dummyId", arguments);
+        try {
+            mb.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Provider 'dummyProvider' not installed", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText arg1 arg2", mb.getText(Locale.US, "defaultText {0} {1}"));
+
+        addMockProvider("dummyProvider");
+
+        assertEquals("Normal use",
+                getFormattedMockString("dummyProvider", "dummyId", MessageBundle.TEXT, arguments, Locale.US),
+                mb.getText(Locale.US));
+        assertEquals("Normal use",
+                getFormattedMockString("dummyProvider", "dummyId", MessageBundle.TITLE, arguments, Locale.US),
+                mb.getTitle(Locale.US));
+        assertEquals("Default not used",
+                getFormattedMockString("dummyProvider", "dummyId", MessageBundle.TEXT, arguments, Locale.US),
+                mb.getText(Locale.US, "defaultText"));
+        assertEquals("Default not used",
+                getFormattedMockString("dummyProvider", "dummyId", MessageBundle.TITLE, arguments, Locale.US),
                 mb.getTitle(Locale.US, "defaultText"));
     }
 }

Modified: 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=171112&r1=171111&r2=171112&view=diff
==============================================================================
--- jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/TextBundleTest.java (original)
+++ jakarta/commons/sandbox/i18n/trunk/src/test/org/apache/commons/i18n/bundles/TextBundleTest.java Fri May 20 05:50:06 2005
@@ -43,6 +43,26 @@
                 textBundle.getText(Locale.US, "defaultText"));
     }
 
+    public void testWithProvider() {
+        addMockProvider(); // Add wrong provider
+        TextBundle textBundle = new TextBundle("dummyProvider", "dummyId");
+        try {
+            textBundle.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Provider 'dummyProvider' not installed", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText", textBundle.getText(Locale.US, "defaultText"));
+
+        addMockProvider("dummyProvider");
+
+        assertEquals("Normal use", getMockString("dummyProvider", "dummyId", TextBundle.TEXT, Locale.US),
+                textBundle.getText(Locale.US));
+        assertEquals("Default not used", getMockString("dummyProvider", "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);
@@ -62,4 +82,26 @@
         assertEquals("Default not used", getFormattedMockString("dummyId", TextBundle.TEXT, arguments, Locale.US),
                 textBundle.getText(Locale.US, "defaultText"));
     }
-}
+
+    public void testWithProviderAndArguments() {
+        addMockProvider(); // Add wrong provider
+        String[] arguments = new String[]{"arg1", "arg2"};
+        TextBundle textBundle = new TextBundle("dummyProvider", "dummyId", arguments);
+        try {
+            textBundle.getText(Locale.US);
+            fail("Entry not found should cause error");
+        }
+        catch(MessageNotFoundException mnfex) {
+            assertEquals("Provider 'dummyProvider' not installed", mnfex.getMessage());
+        }
+        assertEquals("Default used", "defaultText arg1 arg2", textBundle.getText(Locale.US, "defaultText {0} {1}"));
+
+        addMockProvider("dummyProvider");
+
+        assertEquals("Normal use",
+                getFormattedMockString("dummyProvider", "dummyId", TextBundle.TEXT, arguments, Locale.US),
+                textBundle.getText(Locale.US));
+        assertEquals("Default not used",
+                getFormattedMockString("dummyProvider", "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


Mime
View raw message