KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > TestTagUtils


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

16
17 package org.apache.struts.taglib;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.commons.logging.Log;
24
25
26 /**
27  * Unit tests for the TagUtils.
28  */

29 public class TestTagUtils extends TestCase {
30     
31     /** All logging goes through this logger */
32     private static Log log = LogFactory.getLog(TestTagUtils.class);
33
34     protected TagUtils tagutils = TagUtils.getInstance();
35
36     /**
37      * Defines the testcase name for JUnit.
38      *
39      * @param theName the testcase's name.
40      */

41     public TestTagUtils(String JavaDoc theName) {
42         super(theName);
43     }
44
45     /**
46      * Start the tests.
47      *
48      * @param theArgs the arguments. Not used
49      */

50     public static void main(String JavaDoc[] theArgs) {
51         junit.awtui.TestRunner.main(
52             new String JavaDoc[] {TestTagUtils.class.getName()});
53     }
54
55     /**
56      * @return a test suite (<code>TestSuite</code>) that includes all methods
57      * starting with "test"
58      */

59     public static Test suite() {
60         // All methods starting with "test" will be executed in the test suite.
61
return new TestSuite(TestTagUtils.class);
62     }
63
64     public void setUp() {
65     }
66
67     public void tearDown() {
68     }
69     
70     /**
71      * Test Operators.
72      */

73     public void testFilter() {
74
75         // Test Null
76
assertNull("Filter Test 1", tagutils.filter(null));
77
78         // Test Empty String
79
assertEquals("Filter Test 2", "", tagutils.filter(""));
80
81         // Test Single Character
82
assertEquals("Filter Test 3", "a", tagutils.filter("a"));
83
84         // Test Multiple Characters
85
assertEquals("Filter Test 4", "adhdfhdfhadhf", tagutils.filter("adhdfhdfhadhf"));
86
87         // Test Each filtered Character
88
assertEquals("Filter Test 5", "&lt;", tagutils.filter("<"));
89         assertEquals("Filter Test 6", "&gt;", tagutils.filter(">"));
90         assertEquals("Filter Test 7", "&amp;", tagutils.filter("&"));
91         assertEquals("Filter Test 8", "&quot;", tagutils.filter("\""));
92         assertEquals("Filter Test 9", "&#39;", tagutils.filter("'"));
93
94         // Test filtering beginning, middle, end
95
assertEquals("Filter Test 10", "a&lt;", tagutils.filter("a<"));
96         assertEquals("Filter Test 11", "&lt;a", tagutils.filter("<a"));
97         assertEquals("Filter Test 12", "a&lt;a", tagutils.filter("a<a"));
98
99         // Test filtering beginning, middle, end
100
assertEquals("Filter Test 13", "abc&lt;", tagutils.filter("abc<"));
101         assertEquals("Filter Test 14", "&lt;abc", tagutils.filter("<abc"));
102         assertEquals("Filter Test 15", "abc&lt;abc", tagutils.filter("abc<abc"));
103
104         // Test Multiple Characters
105
assertEquals("Filter Test 16", "&lt;input type=&quot;text&quot; value=&#39;Me &amp; You&#39;&gt;",
106                        tagutils.filter("<input type=\"text\" value='Me & You'>"));
107     }
108
109 }
110
Popular Tags