001/* $Id: DigesterPatternStackTest.java 1127928 2011-05-26 14:13:29Z simonetripodi $ 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.commons.digester3.xmlrules; 020 021import static org.junit.Assert.assertEquals; 022 023import org.junit.Before; 024import org.junit.Test; 025 026/** 027 * This test case tests the behavior of DigesterRuleParser.PatternStack, a specialized stack whose toString() method 028 * returns a /-separated representation of the stack's elements. The tests ensure that 029 * DigesterRuleParser.PatternStack.toString() returns the properly formatted string. 030 */ 031public class DigesterPatternStackTest 032{ 033 034 private PatternStack patternStack = new PatternStack(); 035 036 @Before 037 public void setUp() 038 { 039 patternStack.clear(); 040 } 041 042 @Test 043 public void test1() 044 throws Exception 045 { 046 assertEquals( "", patternStack.toString() ); 047 } 048 049 @Test 050 public void test2() 051 throws Exception 052 { 053 patternStack.push( "A" ); 054 assertEquals( "A", patternStack.toString() ); 055 patternStack.pop(); 056 assertEquals( "", patternStack.toString() ); 057 } 058 059 @Test 060 public void test3() 061 throws Exception 062 { 063 patternStack.push( "A" ); 064 patternStack.push( "B" ); 065 assertEquals( "A/B", patternStack.toString() ); 066 067 patternStack.pop(); 068 assertEquals( "A", patternStack.toString() ); 069 } 070 071 @Test 072 public void test4() 073 throws Exception 074 { 075 patternStack.push( "" ); 076 assertEquals( "", patternStack.toString() ); 077 078 patternStack.push( "" ); 079 assertEquals( "", patternStack.toString() ); 080 } 081 082 @Test 083 public void test5() 084 throws Exception 085 { 086 patternStack.push( "A" ); 087 assertEquals( "A", patternStack.toString() ); 088 089 patternStack.push( "" ); 090 patternStack.push( "" ); 091 assertEquals( "A", patternStack.toString() ); 092 093 } 094 095 @Test 096 public void test6() 097 throws Exception 098 { 099 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}