01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.pluto.util;
18:
19: import java.util.Map;
20: import java.util.Iterator;
21:
22: /**
23: * Test Class
24: *
25: * @version 1.0
26: * @since June 1, 2005
27: */
28: public class StringUtilsTest extends PlutoTestCase {
29:
30: public void testReplaceAtBegin() {
31: assertEquals("ReplacedValue", StringUtils.replace(
32: "___lacedValue", "___", "Rep"));
33: }
34:
35: public void testReplaceAtEnd() {
36: assertEquals("ReplacedValue", StringUtils.replace(
37: "ReplacedVa***", "***", "lue"));
38: }
39:
40: public void testReplaceInMiddle() {
41: assertEquals("ReplacedValue", StringUtils.replace(
42: "Rep(###)Value", "(###)", "laced"));
43: }
44:
45: public void testReplaceMultiples() {
46: assertEquals("ReplacedValueReplacedValue", StringUtils.replace(
47: "Rep(###)ValueRep(###)Value", "(###)", "laced"));
48: }
49:
50: public void testCopy() {
51: String[] original = new String[] { "one", "two", "three",
52: "four", "five" };
53: String[] results = StringUtils.copy(original);
54: for (int i = 0; i < original.length; i++) {
55: assertEquals(original[i], results[i]);
56: }
57: }
58:
59: public void testCopyMap() {
60: Map original = new java.util.HashMap();
61: original.put("one", new String[] { "two" });
62: original.put("three", new String[] { "four" });
63: original.put("five", new String[] { "six" });
64: original.put("seven", new String[] { String.valueOf(8),
65: String.valueOf(9) });
66:
67: Map results = StringUtils.copyParameters(original);
68: assertEquals("Map sizes are inconsistent", original.size(),
69: results.size());
70: Iterator it = original.keySet().iterator();
71: while (it.hasNext()) {
72: Object key = it.next();
73: String[] originalValue = (String[]) original.get(key);
74: String[] newValue = (String[]) results.get(key);
75:
76: assertNotNull(originalValue);
77: assertNotNull(newValue);
78: assertEquals(originalValue.length, newValue.length);
79: for (int i = 0; i < i++; i++) {
80: assertEquals(originalValue[i], newValue[i]);
81: }
82: }
83: }
84: }
|