KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > arooa > DualHandlerTest


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.arooa;
5
6 import org.oddjob.arooa.ArooaHandler;
7 import org.oddjob.arooa.ArooaContext;
8 import org.xml.sax.Attributes JavaDoc;
9 import org.xml.sax.SAXParseException JavaDoc;
10
11 import junit.framework.TestCase;
12
13 /**
14  *
15  */

16 public class DualHandlerTest extends TestCase {
17
18     class GoodHandler extends ArooaHandler {
19         public void onStartElement(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
20                 Attributes JavaDoc attrs, ArooaContext context) {
21         }
22
23         public ArooaHandler onStartChild(String JavaDoc uri, String JavaDoc tag,
24                 String JavaDoc qname, Attributes JavaDoc attrs, ArooaContext context) {
25             return this;
26         }
27
28         public void onEndChild(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
29                 ArooaContext context) {
30         }
31
32         public void onEndElement(String JavaDoc uri, String JavaDoc tag,
33                 ArooaContext context) {
34         }
35
36         public void characters(char[] buf, int start, int count,
37                 ArooaContext context) {
38         }
39     }
40     
41     class BadHandler extends ArooaHandler {
42         public void onStartElement(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
43                 Attributes JavaDoc attrs, ArooaContext context) {
44             throw new NullPointerException JavaDoc("Ah ha!");
45         }
46
47         public ArooaHandler onStartChild(String JavaDoc uri, String JavaDoc tag,
48                 String JavaDoc qname, Attributes JavaDoc attrs, ArooaContext context) {
49             throw new NullPointerException JavaDoc("Ah ha!");
50         }
51
52         public void onEndChild(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
53                 ArooaContext context) {
54             throw new NullPointerException JavaDoc("Ah ha!");
55         }
56
57         public void onEndElement(String JavaDoc uri, String JavaDoc tag,
58                 ArooaContext context) {
59             throw new NullPointerException JavaDoc("Ah ha!");
60         }
61
62         public void characters(char[] buf, int start, int count,
63                 ArooaContext context) {
64             throw new NullPointerException JavaDoc("Ah ha!");
65         }
66     }
67     
68     public void testGoodStartElement() throws SAXParseException JavaDoc {
69         DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler());
70         h.onStartElement("", "tag", "tag", null, null);
71         assertTrue("h1OK", h.isHandler1OK());
72         assertTrue("h2OK", h.isHandler2OK());
73     }
74
75     public void testBadStartElement() throws SAXParseException JavaDoc {
76         DualHandler h = new DualHandler(new BadHandler(), new BadHandler());
77         h.onStartElement("", "tag", "tag", null, null);
78         assertFalse("h1OK", h.isHandler1OK());
79         assertFalse("h2OK", h.isHandler2OK());
80     }
81
82     public void testGoodStartChild() throws SAXParseException JavaDoc {
83         DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler());
84         h.onStartChild("", "tag", "tag", null, null);
85         assertTrue("h1OK", h.isHandler1OK());
86         assertTrue("h2OK", h.isHandler2OK());
87     }
88
89     public void testBadStartChild() throws SAXParseException JavaDoc {
90         DualHandler h = new DualHandler(new BadHandler(), new BadHandler());
91         h.onStartElement("", "tag", "tag", null, null);
92         assertFalse("h1OK", h.isHandler1OK());
93         assertFalse("h2OK", h.isHandler2OK());
94     }
95     
96     public void testGoodEndChild() throws SAXParseException JavaDoc {
97         DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler());
98         h = (DualHandler)h.onStartChild("", "tag", "tag", null, null);
99
100         h.onEndChild("", "tag", "tag", null);
101         assertTrue("h1OK", h.isHandler1OK());
102         assertTrue("h2OK", h.isHandler2OK());
103     }
104
105     public void testBadEndChild() throws SAXParseException JavaDoc {
106         DualHandler h = new DualHandler(new BadHandler(), new BadHandler());
107         h = (DualHandler)h.onStartChild("", "tag", "tag", null, null);
108
109         h.onEndChild("", "tag", "tag", null);
110         assertFalse("h1OK", h.isHandler1OK());
111         assertFalse("h2OK", h.isHandler2OK());
112     }
113
114     public void testGoodEndElement() throws SAXParseException JavaDoc {
115         DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler());
116         h.onEndElement("", "tag", null);
117         assertTrue("h1OK", h.isHandler1OK());
118         assertTrue("h2OK", h.isHandler2OK());
119     }
120
121     public void testBadEndElement() throws SAXParseException JavaDoc {
122         DualHandler h = new DualHandler(new BadHandler(), new BadHandler());
123         h.onEndElement("", "tag", null);
124         assertFalse("h1OK", h.isHandler1OK());
125         assertFalse("h2OK", h.isHandler2OK());
126     }
127
128     public void testGoodChars() throws SAXParseException JavaDoc {
129         DualHandler h = new DualHandler(new GoodHandler(), new GoodHandler());
130         h.characters(new char[0], 0, 0, null);
131         assertTrue("h1OK", h.isHandler1OK());
132         assertTrue("h2OK", h.isHandler2OK());
133     }
134
135     public void testBadChars() throws SAXParseException JavaDoc {
136         DualHandler h = new DualHandler(new BadHandler(), new BadHandler());
137         h.characters(new char[0], 0, 0, null);
138         assertFalse("h1OK", h.isHandler1OK());
139         assertFalse("h2OK", h.isHandler2OK());
140     }
141 }
142
Popular Tags