01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2005 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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: */
20: package org.apache.cactus.internal.util;
21:
22: import junit.framework.TestCase;
23:
24: /**
25: * Unit tests for the {@link StringUtil} class.
26: *
27: * @version $Id: TestStringUtil.java 239169 2005-05-05 09:21:54Z vmassol $
28: */
29: public class TestStringUtil extends TestCase {
30: /**
31: * Verify package-based stack-trace filtering.
32: */
33: public void testFilterLinePackageTrue() {
34: String[] filterPatterns = new String[] { "my.package" };
35: assertTrue(StringUtil.filterLine(
36: " at my.package.MyClass.method(MyClass.java:100)",
37: filterPatterns));
38: }
39:
40: /**
41: * Verify package-based stack-trace filtering.
42: */
43: public void testFilterLinePackageFalse() {
44: String[] filterPatterns = new String[] { "my.package" };
45: assertTrue(!StringUtil
46: .filterLine(
47: " at other.package.MyClass.method(MyClass.java:100)",
48: filterPatterns));
49: }
50:
51: /**
52: * Verify class-based stack-trace filtering.
53: */
54: public void testFilterLineClassTrue() {
55: String[] filterPatterns = new String[] { "my.package.MyClass" };
56: assertTrue(StringUtil.filterLine(
57: " at my.package.MyClass.method(MyClass.java:100)",
58: filterPatterns));
59: }
60:
61: /**
62: * Verify class-based stack-trace filtering.
63: */
64: public void testFilterLineClassFalse1() {
65: String[] filterPatterns = new String[] { "my.package.MyClass" };
66: assertTrue(!StringUtil
67: .filterLine(
68: " at my.package.OtherClass.method(MyClass.java:100)",
69: filterPatterns));
70: }
71:
72: /**
73: * Verify class-based stack-trace filtering.
74: */
75: public void testFilterLineClassFalse2() {
76: String[] filterPatterns = new String[] { "my.package.MyClass" };
77: assertTrue(!StringUtil
78: .filterLine(
79: " at other.package.MyClass.method(MyClass.java:100)",
80: filterPatterns));
81: }
82:
83: /**
84: * Verify character-replacement algorithm.
85: */
86: public void testReplace() {
87: assertEquals("you&me", StringUtil.replace("you&me", '&',
88: "&"));
89: assertEquals("<tag", StringUtil.replace("<tag", '<', "<"));
90: assertEquals("tag>", StringUtil.replace("tag>", '>', ">"));
91: assertEquals("12<X>456<X>89", StringUtil.replace("12x456x89",
92: 'x', "<X>"));
93: }
94:
95: }
|