Diff of /jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java
Parent Directory
| Revision Log
| Patch
--- jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java 2005/05/15 23:30:10 170279
+++ jakarta/commons/proper/resources/trunk/src/test/org/apache/commons/resources/impl/BasicMessageListTestCase.java 2005/05/15 23:32:46 170280
@@ -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 @@ public class BasicMessageListTestCase ex
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();