svn commit: r169945 - /jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/MessagesTestCase.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r169945 - /jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/MessagesTestCase.java

jmitchell-3
Author: jmitchell
Date: Thu May 12 22:15:05 2005
New Revision: 169945

URL: http://svn.apache.org/viewcvs?rev=169945&view=rev
Log:
adding new tests, and reports for jcoverage, with any luck I'll have Commons Resources at 100% test coverage by the end of next month

Modified:
    jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/MessagesTestCase.java

Modified: jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/MessagesTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/MessagesTestCase.java?rev=169945&r1=169944&r2=169945&view=diff
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/MessagesTestCase.java (original)
+++ jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/MessagesTestCase.java Thu May 12 22:15:05 2005
@@ -23,6 +23,8 @@
 
 package org.apache.commons.resources;
 
+import java.util.Locale;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -117,6 +119,69 @@
 
  message = local.getMessage("local.missing");
  assertEquals("Correct missing message", "???local.missing???", message);
+
+
+ Messages messages2 = new MyMessages(null);
+ Messages messages3 = messages2.getMessages(null);
+ assertNull("Invalid Messages", messages3);
+
+ }
+
+
+
+    /**
+     * Test the ability to retrieve messages with replacements.
+     */
+ public void testMessage() {
+ String message = null;
+
+ message = messages.getMessage("test.missing");
+ assertEquals("Correct missing message", "???test.missing???", message);
+
+ message = messages.getMessage(Locale.ENGLISH, "test.message");
+ assertEquals(
+ "Correct individual message",
+ "[Base] REPLACE {0} WITH {1}",
+ message);
+
+ message =
+ messages.getMessage("test.message", new String[] { "abc", "def" });
+
+        assertEquals(
+ "Correct replaced message",
+ "[Base] REPLACE abc WITH def",
+ message);
+
+ message =
+ messages.getMessage(Locale.ENGLISH, "test.message", new String[] { "abc", "def" });
+
+        assertEquals(
+ "Correct replaced message",
+ "[Base] REPLACE abc WITH def",
+ message);
+
+ message =
+ messages.getMessage(Locale.ENGLISH, "test.message.single", "abc");
+
+        assertEquals(
+ "Correct replaced message",
+ "[Base] REPLACE abc",
+ message);
+
+ message =
+ messages.getMessage("test.message.single", "abc");
+
+        assertEquals(
+ "Correct replaced message",
+ "[Base] REPLACE abc",
+ message);
+
+ Resources resources2 =
+ factory.getResources(NAME + "-does-not-exist",
+ CONFIG + "-does-not-exist");
+ resources2.setReturnNull(false);
+        Messages messages2 = new Messages(resources2);
+ message = messages2.getMessage("test.message");
  }
 
 
@@ -142,6 +207,8 @@
 
  message = messages.getMessage("test.missing");
  assertEquals("Correct missing message", "???test.missing???", message);
+
+
  }
 
 
@@ -156,4 +223,33 @@
  }
 
 
+ class MyMessages extends Messages{
+
+ public MyMessages(Resources resources) {
+ super(resources);
+ MyMessages.factory = new ResourcesFactory(){
+    public Resources getResources(String name)
+         throws ResourcesException{
+ throw new ResourcesException("Bad Implementation");
+    }
+
+ public boolean isReturnNull() {
+ return false;
+ }
+
+ public void setReturnNull(boolean returnNull) {}
+
+ public Resources getResources(String name, String config) throws ResourcesException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void release() throws ResourcesException {
+ // TODO Auto-generated method stub
+
+ }
+ };
+ }
+
+ }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]