01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.base;
17:
18: import java.util.Iterator;
19:
20: import junit.framework.TestCase;
21:
22: /**
23: *
24: * @author Christoph Beck
25: */
26: public class MessagesTest extends TestCase {
27:
28: /**
29: * Constructor for MessagesTest.
30: * @param arg0
31: */
32: public MessagesTest(String arg0) {
33: super (arg0);
34: }
35:
36: public static void main(String[] args) {
37: junit.textui.TestRunner.run(MessagesTest.class);
38: }
39:
40: public void testGlobal() {
41: Message message = new Message();
42: Messages messages = new Messages();
43: assertFalse(messages.containsGlobalMessages());
44: assertFalse(messages.getGlobalMessages().hasNext());
45: messages.addGlobalMessage(message);
46: assertTrue(messages.getGlobalMessages().hasNext());
47: assertSame(message, messages.getGlobalMessages().next());
48: assertSame(message, messages.getFirstGlobalMessage());
49: assertTrue(messages.containsGlobalMessages());
50:
51: Iterator keys = messages.getKeys();
52: assertTrue(keys.hasNext());
53: assertTrue(keys.next() == Messages.GLOBAL_KEY);
54: assertFalse(keys.hasNext());
55: }
56:
57: public void testAllMessages() {
58: Messages messages = new Messages();
59: Message[] values = { new Message("bundle", "msg1"),
60: new Message("bundle", "msg2"),
61: new Message("bundle", "msg3"),
62: new Message("bundle", "msg4") };
63: messages.addMessage("key1", values[0]);
64: messages.addMessage("key2", values[1]);
65: messages.addMessage("key3", values[2]);
66: messages.addMessage("key2", values[3]);
67: Iterator iter = messages.getAllMessages();
68: assertTrue(iter.hasNext());
69: assertSame(values[0], iter.next());
70: assertTrue(iter.hasNext());
71: assertSame(values[1], iter.next());
72: assertTrue(iter.hasNext());
73: assertSame(values[3], iter.next());
74: assertTrue(iter.hasNext());
75: assertSame(values[2], iter.next());
76: assertFalse(iter.hasNext());
77: }
78: }
|