1 16 package org.apache.commons.lang; 17 18 import junit.framework.Test; 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 import junit.textui.TestRunner; 22 23 31 public class StringUtilsEqualsIndexOfTest extends TestCase { 32 private static final String FOO = "foo"; 33 private static final String BAR = "bar"; 34 private static final String FOOBAR = "foobar"; 35 private static final String [] FOOBAR_SUB_ARRAY = new String [] {"ob", "ba"}; 36 37 public StringUtilsEqualsIndexOfTest(String name) { 38 super(name); 39 } 40 41 public static void main(String [] args) { 42 TestRunner.run(suite()); 43 } 44 45 public static Test suite() { 46 TestSuite suite = new TestSuite(StringUtilsEqualsIndexOfTest.class); 47 suite.setName("StringUtilsEqualsIndexOf Tests"); 48 return suite; 49 } 50 51 protected void setUp() throws Exception { 52 super.setUp(); 53 } 54 55 protected void tearDown() throws Exception { 56 super.tearDown(); 57 } 58 59 61 public void testEquals() { 62 assertEquals(true, StringUtils.equals(null, null)); 63 assertEquals(true, StringUtils.equals(FOO, FOO)); 64 assertEquals(true, StringUtils.equals(FOO, new String (new char[] { 'f', 'o', 'o' }))); 65 assertEquals(false, StringUtils.equals(FOO, new String (new char[] { 'f', 'O', 'O' }))); 66 assertEquals(false, StringUtils.equals(FOO, BAR)); 67 assertEquals(false, StringUtils.equals(FOO, null)); 68 assertEquals(false, StringUtils.equals(null, FOO)); 69 } 70 71 public void testEqualsIgnoreCase() { 72 assertEquals(true, StringUtils.equalsIgnoreCase(null, null)); 73 assertEquals(true, StringUtils.equalsIgnoreCase(FOO, FOO)); 74 assertEquals(true, StringUtils.equalsIgnoreCase(FOO, new String (new char[] { 'f', 'o', 'o' }))); 75 assertEquals(true, StringUtils.equalsIgnoreCase(FOO, new String (new char[] { 'f', 'O', 'O' }))); 76 assertEquals(false, StringUtils.equalsIgnoreCase(FOO, BAR)); 77 assertEquals(false, StringUtils.equalsIgnoreCase(FOO, null)); 78 assertEquals(false, StringUtils.equalsIgnoreCase(null, FOO)); 79 } 80 81 public void testIndexOf_char() { 83 assertEquals(-1, StringUtils.indexOf(null, ' ')); 84 assertEquals(-1, StringUtils.indexOf("", ' ')); 85 assertEquals(0, StringUtils.indexOf("aabaabaa", 'a')); 86 assertEquals(2, StringUtils.indexOf("aabaabaa", 'b')); 87 } 88 89 public void testIndexOf_charInt() { 90 assertEquals(-1, StringUtils.indexOf(null, ' ', 0)); 91 assertEquals(-1, StringUtils.indexOf(null, ' ', -1)); 92 assertEquals(-1, StringUtils.indexOf("", ' ', 0)); 93 assertEquals(-1, StringUtils.indexOf("", ' ', -1)); 94 assertEquals(0, StringUtils.indexOf("aabaabaa", 'a', 0)); 95 assertEquals(2, StringUtils.indexOf("aabaabaa", 'b', 0)); 96 assertEquals(5, StringUtils.indexOf("aabaabaa", 'b', 3)); 97 assertEquals(-1, StringUtils.indexOf("aabaabaa", 'b', 9)); 98 assertEquals(2, StringUtils.indexOf("aabaabaa", 'b', -1)); 99 } 100 101 public void testIndexOf_String() { 102 assertEquals(-1, StringUtils.indexOf(null, null)); 103 assertEquals(-1, StringUtils.indexOf("", null)); 104 assertEquals(0, StringUtils.indexOf("", "")); 105 assertEquals(0, StringUtils.indexOf("aabaabaa", "a")); 106 assertEquals(2, StringUtils.indexOf("aabaabaa", "b")); 107 assertEquals(1, StringUtils.indexOf("aabaabaa", "ab")); 108 assertEquals(0, StringUtils.indexOf("aabaabaa", "")); 109 } 110 111 public void testOrdinalIndexOf() { 112 assertEquals(-1, StringUtils.ordinalIndexOf(null, null, Integer.MIN_VALUE)); 113 assertEquals(-1, StringUtils.ordinalIndexOf("", null, Integer.MIN_VALUE)); 114 assertEquals(-1, StringUtils.ordinalIndexOf("", "", Integer.MIN_VALUE)); 115 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "a", Integer.MIN_VALUE)); 116 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MIN_VALUE)); 117 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MIN_VALUE)); 118 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MIN_VALUE)); 119 120 assertEquals(-1, StringUtils.ordinalIndexOf(null, null, -1)); 121 assertEquals(-1, StringUtils.ordinalIndexOf("", null, -1)); 122 assertEquals(-1, StringUtils.ordinalIndexOf("", "", -1)); 123 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "a", -1)); 124 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", -1)); 125 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", -1)); 126 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", -1)); 127 128 assertEquals(-1, StringUtils.ordinalIndexOf(null, null, 0)); 129 assertEquals(-1, StringUtils.ordinalIndexOf("", null, 0)); 130 assertEquals(-1, StringUtils.ordinalIndexOf("", "", 0)); 131 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "a", 0)); 132 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", 0)); 133 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", 0)); 134 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", 0)); 135 136 assertEquals(-1, StringUtils.ordinalIndexOf(null, null, 1)); 137 assertEquals(-1, StringUtils.ordinalIndexOf("", null, 1)); 138 assertEquals(0, StringUtils.ordinalIndexOf("", "", 1)); 139 assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "a", 1)); 140 assertEquals(2, StringUtils.ordinalIndexOf("aabaabaa", "b", 1)); 141 assertEquals(1, StringUtils.ordinalIndexOf("aabaabaa", "ab", 1)); 142 assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", 1)); 143 144 assertEquals(-1, StringUtils.ordinalIndexOf(null, null, 2)); 145 assertEquals(-1, StringUtils.ordinalIndexOf("", null, 2)); 146 assertEquals(0, StringUtils.ordinalIndexOf("", "", 2)); 147 assertEquals(1, StringUtils.ordinalIndexOf("aabaabaa", "a", 2)); 148 assertEquals(5, StringUtils.ordinalIndexOf("aabaabaa", "b", 2)); 149 assertEquals(4, StringUtils.ordinalIndexOf("aabaabaa", "ab", 2)); 150 assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", 2)); 151 152 assertEquals(-1, StringUtils.ordinalIndexOf(null, null, Integer.MAX_VALUE)); 153 assertEquals(-1, StringUtils.ordinalIndexOf("", null, Integer.MAX_VALUE)); 154 assertEquals(0, StringUtils.ordinalIndexOf("", "", Integer.MAX_VALUE)); 155 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "a", Integer.MAX_VALUE)); 156 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MAX_VALUE)); 157 assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MAX_VALUE)); 158 assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MAX_VALUE)); 159 160 assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 0)); 161 assertEquals(0, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 1)); 162 assertEquals(1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 2)); 163 assertEquals(2, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 3)); 164 assertEquals(3, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 4)); 165 assertEquals(4, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 5)); 166 assertEquals(5, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 6)); 167 assertEquals(6, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 7)); 168 assertEquals(7, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 8)); 169 assertEquals(8, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 9)); 170 assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 10)); 171 } 172 173 public void testIndexOf_StringInt() { 174 assertEquals(-1, StringUtils.indexOf(null, null, 0)); 175 assertEquals(-1, StringUtils.indexOf(null, null, -1)); 176 assertEquals(-1, StringUtils.indexOf(null, "", 0)); 177 assertEquals(-1, StringUtils.indexOf(null, "", -1)); 178 assertEquals(-1, StringUtils.indexOf("", null, 0)); 179 assertEquals(-1, StringUtils.indexOf("", null, -1)); 180 assertEquals(0, StringUtils.indexOf("", "", 0)); 181 assertEquals(0, StringUtils.indexOf("", "", -1)); 182 assertEquals(0, StringUtils.indexOf("", "", 9)); 183 assertEquals(0, StringUtils.indexOf("abc", "", 0)); 184 assertEquals(0, StringUtils.indexOf("abc", "", -1)); 185 assertEquals(3, StringUtils.indexOf("abc", "", 9)); 186 assertEquals(3, StringUtils.indexOf("abc", "", 3)); 187 assertEquals(0, StringUtils.indexOf("aabaabaa", "a", 0)); 188 assertEquals(2, StringUtils.indexOf("aabaabaa", "b", 0)); 189 assertEquals(1, StringUtils.indexOf("aabaabaa", "ab", 0)); 190 assertEquals(5, StringUtils.indexOf("aabaabaa", "b", 3)); 191 assertEquals(-1, StringUtils.indexOf("aabaabaa", "b", 9)); 192 assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1)); 193 assertEquals(2,StringUtils.indexOf("aabaabaa", "", 2)); 194 } 195 196 public void testLastIndexOf_char() { 198 assertEquals(-1, StringUtils.lastIndexOf(null, ' ')); 199 assertEquals(-1, StringUtils.lastIndexOf("", ' ')); 200 assertEquals(7, StringUtils.lastIndexOf("aabaabaa", 'a')); 201 assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b')); 202 } 203 204 public void testLastIndexOf_charInt() { 205 assertEquals(-1, StringUtils.lastIndexOf(null, ' ', 0)); 206 assertEquals(-1, StringUtils.lastIndexOf(null, ' ', -1)); 207 assertEquals(-1, StringUtils.lastIndexOf("", ' ', 0)); 208 assertEquals(-1, StringUtils.lastIndexOf("", ' ', -1)); 209 assertEquals(7, StringUtils.lastIndexOf("aabaabaa", 'a', 8)); 210 assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b', 8)); 211 assertEquals(2, StringUtils.lastIndexOf("aabaabaa", 'b', 3)); 212 assertEquals(5, StringUtils.lastIndexOf("aabaabaa", 'b', 9)); 213 assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", 'b', -1)); 214 assertEquals(0, StringUtils.lastIndexOf("aabaabaa", 'a', 0)); 215 } 216 217 public void testLastIndexOf_String() { 218 assertEquals(-1, StringUtils.lastIndexOf(null, null)); 219 assertEquals(-1, StringUtils.lastIndexOf("", null)); 220 assertEquals(-1, StringUtils.lastIndexOf("", "a")); 221 assertEquals(0, StringUtils.lastIndexOf("", "")); 222 assertEquals(8, StringUtils.lastIndexOf("aabaabaa", "")); 223 assertEquals(7, StringUtils.lastIndexOf("aabaabaa", "a")); 224 assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b")); 225 assertEquals(4, StringUtils.lastIndexOf("aabaabaa", "ab")); 226 } 227 228 public void testLastIndexOf_StringInt() { 229 assertEquals(-1, StringUtils.lastIndexOf(null, null, 0)); 230 assertEquals(-1, StringUtils.lastIndexOf(null, null, -1)); 231 assertEquals(-1, StringUtils.lastIndexOf(null, "", 0)); 232 assertEquals(-1, StringUtils.lastIndexOf(null, "", -1)); 233 assertEquals(-1, StringUtils.lastIndexOf("", null, 0)); 234 assertEquals(-1, StringUtils.lastIndexOf("", null, -1)); 235 assertEquals(0, StringUtils.lastIndexOf("", "", 0)); 236 assertEquals(-1, StringUtils.lastIndexOf("", "", -1)); 237 assertEquals(0, StringUtils.lastIndexOf("", "", 9)); 238 assertEquals(0, StringUtils.lastIndexOf("abc", "", 0)); 239 assertEquals(-1, StringUtils.lastIndexOf("abc", "", -1)); 240 assertEquals(3, StringUtils.lastIndexOf("abc", "", 9)); 241 assertEquals(7, StringUtils.lastIndexOf("aabaabaa", "a", 8)); 242 assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b", 8)); 243 assertEquals(4, StringUtils.lastIndexOf("aabaabaa", "ab", 8)); 244 assertEquals(2, StringUtils.lastIndexOf("aabaabaa", "b", 3)); 245 assertEquals(5, StringUtils.lastIndexOf("aabaabaa", "b", 9)); 246 assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "b", -1)); 247 assertEquals(-1, StringUtils.lastIndexOf("aabaabaa", "b", 0)); 248 assertEquals(0, StringUtils.lastIndexOf("aabaabaa", "a", 0)); 249 } 250 251 public void testContainsChar() { 253 assertEquals(false, StringUtils.contains(null, ' ')); 254 assertEquals(false, StringUtils.contains("", ' ')); 255 assertEquals(false, StringUtils.contains("",null)); 256 assertEquals(false, StringUtils.contains(null,null)); 257 assertEquals(true, StringUtils.contains("abc", 'a')); 258 assertEquals(true, StringUtils.contains("abc", 'b')); 259 assertEquals(true, StringUtils.contains("abc", 'c')); 260 assertEquals(false, StringUtils.contains("abc", 'z')); 261 } 262 263 public void testContainsString() { 264 assertEquals(false, StringUtils.contains(null, null)); 265 assertEquals(false, StringUtils.contains(null, "")); 266 assertEquals(false, StringUtils.contains(null, "a")); 267 assertEquals(false, StringUtils.contains("", null)); 268 assertEquals(true, StringUtils.contains("", "")); 269 assertEquals(false, StringUtils.contains("", "a")); 270 assertEquals(true, StringUtils.contains("abc", "a")); 271 assertEquals(true, StringUtils.contains("abc", "b")); 272 assertEquals(true, StringUtils.contains("abc", "c")); 273 assertEquals(true, StringUtils.contains("abc", "abc")); 274 assertEquals(false, StringUtils.contains("abc", "z")); 275 } 276 277 public void testIndexOfAny_StringStringarray() { 279 assertEquals(-1, StringUtils.indexOfAny(null, (String []) null)); 280 assertEquals(-1, StringUtils.indexOfAny(null, FOOBAR_SUB_ARRAY)); 281 assertEquals(-1, StringUtils.indexOfAny(FOOBAR, (String []) null)); 282 assertEquals(2, StringUtils.indexOfAny(FOOBAR, FOOBAR_SUB_ARRAY)); 283 assertEquals(-1, StringUtils.indexOfAny(FOOBAR, new String [0])); 284 assertEquals(-1, StringUtils.indexOfAny(null, new String [0])); 285 assertEquals(-1, StringUtils.indexOfAny("", new String [0])); 286 assertEquals(-1, StringUtils.indexOfAny(FOOBAR, new String [] {"llll"})); 287 assertEquals(0, StringUtils.indexOfAny(FOOBAR, new String [] {""})); 288 assertEquals(0, StringUtils.indexOfAny("", new String [] {""})); 289 assertEquals(-1, StringUtils.indexOfAny("", new String [] {"a"})); 290 assertEquals(-1, StringUtils.indexOfAny("", new String [] {null})); 291 assertEquals(-1, StringUtils.indexOfAny(FOOBAR, new String [] {null})); 292 assertEquals(-1, StringUtils.indexOfAny(null, new String [] {null})); 293 } 294 295 public void testLastIndexOfAny_StringStringarray() { 296 assertEquals(-1, StringUtils.lastIndexOfAny(null, null)); 297 assertEquals(-1, StringUtils.lastIndexOfAny(null, FOOBAR_SUB_ARRAY)); 298 assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR, null)); 299 assertEquals(3, StringUtils.lastIndexOfAny(FOOBAR, FOOBAR_SUB_ARRAY)); 300 assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR, new String [0])); 301 assertEquals(-1, StringUtils.lastIndexOfAny(null, new String [0])); 302 assertEquals(-1, StringUtils.lastIndexOfAny("", new String [0])); 303 assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR, new String [] {"llll"})); 304 assertEquals(6, StringUtils.lastIndexOfAny(FOOBAR, new String [] {""})); 305 assertEquals(0, StringUtils.lastIndexOfAny("", new String [] {""})); 306 assertEquals(-1, StringUtils.lastIndexOfAny("", new String [] {"a"})); 307 assertEquals(-1, StringUtils.lastIndexOfAny("", new String [] {null})); 308 assertEquals(-1, StringUtils.lastIndexOfAny(FOOBAR, new String [] {null})); 309 assertEquals(-1, StringUtils.lastIndexOfAny(null, new String [] {null})); 310 } 311 312 public void testIndexOfAny_StringChararray() { 314 assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null)); 315 assertEquals(-1, StringUtils.indexOfAny(null, new char[0])); 316 assertEquals(-1, StringUtils.indexOfAny(null, new char[] {'a','b'})); 317 318 assertEquals(-1, StringUtils.indexOfAny("", (char[]) null)); 319 assertEquals(-1, StringUtils.indexOfAny("", new char[0])); 320 assertEquals(-1, StringUtils.indexOfAny("", new char[] {'a','b'})); 321 322 assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (char[]) null)); 323 assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", new char[0])); 324 assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", new char[] {'z','a'})); 325 assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", new char[] {'b','y'})); 326 assertEquals(-1, StringUtils.indexOfAny("ab", new char[] {'z'})); 327 } 328 329 public void testIndexOfAny_StringString() { 330 assertEquals(-1, StringUtils.indexOfAny(null, (String ) null)); 331 assertEquals(-1, StringUtils.indexOfAny(null, "")); 332 assertEquals(-1, StringUtils.indexOfAny(null, "ab")); 333 334 assertEquals(-1, StringUtils.indexOfAny("", (String ) null)); 335 assertEquals(-1, StringUtils.indexOfAny("", "")); 336 assertEquals(-1, StringUtils.indexOfAny("", "ab")); 337 338 assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (String ) null)); 339 assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", "")); 340 assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", "za")); 341 assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", "by")); 342 assertEquals(-1, StringUtils.indexOfAny("ab", "z")); 343 } 344 345 public void testIndexOfAnyBut_StringChararray() { 347 assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null)); 348 assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0])); 349 assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[] {'a','b'})); 350 351 assertEquals(-1, StringUtils.indexOfAnyBut("", (char[]) null)); 352 assertEquals(-1, StringUtils.indexOfAnyBut("", new char[0])); 353 assertEquals(-1, StringUtils.indexOfAnyBut("", new char[] {'a','b'})); 354 355 assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (char[]) null)); 356 assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", new char[0])); 357 assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z','a'})); 358 assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'b','y'})); 359 assertEquals(0, StringUtils.indexOfAnyBut("ab", new char[] {'z'})); 360 } 361 362 public void testIndexOfAnyBut_StringString() { 363 assertEquals(-1, StringUtils.indexOfAnyBut(null, (String ) null)); 364 assertEquals(-1, StringUtils.indexOfAnyBut(null, "")); 365 assertEquals(-1, StringUtils.indexOfAnyBut(null, "ab")); 366 367 assertEquals(-1, StringUtils.indexOfAnyBut("", (String ) null)); 368 assertEquals(-1, StringUtils.indexOfAnyBut("", "")); 369 assertEquals(-1, StringUtils.indexOfAnyBut("", "ab")); 370 371 assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (String ) null)); 372 assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", "")); 373 assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", "za")); 374 assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", "by")); 375 assertEquals(0, StringUtils.indexOfAnyBut("ab", "z")); 376 } 377 378 public void testContainsOnly_String() { 380 String str1 = "a"; 381 String str2 = "b"; 382 String str3 = "ab"; 383 String chars1= "b"; 384 String chars2= "a"; 385 String chars3= "ab"; 386 assertEquals(false, StringUtils.containsOnly(null, (String ) null)); 387 assertEquals(false, StringUtils.containsOnly("", (String ) null)); 388 assertEquals(false, StringUtils.containsOnly(null, "")); 389 assertEquals(false, StringUtils.containsOnly(str1, "")); 390 assertEquals(true, StringUtils.containsOnly("", "")); 391 assertEquals(true, StringUtils.containsOnly("", chars1)); 392 assertEquals(false, StringUtils.containsOnly(str1, chars1)); 393 assertEquals(true, StringUtils.containsOnly(str1, chars2)); 394 assertEquals(true, StringUtils.containsOnly(str1, chars3)); 395 assertEquals(true, StringUtils.containsOnly(str2, chars1)); 396 assertEquals(false, StringUtils.containsOnly(str2, chars2)); 397 assertEquals(true, StringUtils.containsOnly(str2, chars3)); 398 assertEquals(false, StringUtils.containsOnly(str3, chars1)); 399 assertEquals(false, StringUtils.containsOnly(str3, chars2)); 400 assertEquals(true, StringUtils.containsOnly(str3, chars3)); 401 } 402 403 public void testContainsOnly_Chararray() { 404 String str1 = "a"; 405 String str2 = "b"; 406 String str3 = "ab"; 407 char[] chars1= {'b'}; 408 char[] chars2= {'a'}; 409 char[] chars3= {'a', 'b'}; 410 char[] emptyChars = new char[0]; 411 assertEquals(false, StringUtils.containsOnly(null, (char[]) null)); 412 assertEquals(false, StringUtils.containsOnly("", (char[]) null)); 413 assertEquals(false, StringUtils.containsOnly(null, emptyChars)); 414 assertEquals(false, StringUtils.containsOnly(str1, emptyChars)); 415 assertEquals(true, StringUtils.containsOnly("", emptyChars)); 416 assertEquals(true, StringUtils.containsOnly("", chars1)); 417 assertEquals(false, StringUtils.containsOnly(str1, chars1)); 418 assertEquals(true, StringUtils.containsOnly(str1, chars2)); 419 assertEquals(true, StringUtils.containsOnly(str1, chars3)); 420 assertEquals(true, StringUtils.containsOnly(str2, chars1)); 421 assertEquals(false, StringUtils.containsOnly(str2, chars2)); 422 assertEquals(true, StringUtils.containsOnly(str2, chars3)); 423 assertEquals(false, StringUtils.containsOnly(str3, chars1)); 424 assertEquals(false, StringUtils.containsOnly(str3, chars2)); 425 assertEquals(true, StringUtils.containsOnly(str3, chars3)); 426 } 427 428 public void testContainsNone_String() { 429 String str1 = "a"; 430 String str2 = "b"; 431 String str3 = "ab."; 432 String chars1= "b"; 433 String chars2= "."; 434 String chars3= "cd"; 435 assertEquals(true, StringUtils.containsNone(null, (String ) null)); 436 assertEquals(true, StringUtils.containsNone("", (String ) null)); 437 assertEquals(true, StringUtils.containsNone(null, "")); 438 assertEquals(true, StringUtils.containsNone(str1, "")); 439 assertEquals(true, StringUtils.containsNone("", "")); 440 assertEquals(true, StringUtils.containsNone("", chars1)); 441 assertEquals(true, StringUtils.containsNone(str1, chars1)); 442 assertEquals(true, StringUtils.containsNone(str1, chars2)); 443 assertEquals(true, StringUtils.containsNone(str1, chars3)); 444 assertEquals(false, StringUtils.containsNone(str2, chars1)); 445 assertEquals(true, StringUtils.containsNone(str2, chars2)); 446 assertEquals(true, StringUtils.containsNone(str2, chars3)); 447 assertEquals(false, StringUtils.containsNone(str3, chars1)); 448 assertEquals(false, StringUtils.containsNone(str3, chars2)); 449 assertEquals(true, StringUtils.containsNone(str3, chars3)); 450 } 451 452 public void testContainsNone_Chararray() { 453 String str1 = "a"; 454 String str2 = "b"; 455 String str3 = "ab."; 456 char[] chars1= {'b'}; 457 char[] chars2= {'.'}; 458 char[] chars3= {'c', 'd'}; 459 char[] emptyChars = new char[0]; 460 assertEquals(true, StringUtils.containsNone(null, (char[]) null)); 461 assertEquals(true, StringUtils.containsNone("", (char[]) null)); 462 assertEquals(true, StringUtils.containsNone(null, emptyChars)); 463 assertEquals(true, StringUtils.containsNone(str1, emptyChars)); 464 assertEquals(true, StringUtils.containsNone("", emptyChars)); 465 assertEquals(true, StringUtils.containsNone("", chars1)); 466 assertEquals(true, StringUtils.containsNone(str1, chars1)); 467 assertEquals(true, StringUtils.containsNone(str1, chars2)); 468 assertEquals(true, StringUtils.containsNone(str1, chars3)); 469 assertEquals(false, StringUtils.containsNone(str2, chars1)); 470 assertEquals(true, StringUtils.containsNone(str2, chars2)); 471 assertEquals(true, StringUtils.containsNone(str2, chars3)); 472 assertEquals(false, StringUtils.containsNone(str3, chars1)); 473 assertEquals(false, StringUtils.containsNone(str3, chars2)); 474 assertEquals(true, StringUtils.containsNone(str3, chars3)); 475 } 476 477 } 478 | Popular Tags |