01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.wikitext.WikiWidget;
07: import junit.framework.TestCase;
08: import junit.swingui.TestRunner;
09:
10: public class ParentWidgetTest extends TestCase {
11: private ParentWidget parent;
12:
13: private WikiPage rootPage;
14:
15: public static void main(String[] args) {
16: TestRunner
17: .main(new String[] { "fitnesse.wikitext.widgets.ParentWidgetTest" });
18: }
19:
20: class MockParentWidget extends ParentWidget {
21: MockParentWidget(ParentWidget parent) throws Exception {
22: super (parent);
23: }
24:
25: public String render() throws Exception {
26: return null;
27: }
28: }
29:
30: public void setUp() throws Exception {
31: rootPage = InMemoryPage.makeRoot("RooT");
32: parent = new MockParentWidget(new MockWidgetRoot());
33: }
34:
35: public void tearDown() throws Exception {
36: }
37:
38: public void testEmptyPage() throws Exception {
39: assertEquals(0, parent.numberOfChildren());
40: }
41:
42: public void testAddOneChild() throws Exception {
43: MockWidget mock1 = new MockWidget(parent, "mock1");
44: assertEquals(1, parent.numberOfChildren());
45: WikiWidget widget = parent.nextChild();
46: assertTrue("should be a fitnesse.wikitext.widgets.MockWidget",
47: widget instanceof MockWidget);
48: assertSame(mock1, widget);
49: }
50:
51: public void testAddTwoChildren() throws Exception {
52: MockWidget mock1 = new MockWidget(parent, "mock1");
53: MockWidget mock2 = new MockWidget(parent, "mock2");
54:
55: assertEquals(2, parent.numberOfChildren());
56: assertTrue("should have next", parent.hasNextChild());
57: assertSame(mock1, parent.nextChild());
58: assertSame(mock2, parent.nextChild());
59:
60: assertTrue("should not have next", !parent.hasNextChild());
61: }
62:
63: public void testNextChildWhenThereIsNoNext() throws Exception {
64: try {
65: parent.nextChild();
66: fail("Exception should have been thrown");
67: } catch (Exception e) {
68: }
69: }
70:
71: public void testChildHtml() throws Exception {
72: new MockWidget(parent, "mock1");
73: assertEquals("mock1", parent.childHtml());
74: }
75:
76: public void testChildHtml2() throws Exception {
77: new MockWidget(parent, "mock1");
78: new MockWidget(parent, "mock2");
79: assertEquals("mock1mock2", parent.childHtml());
80: }
81:
82: public void testVariables() throws Exception {
83: WidgetRoot root = new WidgetRoot(rootPage);
84: ParentWidget parent1 = new MockParentWidget(root);
85: ParentWidget parent2 = new MockParentWidget(parent1);
86: parent2.addVariable("someKey", "someValue");
87:
88: assertEquals("someValue", root.getVariable("someKey"));
89: assertEquals("someValue", parent1.getVariable("someKey"));
90: assertEquals("someValue", parent2.getVariable("someKey"));
91: }
92:
93: }
|