KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > util > StringHelperTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: StringHelperTest.java 98 2006-02-24 16:18:48Z alouis $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.tools.util;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.objectweb.petals.tools.jbicommon.util.StringHelper;
28
29 import junit.framework.TestCase;
30
31 /**
32  *
33  * @version $Rev: 98 $ $Date: 2006-02-24 17:18:48 +0100 (ven., 24 févr. 2006) $
34  * @since Petals 1.0
35  * @author Adrien LOUIS
36  */

37 public class StringHelperTest extends TestCase {
38
39     /*
40      * Test method for 'org.objectweb.petals.util.StringHelper.isEmpty(String)'
41      */

42     public void testIsEmpty1() {
43         assertTrue(StringHelper.isNullOrEmpty(null));
44     }
45
46     public void testIsEmpty2() {
47         assertTrue(StringHelper.isNullOrEmpty(""));
48     }
49
50     public void testIsEmpty3() {
51         assertFalse(StringHelper.isNullOrEmpty("a"));
52     }
53
54     /*
55      * Test method for 'org.objectweb.petals.util.StringHelper.equal(String,
56      * String)'
57      */

58     public void testEqual1() {
59         assertTrue(StringHelper.equal(null, null));
60     }
61
62     public void testEqual2() {
63         assertTrue(StringHelper.equal("a", "a"));
64     }
65
66     public void testEqual3() {
67         assertFalse(StringHelper.equal(null, ""));
68     }
69
70     public void testEqual4() {
71         assertFalse(StringHelper.equal("", null));
72     }
73
74     public void testEqual5() {
75         assertFalse(StringHelper.equal("a", "A"));
76     }
77
78     public void testEqual6() {
79         assertFalse(StringHelper.equal("a", "b"));
80     }
81
82     /*
83      * Test method for
84      * 'org.objectweb.petals.util.StringHelper.equalIgnoreCase(String, String)'
85      */

86     public void testequalIgnoreCaseIgnoreCase1() {
87         assertTrue(StringHelper.equalIgnoreCase(null, null));
88     }
89
90     public void testequalIgnoreCaseIgnoreCase2() {
91         assertTrue(StringHelper.equalIgnoreCase("a", "a"));
92     }
93
94     public void testequalIgnoreCaseIgnoreCase5() {
95         assertTrue(StringHelper.equalIgnoreCase("a", "A"));
96     }
97
98     public void testequalIgnoreCaseIgnoreCase3() {
99         assertFalse(StringHelper.equalIgnoreCase(null, ""));
100     }
101
102     public void testequalIgnoreCaseIgnoreCase4() {
103         assertFalse(StringHelper.equalIgnoreCase("", null));
104     }
105
106     public void testequalIgnoreCaseIgnoreCase6() {
107         assertFalse(StringHelper.equalIgnoreCase("a", "b"));
108     }
109
110     /*
111      * Test method for
112      * 'org.objectweb.petals.util.StringHelper.extractValueForAttribute(String
113      * string, String attribute,String separator)'
114      */

115
116     // null parameters
117
public void testextractValueForAttribute1() {
118         assertNull(StringHelper.extractValueForAttribute(null, "", ""));
119     }
120
121     public void testextractValueForAttribute2() {
122         assertNull(StringHelper.extractValueForAttribute("", null, ""));
123     }
124
125     public void testextractValueForAttribute3() {
126         assertNull(StringHelper.extractValueForAttribute("", "", null));
127     }
128
129     // att found
130
public void testextractValueForAttribute4() {
131         assertEquals("value", StringHelper.extractValueForAttribute(
132                 "att=value", "att", null));
133     }
134
135     public void testextractValueForAttribute5() {
136         assertEquals("value", StringHelper.extractValueForAttribute(
137                 "yo att=value", "att", null));
138     }
139
140     public void testextractValueForAttribute6() {
141         assertEquals("value", StringHelper.extractValueForAttribute(
142                 "yo att=value&yo", "att", "&"));
143     }
144
145     public void testextractValueForAttribute7() {
146         assertEquals("value etc", StringHelper.extractValueForAttribute(
147                 "yo att=value etc", "att", null));
148     }
149
150     /*
151      * Test method for StringHelper#splitPathElements(String)
152      */

153     public void testSplitPathElements1() {
154         assertTrue(StringHelper.splitPathElements(null).isEmpty());
155     }
156
157     public void testSplitPathElements2() {
158         List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
159         result.add("foo");
160         result.add("bar");
161         assertEquals(result, StringHelper.splitPathElements("/foo/bar"));
162     }
163
164     public void testSplitPathElements3() {
165         List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
166         result.add("foo");
167         result.add("bar");
168         assertEquals(result, StringHelper.splitPathElements("foo/bar"));
169     }
170
171     public void testSplitPathElements4() {
172         List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
173         result.add("foo");
174         result.add("bar");
175         assertEquals(result, StringHelper.splitPathElements("/foo/bar/"));
176     }
177
178     public void testSplitPathElements5() {
179         List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
180         result.add("foo");
181         result.add("bar");
182         assertEquals(result, StringHelper.splitPathElements("//foo///bar//"));
183     }
184
185 }
186
Popular Tags