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

svn commit: r170280 - in /jakarta/commons/proper/resources/trunk/src: java/org/apache/commons/resources/MessageList.java java/org/apache/commons/resources/impl/BasicMessageList.java test/org/apache/commons/resources/impl/BasicMessageListTestCase.java

Author: jmitchell
Date: Sun May 15 16:32:46 2005
New Revision: 170280

URL: http://svn.apache.org/viewcvs?rev=170280&view=rev
Log:
bring org.apache.commons.resources.impl.BasicMessageList to 100% test coverage

Modified:
    jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/MessageList.java
    jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/BasicMessageList.java
    jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java

Modified: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/MessageList.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/MessageList.java?rev=170280&r1=170279&r2=170280&view=diff
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/MessageList.java (original)
+++ jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/MessageList.java Sun May 15 16:32:46 2005
@@ -127,7 +127,7 @@
      * Return the set of messages related to a specific property.
      * If there are no such messages, an empty enumeration is returned.
      *
-     * @param property Property name (or ActionMessages.GLOBAL_MESSAGE_KEY)
+     * @param property Property name
      */
     public Iterator get(String property);
 

Modified: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/BasicMessageList.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/BasicMessageList.java?rev=170280&r1=170279&r2=170280&view=diff
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/BasicMessageList.java (original)
+++ jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/BasicMessageList.java Sun May 15 16:32:46 2005
@@ -106,10 +106,10 @@
      * @param globalMessageKey The new default global message key
      * @param messages The messages to be initially added to this object.
      * 
-     * @TODO - FIXME - globalMessageKey is ignored
      */
     public BasicMessageList(String globalMessageKey, MessageList messages) {
         super();
+		this.setGlobalMessageKey(globalMessageKey);
         this.add(messages);
     }
 
@@ -151,7 +151,7 @@
 
     // See interface for JavaDoc
     public void add(Message message) {
-        this.add(MessageList.GLOBAL_MESSAGE_KEY, message);
+        this.add(getGlobalMessageKey(), message);
     }
 
 

Modified: jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java?rev=170280&r1=170279&r2=170280&view=diff
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java (original)
+++ jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java Sun May 15 16:32:46 2005
@@ -23,7 +23,9 @@
 
 package org.apache.commons.resources.impl;
 
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -138,26 +140,112 @@
         assertTrue(aMsgs.isAccessed());
 	}
 
+	
+	
+	/**
+	 * Tests using the globalMessageKey on the MessageList object.
+	 */
+	public void testGlobalMessageKey() {
+		BasicMessage foo1 = new BasicMessage("key1");
+		BasicMessage foo2 = new BasicMessage("key2");
+		BasicMessage foo3 = new BasicMessage("key3");
+		
+		MessageList customKeyList = 
+			new BasicMessageList("custom.global.message.key");
+		
+		MessageList standardKeyList = 
+			new BasicMessageList();
+		
+		customKeyList.add("foo1", foo1);
+		customKeyList.add("foo2", foo2);
+		customKeyList.add(foo3);
+		
+		standardKeyList.add("foo1", foo1);
+		standardKeyList.add(foo2);
+		standardKeyList.add("foo3", foo3);
+		
+		assertTrue(customKeyList.size() == 3);
+		assertTrue(standardKeyList.size() == 3);
+		
+		assertEquals(customKeyList.getGlobalMessageKey(), 
+				"custom.global.message.key");
+		
+		assertEquals(standardKeyList.getGlobalMessageKey(), 
+				MessageList.GLOBAL_MESSAGE_KEY);
+		
+		Iterator customKeyListIter = 
+			customKeyList.get(MessageList.GLOBAL_MESSAGE_KEY);
+		while (customKeyListIter.hasNext()) {
+			fail("List should be empty");
+		}
+		
+		Message msg = null;
+		Iterator standardKeyListIter = 
+			standardKeyList.get(MessageList.GLOBAL_MESSAGE_KEY);
+		while (standardKeyListIter.hasNext()) {
+			msg = (Message)standardKeyListIter.next();
+			assertEquals(msg.getKey(), "key2");
+		}
+		msg = null;
+				
+
+		MessageList customKeyList2 = 
+			new BasicMessageList("custom.global.message.key", customKeyList);
+		
+		MessageList standardKeyList2 = 
+			new BasicMessageList(standardKeyList);
+		
+		Iterator customKeyList2Iter = 
+			customKeyList2.get(MessageList.GLOBAL_MESSAGE_KEY);
+		while (customKeyList2Iter.hasNext()) {
+			fail("List should be empty");
+		}
+		
+		Iterator standardKeyList2Iter = 
+			standardKeyList2.get(MessageList.GLOBAL_MESSAGE_KEY);
+		while (standardKeyList2Iter.hasNext()) {
+			msg = (Message)standardKeyList2Iter.next();
+			assertEquals(msg.getKey(), "key2");
+		}
+		msg = null;
+		
+		Map map = new HashMap();
+		assertTrue(map.isEmpty());
+		
+		MessageList emptyList = new BasicMessageList();
+		Iterator emptyListIter = emptyList.get();
+		while (emptyListIter.hasNext()) {
+			fail("List should be empty");
+		}
+		
+		MessageList mList = new BasicMessageList("foo");
+		assertEquals(mList.toString(), "{}");
+				
+	}
+	
+	
+	
 	/**
 	 * Tests adding an MessageList object to an MessageList object.
 	 */
 	public void testAddMessages() {
+		
 		msg1 = new BasicMessage("key");
 		msg2 = new BasicMessage("key2");
 		msg3 = new BasicMessage("key3");
-		MessageList msgs = new BasicMessageList();
-		MessageList add = new BasicMessageList();
+		MessageList outer = new BasicMessageList();
+		MessageList inner = new BasicMessageList();
 
-		msgs.add("prop1", msg1);
-		add.add("prop1", msg2);
-		add.add("prop3", msg3);
-
-		msgs.add(add);
-		assertEquals(3, msgs.size());
-		assertEquals(2, msgs.size("prop1"));
+		outer.add("prop1", msg1);
+		inner.add("prop1", msg2);
+		inner.add("prop3", msg3);
+
+		outer.add(inner);
+		assertEquals(3, outer.size());
+		assertEquals(2, outer.size("prop1"));
 
 		// test message order
-		Iterator props = msgs.get();
+		Iterator props = outer.get();
 		int count = 1;
 		while (props.hasNext()) {
 			Message msg = (Message) props.next();



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