KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > util > TestStringUtils


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

15 package org.apache.hivemind.util;
16
17 import org.apache.hivemind.test.HiveMindTestCase;
18 import org.apache.hivemind.util.StringUtils;
19
20 /**
21  * Tests for the static {@link org.apache.hivemind.util.StringUtils} class.
22  *
23  * @author Howard Lewis Ship
24  */

25 public class TestStringUtils extends HiveMindTestCase
26 {
27     public void testCapitalize()
28     {
29         assertEquals("Fred", StringUtils.capitalize("fred"));
30         assertSame("Barney", StringUtils.capitalize("Barney"));
31     }
32
33     public void testCapitalizeEmpty()
34     {
35         assertSame("", StringUtils.capitalize(""));
36     }
37
38     public void testCapitalizeNull()
39     {
40         try
41         {
42             StringUtils.capitalize(null);
43             unreachable();
44         }
45         catch (NullPointerException JavaDoc ex)
46         {
47             assertTrue(true);
48         }
49     }
50
51     public void testSplit()
52     {
53         assertListsEqual(new String JavaDoc[] { "alpha", "beta" }, StringUtils.split("alpha,beta"));
54     }
55
56     public void testSplitSingle()
57     {
58         assertListsEqual(new String JavaDoc[] { "alpha" }, StringUtils.split("alpha"));
59     }
60
61     public void testSplitNull()
62     {
63         assertListsEqual(new String JavaDoc[0], StringUtils.split(null));
64     }
65
66     public void testSplitEmpty()
67     {
68         assertListsEqual(new String JavaDoc[0], StringUtils.split(null));
69     }
70
71     public void testSplitTrailingComma()
72     {
73         assertListsEqual(
74             new String JavaDoc[] { "fred", "barney", "wilma" },
75             StringUtils.split("fred,barney,wilma,"));
76     }
77
78     public void testJoin()
79     {
80         assertEquals("alpha:beta", StringUtils.join(new String JavaDoc[] { "alpha", "beta" }, ':'));
81     }
82
83     public void testJoinNull()
84     {
85         assertEquals(null, StringUtils.join(null, ','));
86     }
87
88     public void testJoinEmpty()
89     {
90         assertEquals(null, StringUtils.join(new String JavaDoc[0], ','));
91     }
92 }
Popular Tags