Source Code Cross Referenced for StringUtilsEqualsIndexOfTest.java in  » Library » Apache-common-lang » org » apache » commons » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.lang;
018:
019:        import junit.framework.Test;
020:        import junit.framework.TestCase;
021:        import junit.framework.TestSuite;
022:        import junit.textui.TestRunner;
023:
024:        /**
025:         * Unit tests {@link org.apache.commons.lang.StringUtils} - Substring methods
026:         *
027:         * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
028:         * @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
029:         * @author Phil Steitz
030:         * @version $Id: StringUtilsEqualsIndexOfTest.java 437554 2006-08-28 06:21:41Z bayard $
031:         */
032:        public class StringUtilsEqualsIndexOfTest extends TestCase {
033:            private static final String FOO = "foo";
034:            private static final String BAR = "bar";
035:            private static final String FOOBAR = "foobar";
036:            private static final String[] FOOBAR_SUB_ARRAY = new String[] {
037:                    "ob", "ba" };
038:
039:            public StringUtilsEqualsIndexOfTest(String name) {
040:                super (name);
041:            }
042:
043:            public static void main(String[] args) {
044:                TestRunner.run(suite());
045:            }
046:
047:            public static Test suite() {
048:                TestSuite suite = new TestSuite(
049:                        StringUtilsEqualsIndexOfTest.class);
050:                suite.setName("StringUtilsEqualsIndexOf Tests");
051:                return suite;
052:            }
053:
054:            protected void setUp() throws Exception {
055:                super .setUp();
056:            }
057:
058:            protected void tearDown() throws Exception {
059:                super .tearDown();
060:            }
061:
062:            //-----------------------------------------------------------------------
063:
064:            public void testEquals() {
065:                assertEquals(true, StringUtils.equals(null, null));
066:                assertEquals(true, StringUtils.equals(FOO, FOO));
067:                assertEquals(true, StringUtils.equals(FOO, new String(
068:                        new char[] { 'f', 'o', 'o' })));
069:                assertEquals(false, StringUtils.equals(FOO, new String(
070:                        new char[] { 'f', 'O', 'O' })));
071:                assertEquals(false, StringUtils.equals(FOO, BAR));
072:                assertEquals(false, StringUtils.equals(FOO, null));
073:                assertEquals(false, StringUtils.equals(null, FOO));
074:            }
075:
076:            public void testEqualsIgnoreCase() {
077:                assertEquals(true, StringUtils.equalsIgnoreCase(null, null));
078:                assertEquals(true, StringUtils.equalsIgnoreCase(FOO, FOO));
079:                assertEquals(true, StringUtils.equalsIgnoreCase(FOO,
080:                        new String(new char[] { 'f', 'o', 'o' })));
081:                assertEquals(true, StringUtils.equalsIgnoreCase(FOO,
082:                        new String(new char[] { 'f', 'O', 'O' })));
083:                assertEquals(false, StringUtils.equalsIgnoreCase(FOO, BAR));
084:                assertEquals(false, StringUtils.equalsIgnoreCase(FOO, null));
085:                assertEquals(false, StringUtils.equalsIgnoreCase(null, FOO));
086:            }
087:
088:            //-----------------------------------------------------------------------
089:            public void testIndexOf_char() {
090:                assertEquals(-1, StringUtils.indexOf(null, ' '));
091:                assertEquals(-1, StringUtils.indexOf("", ' '));
092:                assertEquals(0, StringUtils.indexOf("aabaabaa", 'a'));
093:                assertEquals(2, StringUtils.indexOf("aabaabaa", 'b'));
094:            }
095:
096:            public void testIndexOf_charInt() {
097:                assertEquals(-1, StringUtils.indexOf(null, ' ', 0));
098:                assertEquals(-1, StringUtils.indexOf(null, ' ', -1));
099:                assertEquals(-1, StringUtils.indexOf("", ' ', 0));
100:                assertEquals(-1, StringUtils.indexOf("", ' ', -1));
101:                assertEquals(0, StringUtils.indexOf("aabaabaa", 'a', 0));
102:                assertEquals(2, StringUtils.indexOf("aabaabaa", 'b', 0));
103:                assertEquals(5, StringUtils.indexOf("aabaabaa", 'b', 3));
104:                assertEquals(-1, StringUtils.indexOf("aabaabaa", 'b', 9));
105:                assertEquals(2, StringUtils.indexOf("aabaabaa", 'b', -1));
106:            }
107:
108:            public void testIndexOf_String() {
109:                assertEquals(-1, StringUtils.indexOf(null, null));
110:                assertEquals(-1, StringUtils.indexOf("", null));
111:                assertEquals(0, StringUtils.indexOf("", ""));
112:                assertEquals(0, StringUtils.indexOf("aabaabaa", "a"));
113:                assertEquals(2, StringUtils.indexOf("aabaabaa", "b"));
114:                assertEquals(1, StringUtils.indexOf("aabaabaa", "ab"));
115:                assertEquals(0, StringUtils.indexOf("aabaabaa", ""));
116:            }
117:
118:            public void testOrdinalIndexOf() {
119:                assertEquals(-1, StringUtils.ordinalIndexOf(null, null,
120:                        Integer.MIN_VALUE));
121:                assertEquals(-1, StringUtils.ordinalIndexOf("", null,
122:                        Integer.MIN_VALUE));
123:                assertEquals(-1, StringUtils.ordinalIndexOf("", "",
124:                        Integer.MIN_VALUE));
125:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "a",
126:                        Integer.MIN_VALUE));
127:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b",
128:                        Integer.MIN_VALUE));
129:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab",
130:                        Integer.MIN_VALUE));
131:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "",
132:                        Integer.MIN_VALUE));
133:
134:                assertEquals(-1, StringUtils.ordinalIndexOf(null, null, -1));
135:                assertEquals(-1, StringUtils.ordinalIndexOf("", null, -1));
136:                assertEquals(-1, StringUtils.ordinalIndexOf("", "", -1));
137:                assertEquals(-1, StringUtils
138:                        .ordinalIndexOf("aabaabaa", "a", -1));
139:                assertEquals(-1, StringUtils
140:                        .ordinalIndexOf("aabaabaa", "b", -1));
141:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab",
142:                        -1));
143:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", -1));
144:
145:                assertEquals(-1, StringUtils.ordinalIndexOf(null, null, 0));
146:                assertEquals(-1, StringUtils.ordinalIndexOf("", null, 0));
147:                assertEquals(-1, StringUtils.ordinalIndexOf("", "", 0));
148:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "a", 0));
149:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", 0));
150:                assertEquals(-1, StringUtils
151:                        .ordinalIndexOf("aabaabaa", "ab", 0));
152:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", 0));
153:
154:                assertEquals(-1, StringUtils.ordinalIndexOf(null, null, 1));
155:                assertEquals(-1, StringUtils.ordinalIndexOf("", null, 1));
156:                assertEquals(0, StringUtils.ordinalIndexOf("", "", 1));
157:                assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "a", 1));
158:                assertEquals(2, StringUtils.ordinalIndexOf("aabaabaa", "b", 1));
159:                assertEquals(1, StringUtils.ordinalIndexOf("aabaabaa", "ab", 1));
160:                assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", 1));
161:
162:                assertEquals(-1, StringUtils.ordinalIndexOf(null, null, 2));
163:                assertEquals(-1, StringUtils.ordinalIndexOf("", null, 2));
164:                assertEquals(0, StringUtils.ordinalIndexOf("", "", 2));
165:                assertEquals(1, StringUtils.ordinalIndexOf("aabaabaa", "a", 2));
166:                assertEquals(5, StringUtils.ordinalIndexOf("aabaabaa", "b", 2));
167:                assertEquals(4, StringUtils.ordinalIndexOf("aabaabaa", "ab", 2));
168:                assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", 2));
169:
170:                assertEquals(-1, StringUtils.ordinalIndexOf(null, null,
171:                        Integer.MAX_VALUE));
172:                assertEquals(-1, StringUtils.ordinalIndexOf("", null,
173:                        Integer.MAX_VALUE));
174:                assertEquals(0, StringUtils.ordinalIndexOf("", "",
175:                        Integer.MAX_VALUE));
176:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "a",
177:                        Integer.MAX_VALUE));
178:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b",
179:                        Integer.MAX_VALUE));
180:                assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab",
181:                        Integer.MAX_VALUE));
182:                assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "",
183:                        Integer.MAX_VALUE));
184:
185:                assertEquals(-1, StringUtils
186:                        .ordinalIndexOf("aaaaaaaaa", "a", 0));
187:                assertEquals(0, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 1));
188:                assertEquals(1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 2));
189:                assertEquals(2, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 3));
190:                assertEquals(3, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 4));
191:                assertEquals(4, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 5));
192:                assertEquals(5, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 6));
193:                assertEquals(6, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 7));
194:                assertEquals(7, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 8));
195:                assertEquals(8, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 9));
196:                assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a",
197:                        10));
198:            }
199:
200:            public void testIndexOf_StringInt() {
201:                assertEquals(-1, StringUtils.indexOf(null, null, 0));
202:                assertEquals(-1, StringUtils.indexOf(null, null, -1));
203:                assertEquals(-1, StringUtils.indexOf(null, "", 0));
204:                assertEquals(-1, StringUtils.indexOf(null, "", -1));
205:                assertEquals(-1, StringUtils.indexOf("", null, 0));
206:                assertEquals(-1, StringUtils.indexOf("", null, -1));
207:                assertEquals(0, StringUtils.indexOf("", "", 0));
208:                assertEquals(0, StringUtils.indexOf("", "", -1));
209:                assertEquals(0, StringUtils.indexOf("", "", 9));
210:                assertEquals(0, StringUtils.indexOf("abc", "", 0));
211:                assertEquals(0, StringUtils.indexOf("abc", "", -1));
212:                assertEquals(3, StringUtils.indexOf("abc", "", 9));
213:                assertEquals(3, StringUtils.indexOf("abc", "", 3));
214:                assertEquals(0, StringUtils.indexOf("aabaabaa", "a", 0));
215:                assertEquals(2, StringUtils.indexOf("aabaabaa", "b", 0));
216:                assertEquals(1, StringUtils.indexOf("aabaabaa", "ab", 0));
217:                assertEquals(5, StringUtils.indexOf("aabaabaa", "b", 3));
218:                assertEquals(-1, StringUtils.indexOf("aabaabaa", "b", 9));
219:                assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1));
220:                assertEquals(2, StringUtils.indexOf("aabaabaa", "", 2));
221:            }
222:
223:            //-----------------------------------------------------------------------
224:            public void testLastIndexOf_char() {
225:                assertEquals(-1, StringUtils.lastIndexOf(null, ' '));
226:                assertEquals(-1, StringUtils.lastIndexOf("", ' '));
227:                assertEquals(7, StringUtils.lastIndexOf("aabaabaa", 'a'));
228:                assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b'));
229:            }
230:
231:            public void testLastIndexOf_charInt() {
232:                assertEquals(-1, StringUtils.lastIndexOf(null, ' ', 0));
233:                assertEquals(-1, StringUtils.lastIndexOf(null, ' ', -1));
234:                assertEquals(-1, StringUtils.lastIndexOf("", ' ', 0));
235:                assertEquals(-1, StringUtils.lastIndexOf("", ' ', -1));
236:                assertEquals(7, StringUtils.lastIndexOf("aabaabaa", 'a', 8));
237:                assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b', 8));
238:                assertEquals(2, StringUtils.lastIndexOf("aabaabaa", 'b', 3));
239:                assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b', 9));
240:                assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", 'b', -1));
241:                assertEquals(0, StringUtils.lastIndexOf("aabaabaa", 'a', 0));
242:            }
243:
244:            public void testLastIndexOf_String() {
245:                assertEquals(-1, StringUtils.lastIndexOf(null, null));
246:                assertEquals(-1, StringUtils.lastIndexOf("", null));
247:                assertEquals(-1, StringUtils.lastIndexOf("", "a"));
248:                assertEquals(0, StringUtils.lastIndexOf("", ""));
249:                assertEquals(8, StringUtils.lastIndexOf("aabaabaa", ""));
250:                assertEquals(7, StringUtils.lastIndexOf("aabaabaa", "a"));
251:                assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b"));
252:                assertEquals(4, StringUtils.lastIndexOf("aabaabaa", "ab"));
253:            }
254:
255:            public void testLastIndexOf_StringInt() {
256:                assertEquals(-1, StringUtils.lastIndexOf(null, null, 0));
257:                assertEquals(-1, StringUtils.lastIndexOf(null, null, -1));
258:                assertEquals(-1, StringUtils.lastIndexOf(null, "", 0));
259:                assertEquals(-1, StringUtils.lastIndexOf(null, "", -1));
260:                assertEquals(-1, StringUtils.lastIndexOf("", null, 0));
261:                assertEquals(-1, StringUtils.lastIndexOf("", null, -1));
262:                assertEquals(0, StringUtils.lastIndexOf("", "", 0));
263:                assertEquals(-1, StringUtils.lastIndexOf("", "", -1));
264:                assertEquals(0, StringUtils.lastIndexOf("", "", 9));
265:                assertEquals(0, StringUtils.lastIndexOf("abc", "", 0));
266:                assertEquals(-1, StringUtils.lastIndexOf("abc", "", -1));
267:                assertEquals(3, StringUtils.lastIndexOf("abc", "", 9));
268:                assertEquals(7, StringUtils.lastIndexOf("aabaabaa", "a", 8));
269:                assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b", 8));
270:                assertEquals(4, StringUtils.lastIndexOf("aabaabaa", "ab", 8));
271:                assertEquals(2, StringUtils.lastIndexOf("aabaabaa", "b", 3));
272:                assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b", 9));
273:                assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "b", -1));
274:                assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "b", 0));
275:                assertEquals(0, StringUtils.lastIndexOf("aabaabaa", "a", 0));
276:            }
277:
278:            //-----------------------------------------------------------------------
279:            public void testContainsChar() {
280:                assertEquals(false, StringUtils.contains(null, ' '));
281:                assertEquals(false, StringUtils.contains("", ' '));
282:                assertEquals(false, StringUtils.contains("", null));
283:                assertEquals(false, StringUtils.contains(null, null));
284:                assertEquals(true, StringUtils.contains("abc", 'a'));
285:                assertEquals(true, StringUtils.contains("abc", 'b'));
286:                assertEquals(true, StringUtils.contains("abc", 'c'));
287:                assertEquals(false, StringUtils.contains("abc", 'z'));
288:            }
289:
290:            public void testContainsString() {
291:                assertEquals(false, StringUtils.contains(null, null));
292:                assertEquals(false, StringUtils.contains(null, ""));
293:                assertEquals(false, StringUtils.contains(null, "a"));
294:                assertEquals(false, StringUtils.contains("", null));
295:                assertEquals(true, StringUtils.contains("", ""));
296:                assertEquals(false, StringUtils.contains("", "a"));
297:                assertEquals(true, StringUtils.contains("abc", "a"));
298:                assertEquals(true, StringUtils.contains("abc", "b"));
299:                assertEquals(true, StringUtils.contains("abc", "c"));
300:                assertEquals(true, StringUtils.contains("abc", "abc"));
301:                assertEquals(false, StringUtils.contains("abc", "z"));
302:            }
303:
304:            public void testContainsIgnoreCase_StringString() {
305:                assertFalse(StringUtils.containsIgnoreCase(null, null));
306:
307:                // Null tests
308:                assertFalse(StringUtils.containsIgnoreCase(null, ""));
309:                assertFalse(StringUtils.containsIgnoreCase(null, "a"));
310:                assertFalse(StringUtils.containsIgnoreCase(null, "abc"));
311:
312:                assertFalse(StringUtils.containsIgnoreCase("", null));
313:                assertFalse(StringUtils.containsIgnoreCase("a", null));
314:                assertFalse(StringUtils.containsIgnoreCase("abc", null));
315:
316:                // Match len = 0
317:                assertTrue(StringUtils.containsIgnoreCase("", ""));
318:                assertTrue(StringUtils.containsIgnoreCase("a", ""));
319:                assertTrue(StringUtils.containsIgnoreCase("abc", ""));
320:
321:                // Match len = 1
322:                assertFalse(StringUtils.containsIgnoreCase("", "a"));
323:                assertTrue(StringUtils.containsIgnoreCase("a", "a"));
324:                assertTrue(StringUtils.containsIgnoreCase("abc", "a"));
325:                assertFalse(StringUtils.containsIgnoreCase("", "A"));
326:                assertTrue(StringUtils.containsIgnoreCase("a", "A"));
327:                assertTrue(StringUtils.containsIgnoreCase("abc", "A"));
328:
329:                // Match len > 1
330:                assertFalse(StringUtils.containsIgnoreCase("", "abc"));
331:                assertFalse(StringUtils.containsIgnoreCase("a", "abc"));
332:                assertTrue(StringUtils.containsIgnoreCase("xabcz", "abc"));
333:                assertFalse(StringUtils.containsIgnoreCase("", "ABC"));
334:                assertFalse(StringUtils.containsIgnoreCase("a", "ABC"));
335:                assertTrue(StringUtils.containsIgnoreCase("xabcz", "ABC"));
336:            }
337:
338:            //-----------------------------------------------------------------------
339:            public void testIndexOfAny_StringStringarray() {
340:                assertEquals(-1, StringUtils.indexOfAny(null, (String[]) null));
341:                assertEquals(-1, StringUtils.indexOfAny(null, FOOBAR_SUB_ARRAY));
342:                assertEquals(-1, StringUtils
343:                        .indexOfAny(FOOBAR, (String[]) null));
344:                assertEquals(2, StringUtils
345:                        .indexOfAny(FOOBAR, FOOBAR_SUB_ARRAY));
346:                assertEquals(-1, StringUtils.indexOfAny(FOOBAR, new String[0]));
347:                assertEquals(-1, StringUtils.indexOfAny(null, new String[0]));
348:                assertEquals(-1, StringUtils.indexOfAny("", new String[0]));
349:                assertEquals(-1, StringUtils.indexOfAny(FOOBAR,
350:                        new String[] { "llll" }));
351:                assertEquals(0, StringUtils.indexOfAny(FOOBAR,
352:                        new String[] { "" }));
353:                assertEquals(0, StringUtils.indexOfAny("", new String[] { "" }));
354:                assertEquals(-1, StringUtils.indexOfAny("",
355:                        new String[] { "a" }));
356:                assertEquals(-1, StringUtils.indexOfAny("",
357:                        new String[] { null }));
358:                assertEquals(-1, StringUtils.indexOfAny(FOOBAR,
359:                        new String[] { null }));
360:                assertEquals(-1, StringUtils.indexOfAny(null,
361:                        new String[] { null }));
362:            }
363:
364:            public void testLastIndexOfAny_StringStringarray() {
365:                assertEquals(-1, StringUtils.lastIndexOfAny(null, null));
366:                assertEquals(-1, StringUtils.lastIndexOfAny(null,
367:                        FOOBAR_SUB_ARRAY));
368:                assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR, null));
369:                assertEquals(3, StringUtils.lastIndexOfAny(FOOBAR,
370:                        FOOBAR_SUB_ARRAY));
371:                assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR,
372:                        new String[0]));
373:                assertEquals(-1, StringUtils
374:                        .lastIndexOfAny(null, new String[0]));
375:                assertEquals(-1, StringUtils.lastIndexOfAny("", new String[0]));
376:                assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR,
377:                        new String[] { "llll" }));
378:                assertEquals(6, StringUtils.lastIndexOfAny(FOOBAR,
379:                        new String[] { "" }));
380:                assertEquals(0, StringUtils.lastIndexOfAny("",
381:                        new String[] { "" }));
382:                assertEquals(-1, StringUtils.lastIndexOfAny("",
383:                        new String[] { "a" }));
384:                assertEquals(-1, StringUtils.lastIndexOfAny("",
385:                        new String[] { null }));
386:                assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR,
387:                        new String[] { null }));
388:                assertEquals(-1, StringUtils.lastIndexOfAny(null,
389:                        new String[] { null }));
390:            }
391:
392:            //-----------------------------------------------------------------------
393:            public void testIndexOfAny_StringChararray() {
394:                assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null));
395:                assertEquals(-1, StringUtils.indexOfAny(null, new char[0]));
396:                assertEquals(-1, StringUtils.indexOfAny(null, new char[] { 'a',
397:                        'b' }));
398:
399:                assertEquals(-1, StringUtils.indexOfAny("", (char[]) null));
400:                assertEquals(-1, StringUtils.indexOfAny("", new char[0]));
401:                assertEquals(-1, StringUtils.indexOfAny("", new char[] { 'a',
402:                        'b' }));
403:
404:                assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx",
405:                        (char[]) null));
406:                assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx",
407:                        new char[0]));
408:                assertEquals(0, StringUtils.indexOfAny("zzabyycdxx",
409:                        new char[] { 'z', 'a' }));
410:                assertEquals(3, StringUtils.indexOfAny("zzabyycdxx",
411:                        new char[] { 'b', 'y' }));
412:                assertEquals(-1, StringUtils.indexOfAny("ab",
413:                        new char[] { 'z' }));
414:            }
415:
416:            public void testIndexOfAny_StringString() {
417:                assertEquals(-1, StringUtils.indexOfAny(null, (String) null));
418:                assertEquals(-1, StringUtils.indexOfAny(null, ""));
419:                assertEquals(-1, StringUtils.indexOfAny(null, "ab"));
420:
421:                assertEquals(-1, StringUtils.indexOfAny("", (String) null));
422:                assertEquals(-1, StringUtils.indexOfAny("", ""));
423:                assertEquals(-1, StringUtils.indexOfAny("", "ab"));
424:
425:                assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx",
426:                        (String) null));
427:                assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", ""));
428:                assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", "za"));
429:                assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", "by"));
430:                assertEquals(-1, StringUtils.indexOfAny("ab", "z"));
431:            }
432:
433:            //-----------------------------------------------------------------------
434:            public void testIndexOfAnyBut_StringChararray() {
435:                assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null));
436:                assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0]));
437:                assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[] {
438:                        'a', 'b' }));
439:
440:                assertEquals(-1, StringUtils.indexOfAnyBut("", (char[]) null));
441:                assertEquals(-1, StringUtils.indexOfAnyBut("", new char[0]));
442:                assertEquals(-1, StringUtils.indexOfAnyBut("", new char[] {
443:                        'a', 'b' }));
444:
445:                assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx",
446:                        (char[]) null));
447:                assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx",
448:                        new char[0]));
449:                assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx",
450:                        new char[] { 'z', 'a' }));
451:                assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx",
452:                        new char[] { 'b', 'y' }));
453:                assertEquals(0, StringUtils.indexOfAnyBut("ab",
454:                        new char[] { 'z' }));
455:            }
456:
457:            public void testIndexOfAnyBut_StringString() {
458:                assertEquals(-1, StringUtils.indexOfAnyBut(null, (String) null));
459:                assertEquals(-1, StringUtils.indexOfAnyBut(null, ""));
460:                assertEquals(-1, StringUtils.indexOfAnyBut(null, "ab"));
461:
462:                assertEquals(-1, StringUtils.indexOfAnyBut("", (String) null));
463:                assertEquals(-1, StringUtils.indexOfAnyBut("", ""));
464:                assertEquals(-1, StringUtils.indexOfAnyBut("", "ab"));
465:
466:                assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx",
467:                        (String) null));
468:                assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", ""));
469:                assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", "za"));
470:                assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", "by"));
471:                assertEquals(0, StringUtils.indexOfAnyBut("ab", "z"));
472:            }
473:
474:            //-----------------------------------------------------------------------
475:            public void testContainsOnly_String() {
476:                String str1 = "a";
477:                String str2 = "b";
478:                String str3 = "ab";
479:                String chars1 = "b";
480:                String chars2 = "a";
481:                String chars3 = "ab";
482:                assertEquals(false, StringUtils.containsOnly(null,
483:                        (String) null));
484:                assertEquals(false, StringUtils.containsOnly("", (String) null));
485:                assertEquals(false, StringUtils.containsOnly(null, ""));
486:                assertEquals(false, StringUtils.containsOnly(str1, ""));
487:                assertEquals(true, StringUtils.containsOnly("", ""));
488:                assertEquals(true, StringUtils.containsOnly("", chars1));
489:                assertEquals(false, StringUtils.containsOnly(str1, chars1));
490:                assertEquals(true, StringUtils.containsOnly(str1, chars2));
491:                assertEquals(true, StringUtils.containsOnly(str1, chars3));
492:                assertEquals(true, StringUtils.containsOnly(str2, chars1));
493:                assertEquals(false, StringUtils.containsOnly(str2, chars2));
494:                assertEquals(true, StringUtils.containsOnly(str2, chars3));
495:                assertEquals(false, StringUtils.containsOnly(str3, chars1));
496:                assertEquals(false, StringUtils.containsOnly(str3, chars2));
497:                assertEquals(true, StringUtils.containsOnly(str3, chars3));
498:            }
499:
500:            public void testContainsOnly_Chararray() {
501:                String str1 = "a";
502:                String str2 = "b";
503:                String str3 = "ab";
504:                char[] chars1 = { 'b' };
505:                char[] chars2 = { 'a' };
506:                char[] chars3 = { 'a', 'b' };
507:                char[] emptyChars = new char[0];
508:                assertEquals(false, StringUtils.containsOnly(null,
509:                        (char[]) null));
510:                assertEquals(false, StringUtils.containsOnly("", (char[]) null));
511:                assertEquals(false, StringUtils.containsOnly(null, emptyChars));
512:                assertEquals(false, StringUtils.containsOnly(str1, emptyChars));
513:                assertEquals(true, StringUtils.containsOnly("", emptyChars));
514:                assertEquals(true, StringUtils.containsOnly("", chars1));
515:                assertEquals(false, StringUtils.containsOnly(str1, chars1));
516:                assertEquals(true, StringUtils.containsOnly(str1, chars2));
517:                assertEquals(true, StringUtils.containsOnly(str1, chars3));
518:                assertEquals(true, StringUtils.containsOnly(str2, chars1));
519:                assertEquals(false, StringUtils.containsOnly(str2, chars2));
520:                assertEquals(true, StringUtils.containsOnly(str2, chars3));
521:                assertEquals(false, StringUtils.containsOnly(str3, chars1));
522:                assertEquals(false, StringUtils.containsOnly(str3, chars2));
523:                assertEquals(true, StringUtils.containsOnly(str3, chars3));
524:            }
525:
526:            public void testContainsNone_String() {
527:                String str1 = "a";
528:                String str2 = "b";
529:                String str3 = "ab.";
530:                String chars1 = "b";
531:                String chars2 = ".";
532:                String chars3 = "cd";
533:                assertEquals(true, StringUtils
534:                        .containsNone(null, (String) null));
535:                assertEquals(true, StringUtils.containsNone("", (String) null));
536:                assertEquals(true, StringUtils.containsNone(null, ""));
537:                assertEquals(true, StringUtils.containsNone(str1, ""));
538:                assertEquals(true, StringUtils.containsNone("", ""));
539:                assertEquals(true, StringUtils.containsNone("", chars1));
540:                assertEquals(true, StringUtils.containsNone(str1, chars1));
541:                assertEquals(true, StringUtils.containsNone(str1, chars2));
542:                assertEquals(true, StringUtils.containsNone(str1, chars3));
543:                assertEquals(false, StringUtils.containsNone(str2, chars1));
544:                assertEquals(true, StringUtils.containsNone(str2, chars2));
545:                assertEquals(true, StringUtils.containsNone(str2, chars3));
546:                assertEquals(false, StringUtils.containsNone(str3, chars1));
547:                assertEquals(false, StringUtils.containsNone(str3, chars2));
548:                assertEquals(true, StringUtils.containsNone(str3, chars3));
549:            }
550:
551:            public void testContainsNone_Chararray() {
552:                String str1 = "a";
553:                String str2 = "b";
554:                String str3 = "ab.";
555:                char[] chars1 = { 'b' };
556:                char[] chars2 = { '.' };
557:                char[] chars3 = { 'c', 'd' };
558:                char[] emptyChars = new char[0];
559:                assertEquals(true, StringUtils
560:                        .containsNone(null, (char[]) null));
561:                assertEquals(true, StringUtils.containsNone("", (char[]) null));
562:                assertEquals(true, StringUtils.containsNone(null, emptyChars));
563:                assertEquals(true, StringUtils.containsNone(str1, emptyChars));
564:                assertEquals(true, StringUtils.containsNone("", emptyChars));
565:                assertEquals(true, StringUtils.containsNone("", chars1));
566:                assertEquals(true, StringUtils.containsNone(str1, chars1));
567:                assertEquals(true, StringUtils.containsNone(str1, chars2));
568:                assertEquals(true, StringUtils.containsNone(str1, chars3));
569:                assertEquals(false, StringUtils.containsNone(str2, chars1));
570:                assertEquals(true, StringUtils.containsNone(str2, chars2));
571:                assertEquals(true, StringUtils.containsNone(str2, chars3));
572:                assertEquals(false, StringUtils.containsNone(str3, chars1));
573:                assertEquals(false, StringUtils.containsNone(str3, chars2));
574:                assertEquals(true, StringUtils.containsNone(str3, chars3));
575:            }
576:
577:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.