View Javadoc

1   /* $Id: DigesterPatternStackTest.java 1127928 2011-05-26 14:13:29Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.commons.digester3.xmlrules;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  /**
27   * This test case tests the behavior of DigesterRuleParser.PatternStack, a specialized stack whose toString() method
28   * returns a /-separated representation of the stack's elements. The tests ensure that
29   * DigesterRuleParser.PatternStack.toString() returns the properly formatted string.
30   */
31  public class DigesterPatternStackTest
32  {
33  
34      private PatternStack patternStack = new PatternStack();
35  
36      @Before
37      public void setUp()
38      {
39          patternStack.clear();
40      }
41  
42      @Test
43      public void test1()
44          throws Exception
45      {
46          assertEquals( "", patternStack.toString() );
47      }
48  
49      @Test
50      public void test2()
51          throws Exception
52      {
53          patternStack.push( "A" );
54          assertEquals( "A", patternStack.toString() );
55          patternStack.pop();
56          assertEquals( "", patternStack.toString() );
57      }
58  
59      @Test
60      public void test3()
61          throws Exception
62      {
63          patternStack.push( "A" );
64          patternStack.push( "B" );
65          assertEquals( "A/B", patternStack.toString() );
66  
67          patternStack.pop();
68          assertEquals( "A", patternStack.toString() );
69      }
70  
71      @Test
72      public void test4()
73          throws Exception
74      {
75          patternStack.push( "" );
76          assertEquals( "", patternStack.toString() );
77  
78          patternStack.push( "" );
79          assertEquals( "", patternStack.toString() );
80      }
81  
82      @Test
83      public void test5()
84          throws Exception
85      {
86          patternStack.push( "A" );
87          assertEquals( "A", patternStack.toString() );
88  
89          patternStack.push( "" );
90          patternStack.push( "" );
91          assertEquals( "A", patternStack.toString() );
92  
93      }
94  
95      @Test
96      public void test6()
97          throws Exception
98      {
99          patternStack.push( "A" );
100         patternStack.push( "B" );
101         patternStack.clear();
102         assertEquals( "", patternStack.toString() );
103     }
104 
105     @Test
106     public void test7()
107         throws Exception
108     {
109         patternStack.push( "///" );
110         assertEquals( "///", patternStack.toString() );
111 
112         patternStack.push( "/" );
113         assertEquals( "/////", patternStack.toString() );
114 
115         patternStack.pop();
116         assertEquals( "///", patternStack.toString() );
117 
118         patternStack.pop();
119         assertEquals( "", patternStack.toString() );
120     }
121 
122 }