1 9 package org.jboss.portal.test.core.util; 10 11 import java.util.HashMap ; 12 13 import junit.framework.TestCase; 14 15 import org.jboss.portal.core.util.Parameters; 16 17 21 public class ParametersTestCase 22 extends TestCase 23 { 24 25 private Parameters params; 26 27 String booltrue01 = "true"; 28 29 String booltrue02 = "trUe"; 30 31 String booltrue03 = "TRUE"; 32 33 String boolfalse01 = "false"; 34 35 String boolfalse02 = "FALse"; 36 37 String boolfalse03 = "FALSE"; 38 39 String int01 = "10"; 40 41 String int02 = " 10"; 42 43 String int03 = " 10 "; 44 45 String float01 = "3.14"; 46 47 String float02 = " 3.14"; 48 49 String float03 = " 3.14 "; 50 51 String float04 = "3"; 52 53 String double01 = "" + Math.PI; 54 55 String double02 = " " + Math.PI; 56 57 String double03 = "3.14"; 58 59 String double04 = "3"; 60 61 String string01 = "foo"; 62 63 String string02 = " bar"; 64 65 String stringEmpty = ""; 66 67 String stringNull = null; 68 69 String long01 = "" + (Integer.MAX_VALUE + 10); 70 71 public void setUp() 72 { 73 HashMap map = new HashMap (); 74 map.put("booltrue01", new String [] { booltrue01 }); 75 map.put("booltrue02", new String [] { booltrue02 }); 76 map.put("booltrue03", new String [] { booltrue03 }); 77 map.put("boolfalse01", new String [] { boolfalse01 }); 78 map.put("boolfalse02", new String [] { boolfalse02 }); 79 map.put("boolfalse03", new String [] { boolfalse03 }); 80 map.put("int01", new String [] { int01 }); 81 map.put("int02", new String [] { int02 }); 82 map.put("int03", new String [] { int03 }); 83 map.put("float01", new String [] { float01 }); 84 map.put("float02", new String [] { float02 }); 85 map.put("float03", new String [] { float03 }); 86 map.put("float04", new String [] { float04 }); 87 map.put("double01", new String [] { double01 }); 88 map.put("double02", new String [] { double02 }); 89 map.put("double03", new String [] { double03 }); 90 map.put("double04", new String [] { double04 }); 91 map.put("string01", new String [] { string01 }); 92 map.put("string02", new String [] { string02 }); 93 map.put("long01", new String [] { long01 }); 94 map.put("stringEmpty", new String [] { stringEmpty }); 95 map.put("stringNull", new String [] { stringNull }); 96 97 params = new Parameters(map); 98 } 99 100 public void testGet01() 101 { 102 String string = params.get("string01", "toto"); 103 assertEquals(string01, string); 104 } 105 106 public void testGet02() 107 { 108 String string = params.get("string02", "toto"); 109 assertEquals(string02, string); 110 } 111 112 public void testGet03() 114 { 115 String string = params.get("StringNull", "toto"); 116 assertEquals("toto", string); 117 } 118 119 public void testGet04() 120 { 121 String string = params.get("stringEmpty", "toto"); 122 assertEquals(stringEmpty, string); 123 } 124 125 public void testGet05() 127 { 128 String string = params.get(null, "toto"); 129 assertEquals("toto", string); 130 } 131 132 public void testGetBoolean01() 133 { 134 boolean bool = params.getBoolean("booltrue01", false); 135 assertEquals(true, bool); 136 } 137 138 public void testGetBoolean02() 139 { 140 boolean bool = params.getBoolean("booltrue02", false); 141 assertEquals(true, bool); 142 } 143 144 public void testGetBoolean03() 145 { 146 boolean bool = params.getBoolean("booltrue03", false); 147 assertEquals(true, bool); 148 } 149 150 public void testGetBoolean04() 151 { 152 boolean bool = params.getBoolean("boolfalse01", true); 153 assertEquals(false, bool); 154 } 155 156 public void testGetBoolean05() 157 { 158 boolean bool = params.getBoolean("boolfalse02", true); 159 assertEquals(false, bool); 160 } 161 162 public void testGetBoolean06() 163 { 164 boolean bool = params.getBoolean("boolfalse03", true); 165 assertEquals(false, bool); 166 } 167 168 public void testGetBoolean07() 169 { 170 boolean bool = params.getBoolean(null, true); 171 assertEquals(true, bool); 172 } 173 174 public void testGetBoolean08() 175 { 176 boolean bool = params.getBoolean(null, false); 177 assertEquals(false, bool); 178 } 179 180 public void testGetBoolean09() 181 { 182 boolean bool = params.getBoolean("stringEmpty", true); 183 assertEquals(true, bool); 184 } 185 186 public void testGetBoolean10() 187 { 188 boolean bool = params.getBoolean("stringEmpty", false); 189 assertEquals(false, bool); 190 } 191 192 public void testGetBoolean11() 193 { 194 boolean bool = params.getBoolean("stringNull", true); 195 assertEquals(true, bool); 196 } 197 198 public void testGetBoolean12() 199 { 200 boolean bool = params.getBoolean("stringNull", false); 201 assertEquals(false, bool); 202 } 203 204 public void testGetBooleanObject01() 205 { 206 Boolean bool = params.getBooleanObject("booltrue01", false); 207 assertEquals(Boolean.TRUE, bool); 208 } 209 210 public void testGetBooleanObject02() 211 { 212 Boolean bool = params.getBooleanObject("booltrue02", false); 213 assertEquals(Boolean.TRUE, bool); 214 } 215 216 public void testGetBooleanObject03() 217 { 218 Boolean bool = params.getBooleanObject("booltrue03", false); 219 assertEquals(Boolean.TRUE, bool); 220 } 221 222 public void testGetBooleanObject04() 223 { 224 Boolean bool = params.getBooleanObject("boolfalse01", true); 225 assertEquals(Boolean.FALSE, bool); 226 } 227 228 public void testGetBooleanObject05() 229 { 230 Boolean bool = params.getBooleanObject("boolfalse02", true); 231 assertEquals(Boolean.FALSE, bool); 232 } 233 234 public void testGetBooleanObject06() 235 { 236 Boolean bool = params.getBooleanObject("boolfalse03", true); 237 assertEquals(Boolean.FALSE, bool); 238 } 239 240 public void testGetBooleanObject07() 241 { 242 Boolean bool = params.getBooleanObject(null, true); 243 assertEquals(Boolean.TRUE, bool); 244 } 245 246 public void testGetBooleanObject08() 247 { 248 Boolean bool = params.getBooleanObject(null, false); 249 assertEquals(Boolean.FALSE, bool); 250 } 251 252 public void testGetBooleanObject09() 253 { 254 Boolean bool = params.getBooleanObject("stringEmpty", true); 255 assertEquals(Boolean.TRUE, bool); 256 } 257 258 public void testGetBooleanObject10() 259 { 260 Boolean bool = params.getBooleanObject("stringEmpty", false); 261 assertEquals(Boolean.FALSE, bool); 262 } 263 264 public void testGetBooleanObject11() 265 { 266 Boolean bool = params.getBooleanObject("stringNull", true); 267 assertEquals(Boolean.TRUE, bool); 268 } 269 270 public void testGetBooleanObject12() 271 { 272 Boolean bool = params.getBooleanObject("stringNull", false); 273 assertEquals(Boolean.FALSE, bool); 274 } 275 276 public void testGetByteArray01() 277 { 278 byte[] bytes = params.getByteArray("string01", "toto".getBytes()); 279 assertEquals(string01, new String (bytes)); 280 } 281 282 public void testGetByteArray02() 283 { 284 byte[] bytes = params.getByteArray("string02", "toto".getBytes()); 285 assertEquals(string02, new String (bytes)); 286 } 287 288 public void testGetByteArray03() 289 { 290 byte[] bytes = params.getByteArray(null, "toto".getBytes()); 291 assertEquals("toto", new String (bytes)); 292 } 293 294 public void testGetByteArray04() 295 { 296 byte[] bytes = params.getByteArray(stringEmpty, "toto".getBytes()); 297 assertEquals("toto", new String (bytes)); 298 } 299 300 public void testGetByteArray05() 301 { 302 byte[] bytes = params.getByteArray(stringNull, "toto".getBytes()); 303 assertEquals("toto", new String (bytes)); 304 } 305 306 public void testGetDouble01() 307 { 308 double value = params.getDouble("double01", 2.2); 309 assertEquals(Math.PI, value, 0); 310 } 311 312 public void testGetDouble02() 313 { 314 double value = params.getDouble("double02", 2.2); 315 assertEquals(Math.PI, value, 0); 316 } 317 318 public void testGetDouble03() 319 { 320 double value = params.getDouble("double03", 2.2); 321 assertEquals(3.14, value, 0); 322 } 323 324 public void testGetDouble04() 325 { 326 double value = params.getDouble("double04", 2.2); 327 assertEquals(3, value, 0); 328 } 329 330 public void testGetDouble05() 331 { 332 double value = params.getDouble(null, 2.2); 333 assertEquals(2.2, value, 0); 334 } 335 336 public void testGetDouble06() 337 { 338 double value = params.getDouble("stringEmpty", 2.2); 339 assertEquals(2.2, value, 0); 340 } 341 342 public void testGetDouble07() 343 { 344 double value = params.getDouble("stringNull", 2.2); 345 assertEquals(2.2, value, 0); 346 } 347 348 public void testGetDoubleObject01() 349 { 350 Double value = params.getDoubleObject("double01", 2.2); 351 assertEquals(new Double (Math.PI), value); 352 } 353 354 public void testGetDoubleObject02() 355 { 356 Double value = params.getDoubleObject("double02", 2.2); 357 assertEquals(new Double (Math.PI), value); 358 } 359 360 public void testGetDoubleObject03() 361 { 362 Double value = params.getDoubleObject("double03", 2.2); 363 assertEquals(new Double (3.14), value); 364 } 365 366 public void testGetDoubleObject04() 367 { 368 Double value = params.getDoubleObject("double04", 2.2); 369 assertEquals(new Double (3), value); 370 } 371 372 public void testGetDoubleObject05() 373 { 374 Double value = params.getDoubleObject(null, 2.2); 375 assertEquals(new Double (2.2), value); 376 } 377 378 public void testGetDoubleObject06() 379 { 380 Double value = params.getDoubleObject("stringEmpty", 2.2); 381 assertEquals(new Double (2.2), value); 382 } 383 384 public void testGetDoubleObject07() 385 { 386 Double value = params.getDoubleObject("stringNull", 2.2); 387 assertEquals(new Double (2.2), value); 388 } 389 390 public void testGetFloat01() 391 { 392 float value = params.getFloat("float01", 2.2f); 393 assertEquals(3.14f, value, 0); 394 } 395 396 public void testGetFloat02() 397 { 398 float value = params.getFloat("float02", 2.2f); 399 assertEquals(3.14f, value, 0); 400 } 401 402 public void testGetFloat03() 403 { 404 float value = params.getFloat("float03", 2.2f); 405 assertEquals(3.14f, value, 0); 406 } 407 408 public void testGetFloat04() 409 { 410 float value = params.getFloat("float04", 2.2f); 411 assertEquals(3f, value, 0); 412 } 413 414 public void testGetFloat05() 415 { 416 float value = params.getFloat("double01", 2.2f); 417 assertEquals(3.1415927f, value, 0); 418 } 419 420 public void testGetFloat06() 421 { 422 float value = params.getFloat(null, 2.2f); 423 assertEquals(2.2f, value, 0); 424 } 425 426 public void testGetFloat07() 427 { 428 float value = params.getFloat(stringEmpty, 2.2f); 429 assertEquals(2.2f, value, 0); 430 } 431 432 public void testGetFloat08() 433 { 434 float value = params.getFloat(stringNull, 2.2f); 435 assertEquals(2.2f, value, 0); 436 } 437 438 public void testGetFloatObject01() 439 { 440 Float value = params.getFloatObject("float01", 2.2f); 441 assertEquals(new Float (3.14f), value); 442 } 443 444 public void testGetFloatObject02() 445 { 446 Float value = params.getFloatObject("float02", 2.2f); 447 assertEquals(new Float (3.14f), value); 448 } 449 450 public void testGetFloatObject03() 451 { 452 Float value = params.getFloatObject("float03", 2.2f); 453 assertEquals(new Float (3.14f), value); 454 } 455 456 public void testGetFloatObject04() 457 { 458 Float value = params.getFloatObject("float04", 2.2f); 459 assertEquals(new Float (3f), value); 460 } 461 462 public void testGetFloatObject05() 463 { 464 Float value = params.getFloatObject("double01", 2.2f); 465 assertEquals(new Float (3.1415927f), value); 466 } 467 468 public void testGetFloatObject06() 469 { 470 Float value = params.getFloatObject(null, 2.2f); 471 assertEquals(new Float (2.2f), value); 472 } 473 474 public void testGetFloatObject07() 475 { 476 Float value = params.getFloatObject(stringEmpty, 2.2f); 477 assertEquals(new Float (2.2f), value); 478 } 479 480 public void testGetFloatObject08() 481 { 482 Float value = params.getFloatObject(stringNull, 2.2f); 483 assertEquals(new Float (2.2f), value); 484 } 485 486 public void testGetInt01() 487 { 488 int value = params.getInt("int01", 9); 489 assertEquals(10, value); 490 } 491 492 public void testGetInt02() 493 { 494 int value = params.getInt("int01", 9); 495 assertEquals(10, value); 496 } 497 498 public void testGetInt03() 499 { 500 int value = params.getInt("int01", 9); 501 assertEquals(10, value); 502 } 503 504 public void testGetInt04() 505 { 506 int value = params.getInt("float01", 9); 507 assertEquals(9, value); 508 } 509 510 public void testGetInt05() 511 { 512 int value = params.getInt(null, 9); 513 assertEquals(9, value); 514 } 515 516 public void testGetInt06() 517 { 518 int value = params.getInt("stringEmpty", 9); 519 assertEquals(9, value); 520 } 521 522 public void testGetInt07() 523 { 524 int value = params.getInt("stringNull", 9); 525 assertEquals(9, value); 526 } 527 528 public void testGetIntObject01() 529 { 530 Integer value = params.getIntObject("int01", 9); 531 assertEquals(new Integer (10), value); 532 } 533 534 public void testGetIntObject02() 535 { 536 Integer value = params.getIntObject("int01", 9); 537 assertEquals(new Integer (10), value); 538 } 539 540 public void testGetIntObject03() 541 { 542 Integer value = params.getIntObject("int01", 9); 543 assertEquals(new Integer (10), value); 544 } 545 546 public void testGetIntObject04() 547 { 548 Integer value = params.getIntObject("float01", 9); 549 assertEquals(new Integer (9), value); 550 } 551 552 public void testGetIntObject05() 553 { 554 Integer value = params.getIntObject(null, 9); 555 assertEquals(new Integer (9), value); 556 } 557 558 public void testGetIntObject06() 559 { 560 Integer value = params.getIntObject("stringEmpty", 9); 561 assertEquals(new Integer (9), value); 562 } 563 564 public void testGetIntObject07() 565 { 566 Integer value = params.getIntObject("stringNull", 9); 567 assertEquals(new Integer (9), value); 568 } 569 570 public void testGetShort01() 571 { 572 short value = params.getShort("int01", (short) 9); 573 assertEquals(10, value); 574 } 575 576 public void testGetShort02() 577 { 578 short value = params.getShort("int01", (short) 9); 579 assertEquals(10, value); 580 } 581 582 public void testGetShort03() 583 { 584 short value = params.getShort("int01", (short) 9); 585 assertEquals(10, value); 586 } 587 588 public void testGetShort04() 589 { 590 short value = params.getShort("float01", (short) 9); 591 assertEquals(9, value); 592 } 593 594 public void testGetShort05() 595 { 596 short value = params.getShort(null, (short) 9); 597 assertEquals(9, value); 598 } 599 600 public void testGetShort06() 601 { 602 short value = params.getShort("stringEmpty", (short) 9); 603 assertEquals(9, value); 604 } 605 606 public void testGetShort07() 607 { 608 short value = params.getShort("stringNull", (short) 9); 609 assertEquals(9, value); 610 } 611 612 public void testGetShortObject01() 613 { 614 Short value = params.getShortObject("int01", (short) 9); 615 assertEquals(new Short ((short) 10), value); 616 } 617 618 public void testGetShortObject02() 619 { 620 Short value = params.getShortObject("int01", (short) 9); 621 assertEquals(new Short ((short) 10), value); 622 } 623 624 public void testGetShortObject03() 625 { 626 Short value = params.getShortObject("int01", (short) 9); 627 assertEquals(new Short ((short) 10), value); 628 } 629 630 public void testGetShortObject04() 631 { 632 Short value = params.getShortObject("float01", (short) 9); 633 assertEquals(new Short ((short) 9), value); 634 } 635 636 public void testGetShortObject05() 637 { 638 Short value = params.getShortObject(null, (short) 9); 639 assertEquals(new Short ((short) 9), value); 640 } 641 642 public void testGetShortObject06() 643 { 644 Short value = params.getShortObject("stringEmpty", (short) 9); 645 assertEquals(new Short ((short) 9), value); 646 } 647 648 public void testGetShortObject07() 649 { 650 Short value = params.getShortObject("stringNull", (short) 9); 651 assertEquals(new Short ((short) 9), value); 652 } 653 654 public void testGetLong01() 655 { 656 long value = params.getLong("long01", 9); 657 assertEquals((new Long (Integer.MAX_VALUE + 10)).longValue(), value); 658 } 659 660 public void testGetLong02() 661 { 662 long value = params.getLong(null, 9); 663 assertEquals(9, value); 664 } 665 666 public void testGetLong03() 667 { 668 long value = params.getLong("stringEmpty", 9); 669 assertEquals(9, value); 670 } 671 672 public void testGetLong04() 673 { 674 long value = params.getLong("stringNull", 9); 675 assertEquals(9, value); 676 } 677 678 public void testGetLongObject01() 679 { 680 Long value = params.getLongObject("long01", 9); 681 assertEquals((new Long (Integer.MAX_VALUE + 10)), value); 682 } 683 684 public void testGetLongObject02() 685 { 686 Long value = params.getLongObject(null, 9); 687 assertEquals(new Long (9), value); 688 } 689 690 public void testGetLongObject03() 691 { 692 Long value = params.getLongObject("stringEmpty", 9); 693 assertEquals(new Long (9), value); 694 } 695 696 public void testGetLongObject04() 697 { 698 Long value = params.getLongObject("stringNull", 9); 699 assertEquals(new Long (9), value); 700 } 701 } 702 703 | Popular Tags |