KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > xmlrules > DigesterPatternStackTest


1 /* $Id: DigesterPatternStackTest.java 155412 2005-02-26 12:58:36Z dirkv $
2  *
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.commons.digester.xmlrules;
19
20
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23
24
25 /**
26  * This test case tests the behavior of
27  * DigesterRuleParser.PatternStack, a specialized stack whose
28  * toString() method returns a /-separated representation of the
29  * stack's elements. The tests ensure that
30  * DigesterRuleParser.PatternStack.toString() returns the properly
31  * formatted string.
32  */

33 public class DigesterPatternStackTest extends TestCase {
34
35     public DigesterPatternStackTest(String JavaDoc testName) {
36         super(testName);
37     }
38
39     public static void main(java.lang.String JavaDoc[] args) {
40         junit.textui.TestRunner.run(suite());
41     }
42
43     public static junit.framework.Test suite() {
44         TestSuite suite = new TestSuite(DigesterPatternStackTest.class);
45
46         return suite;
47     }
48
49     private DigesterRuleParser.PatternStack stack;
50
51     public void setUp() {
52         DigesterRuleParser parser = new DigesterRuleParser();
53         stack = parser.patternStack;
54     }
55
56     public void test1() throws Exception JavaDoc {
57         assertEquals("", stack.toString());
58     }
59
60     public void test2() throws Exception JavaDoc {
61         stack.push("A");
62         assertEquals("A", stack.toString());
63         stack.pop();
64         assertEquals("", stack.toString());
65     }
66
67     public void test3() throws Exception JavaDoc {
68         stack.push("A");
69         stack.push("B");
70         assertEquals("A/B", stack.toString());
71
72         stack.pop();
73         assertEquals("A", stack.toString());
74     }
75
76     public void test4() throws Exception JavaDoc {
77         stack.push("");
78         assertEquals("", stack.toString());
79
80         stack.push("");
81         assertEquals("", stack.toString());
82     }
83
84     public void test5() throws Exception JavaDoc {
85         stack.push("A");
86         assertEquals("A", stack.toString());
87
88         stack.push("");
89         stack.push("");
90         assertEquals("A", stack.toString());
91
92     }
93
94     public void test6() throws Exception JavaDoc {
95         stack.push("A");
96         stack.push("B");
97         stack.clear();
98         assertEquals("", stack.toString());
99     }
100
101     public void test7() throws Exception JavaDoc {
102         stack.push("///");
103         assertEquals("///", stack.toString());
104
105         stack.push("/");
106         assertEquals("/////", stack.toString());
107
108         stack.pop();
109         assertEquals("///", stack.toString());
110
111         stack.pop();
112         assertEquals("", stack.toString());
113     }
114
115 }
116
Popular Tags