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 junit.framework.*;
06: import fitnesse.wikitext.*;
07: import fitnesse.wiki.*;
08: import java.util.*;
09:
10: public class WidgetVisitorTest extends TestCase implements
11: WidgetVisitor {
12: List visits = new ArrayList();
13: private WikiPage root;
14:
15: public void visit(WikiWidget widget) {
16: visits.add(widget);
17: }
18:
19: public void visit(WikiWordWidget widget) {
20: visits.add(widget);
21: }
22:
23: public void visit(AliasLinkWidget widget) throws Exception {
24: }
25:
26: public void setUp() throws Exception {
27: visits.clear();
28: root = InMemoryPage.makeRoot("RooT");
29: }
30:
31: public void testSimpleVisitorVisitsAllWidgets() throws Exception {
32: WidgetRoot root = new WidgetRoot("''hello''", this .root);
33: root.acceptVisitor(this );
34: assertEquals(3, visits.size());
35: assertEquals(WidgetRoot.class, visits.get(0).getClass());
36: assertEquals(ItalicWidget.class, visits.get(1).getClass());
37: assertEquals(TextWidget.class, visits.get(2).getClass());
38: }
39:
40: public void testComplexVisitorVisitsAllWidgets() throws Exception {
41: WidgetRoot root = new WidgetRoot(
42: "|CellOne|CellTwo|\n|''hello''|'''hello'''|\n",
43: this .root);
44: root.acceptVisitor(this );
45: assertEquals(14, visits.size());
46: }
47: }
|