1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.data.holder.Map; 18 import org.as2lib.data.holder.map.HashMap; 19 import org.as2lib.env.except.IllegalArgumentException; 20 import org.as2lib.env.log.LogSupport; 21 import org.as2lib.env.overload.Overload; 22 import org.as2lib.test.unit.info.*; 23 import org.as2lib.test.unit.ExecutionInfo; 24 import org.as2lib.test.unit.Test; 25 import org.as2lib.test.unit.TestRunner; 26 import org.as2lib.test.unit.TestCaseRunner; 27 import org.as2lib.app.exec.Call; 28 import org.as2lib.app.exec.Executable; 29 import org.as2lib.app.exec.Process; 30 import org.as2lib.util.ObjectUtil; 31 import org.as2lib.test.unit.LoggerTestListener; 32 33 /** 34 * {@code Testcase} is the basic class to extend for unit-tests. 35 * 36 * <p>A {@code TestCase} contains the API to write unit-tests. 37 * 38 * <p>It is handled as an abstract class this means you have to extend it if you 39 * want to work with the system (similar to the most other unit testing systems). 40 * 41 * <p>Example for a simple test: 42 * <code> 43 * import org.as2lib.test.unit.TestCase; 44 * 45 * class MyTestCase extends TestCase {} 46 * </code> 47 * 48 * <p>To execute a {@code TestCase} you just have to call {@code run()}. It logs 49 * automatically with {@link LoggerTestListener}. 50 * 51 * <p>The test will return detailed informations about the executed method. The 52 * method {@code fail} will simply fail the test. 53 * 54 * <p>Example for a test that fails: 55 * <code> 56 * import org.as2lib.test.unit.TestCase; 57 * 58 * class MyTestCase extends TestCase { 59 * public function testOne(Void):Void { 60 * if (1 == 0) { // example to show that fail can be used everywhere. 61 * fail ("Error occured"); 62 * } 63 * } 64 * } 65 * </code> 66 * 67 * <p>Within the "test"-methods you have access to different assert methods. Those 68 * methods fail if a certain condition is given or not and add a information for 69 * the failure to the informations about the execution. 70 * 71 * <p>Example for a assertion: 72 * <code> 73 * import org.as2lib.test.unit.TestCase; 74 * 75 * class MyTestCase extends TestCase { 76 * public function testOne(Void):Void { 77 * assertEquals("1 is not 0", 1, 0); 78 * } 79 * } 80 * </code> 81 * 82 * <p>Supported assert methods are: 83 * <table> 84 * <thead> 85 * <tr> 86 * <th>method name</th> 87 * <th>condition</th> 88 * </tr> 89 * </thead> 90 * <tbody> 91 * <tr> 92 * <th>assertTrue</th> 93 * <td><i>value</i> === true</td> 94 * </tr> 95 * <tr> 96 * <th>assertFalse</th> 97 * <td><i>value</i> === false</td> 98 * </tr> 99 * <tr> 100 * <th>assertEquals</th> 101 * <td>ObjectUtil.compare(<i>a</i>,<i>b</i>);</td> 102 * </tr> 103 * <tr> 104 * <th>assertAlmostEquals</th> 105 * <td>(<i>a</i> < <i>b</i> && <i>a</i>+x > <i>b</i>) || 106 * (<i>a</i> > <i>b</i> && <i>a</i>-x < <i>b</i>)</td> 107 * </tr> 108 * <tr> 109 * <th>assertNotEquals</th> 110 * <td>!ObjectUtil.compare(<i>a</i>,<i>b</i>);</td> 111 * </tr> 112 * <tr> 113 * <th>assertSame</th> 114 * <td><i>a</i> === <i>b</i></td> 115 * </tr> 116 * <tr> 117 * <th>assertNotSame</th> 118 * <td><i>a</i> !== <i>b</i></td> 119 * </tr> 120 * <tr> 121 * <th>assertNull</th> 122 * <td><i>value</i> === null</td> 123 * </tr> 124 * <tr> 125 * <th>assertNotNull</th> 126 * <td><i>value</i> !== null</td> 127 * </tr> 128 * <tr> 129 * <th>assertUndefined</th> 130 * <td><i>value</i> === undefined</td> 131 * </tr> 132 * <tr> 133 * <th>assertNotUndefined</th> 134 * <td><i>value</i> !== undefined</td> 135 * </tr> 136 * <tr> 137 * <th>assertEmpty</th> 138 * <td><i>value</i> == null (equals == undefined)</td> 139 * </tr> 140 * <tr> 141 * <th>assertNotEmpty</th> 142 * <td><i>value</i> != null (equals != undefined)</td> 143 * </tr> 144 * <tr> 145 * <th>assertInfinity</th> 146 * <td><i>value</i> === Infinity</td> 147 * </tr> 148 * <tr> 149 * <th>assertNotInfinity</th> 150 * <td><i>value</i> !== Infinity</td> 151 * </tr> 152 * <tr> 153 * <th>assertThrows</th> 154 * <td><i>call</i>(<i>arguments</i>) throws <i>exception</i></td> 155 * </tr> 156 * <tr> 157 * <th>assertNotThrows</th> 158 * <td><i>call</i>(<i>arguments</i>) doesnt throw <i>exception</i></td> 159 * </tr> 160 * <tr> 161 * <th>assertTypeOf</th> 162 * <td><i>value</i> typeof <i>type</i></td> 163 * </tr> 164 * <tr> 165 * <th>assertInstanceOf</th> 166 * <td><i>value</i> instanceof <i>type</i></td> 167 * </tr> 168 * </tbody> 169 * </table> 170 * 171 * <p>The system will fetch all methods with a name that starts with "test" and 172 * execute them in a new, isolated instance of the {@code TestCase} to prevent 173 * tests inteferences. 174 * 175 * <p>Example for a test with instance properties: 176 * <code> 177 * import org.as2lib.test.unit.TestCase; 178 * 179 * class MyTestCase extends TestCase { 180 * private var a:String; 181 * 182 * private function testOne(Void):Void { 183 * trace(a); // undefined 184 * a = "1"; 185 * trace(a); // 1 186 * } 187 * 188 * private function testTwo(Void):Void { 189 * trace(a); // undefined 190 * a = "1"; 191 * trace(a); // 1 192 * } 193 * } 194 * </code> 195 * 196 * <p>The method {@link #setUp} allows preparing the new instance. 197 * The method {@link #tearDown} allows to clear those preparations. 198 * 199 * <p>Example with {@code setUp} and {@code tearDown}: 200 * <code> 201 * import org.as2lib.test.unit.TestCase; 202 * 203 * class MyTestCase extends TestCase { 204 * 205 * private static var content:String="1"; 206 * 207 * private static function setContent(newContent:String):Void { 208 * content = newContent; 209 * } 210 * 211 * private static function getContent(Void):String { 212 * return content; 213 * } 214 * 215 * private var cache:String; 216 * 217 * private function setUp() { 218 * cache = getContent(); 219 * } 220 * 221 * private function testOne() { 222 * trace(getContent()); // 1 223 * setContent("2"); 224 * trace(getContent()); // 2 225 * } 226 * 227 * private function testTwo() { 228 * trace(getContent()); // 1 229 * setContent("3"); 230 * trace(getContent()); // 3 231 * } 232 * 233 * private function tearDown() { 234 * setContent(cache); 235 * } 236 * } 237 * </code> 238 * 239 * @author Martin Heidegger 240 * @version 2.0 241 * @see org.as2lib.test.unit.TestSuite 242 * @see org.as2lib.test.unit.Test 243 * @see org.as2lib.test.unit.TestRunner 244 */ 245 246 class org.as2lib.test.unit.TestCase extends LogSupport implements Test { 247 248 /* Defaut maximal difference used in {@code assertAlmostEquals}. */ 249 public static var DEFAULT_MAX_DIFF:Number = 1e-10; 250 251 /** All {@code TestRunner}s mapped to classes. */ 252 private static var testRunners:Map = new HashMap(); 253 254 /** 255 * Blocks the collection of 256 * {@code org.as2lib.test.unit.TestSuiteFactory#collectAllTestCases}. 257 * 258 * @return {@code true} to block the collection 259 */ 260 public static function blockCollecting(Void):Boolean { 261 return true; 262 } 263 264 /** 265 * Returns the {@code TestRunner} that applies to this {@code TestCase} instance. 266 * 267 * <p>Its required to execute methods of a Test that this runs in a clean 268 * instance that should not contain any state. To keep one {@code TestRunner} 269 * per class it is necessary to save {@code TestRunner} in a {@code HashMap} 270 * that stores the correct {@code TestCaseRunner} to the {@code TestCase}. 271 * 272 * @param instance instance to fetch the correct {@code TestCaseRunner} 273 * @return {@code TestRunner} that applies to this {@code TestCase} instance 274 */ 275 private static function getClassTestRunner(instance:TestCase):TestCaseRunner { 276 var clazz = instance["__proto__"]; 277 var p:TestCaseRunner = testRunners.get(clazz); 278 if (!p) { 279 p = new TestCaseRunner(instance); 280 testRunners.put(clazz, p); 281 } 282 return p; 283 } 284 285 /* Executor for this testcase. */ 286 private var testRunner:TestCaseRunner; 287 288 /** 289 * Abstract constructor. 290 */ 291 private function TestCase(Void) {} 292 293 /** 294 * Template method to set up the testcase before running a method. 295 * 296 * <p>This method will get called before executing each method in a clean, 297 * new instance. 298 */ 299 public function setUp(Void):Void {} 300 301 /** 302 * Template method to tear down the testcase after running a method. 303 * 304 * <p>This method will get called after the execution of each method of this 305 * testcase. 306 */ 307 public function tearDown(Void):Void {} 308 309 /** 310 * Runs this testcase. 311 * 312 * <p>Runs all methods of this testcase in an new container and logs all its 313 * events. 314 * 315 * @see Test#run 316 * @return {@code TestRunner} to the {@code TestCase} 317 */ 318 public function run(Void):TestRunner { 319 var testRunner:TestRunner = getTestRunner(); 320 testRunner.addListener(LoggerTestListener.getInstance()); 321 testRunner.start(); 322 return testRunner; 323 } 324 325 /** 326 * Returns the {@code TestRunner} that executes this {@code TestCase}. 327 * 328 * @return {@code TestRunner} that executes this {@code TestCase} 329 */ 330 public function getTestRunner(Void):TestRunner { 331 if (!testRunner) { 332 testRunner = getClassTestRunner(this); 333 } 334 return testRunner; 335 } 336 337 /** 338 * Pauses the execution of this testcase. 339 * 340 * <p>This method has been introduces to pause the execution of this method. 341 * The run will not be completed if {@code resume} will not be called! 342 */ 343 private function pause(Void):Void { 344 testRunner.pause(); 345 } 346 347 /** 348 * Resumes the run of this method. 349 * 350 * <p>This method resumes the exeuction of a {@code TestCase} that has been 351 * paused with {@code pause}. 352 */ 353 private function resume(Void):Void { 354 testRunner.resume(); 355 } 356 357 /** 358 * Method to start a subprocess for this process. 359 * 360 * @param process process to start 361 * @param args arguments to be used for the process 362 * @param callBack call to be executed if the execution finishes 363 */ 364 private function startProcess(process:Process, args:Array, callBack:Executable):Void { 365 testRunner.startSubProcess(process, args, callBack); 366 } 367 368 /** 369 * Adds a execution info to the process. 370 * 371 * @param info info to be added 372 * @return {@code false} if the info is a error, else {@code true} 373 */ 374 private function addInfo(info:ExecutionInfo):Boolean { 375 testRunner.addInfo(info); 376 return !info.isFailed(); 377 } 378 379 /** 380 * Simply fails the current Testcase. 381 * 382 * @param message message to the failing of the method 383 */ 384 private function fail(message:String):Void { 385 message = (typeof message == "string") ? message : "<no message applied>"; 386 addInfo(new FailureInfo(message)); 387 } 388 389 /** 390 * @overload #assertTrueWithMessage 391 * @overload #assertTrueWithoutMessage 392 */ 393 private function assertTrue():Boolean { 394 var overload:Overload = new Overload(this); 395 overload.addHandler([String, Object], assertTrueWithMessage); 396 overload.addHandler([Object], assertTrueWithoutMessage); 397 overload.addHandler([], assertTrueWithoutMessage); 398 return overload.forward(arguments); 399 } 400 401 /** 402 * Asserts if the passed-in {@code val} is {@code true}. 403 * 404 * @param val boolean that should be {@code true}. 405 * @return {@code true} if no error occured else {@code false} 406 * @see #assertFalse 407 * @see #assertTrue 408 * @see #assertTrueWithMessage 409 */ 410 private function assertTrueWithoutMessage(val:Boolean):Boolean { 411 return assertTrueWithMessage("", val); 412 } 413 414 /** 415 * Asserts if the passed-in {@code val} is {@code true} or fails with the 416 * passed-in {@code message}. 417 * 418 * <p>This methods asserts the same like {@code assertTrueWithoutMessage} 419 * but it adds a message to the failure. 420 * 421 * @param message message to be provided if the assertion fails 422 * @param val boolean that should be {@code true} 423 * @return {@code true} if no error occured else {@code false} 424 * @see #assertFalse 425 * @see #assertTrue 426 * @see #assertTrueWithoutMessage 427 */ 428 private function assertTrueWithMessage(message:String, val:Boolean):Boolean { 429 return addInfo(new AssertTrueInfo(message, val)); 430 } 431 432 /** 433 * @overload #assertFalseWithMessage 434 * @overload #assertFalseWithoutMessage 435 */ 436 private function assertFalse():Boolean { 437 var overload:Overload = new Overload(this); 438 overload.addHandler([String, Object], assertFalseWithMessage); 439 overload.addHandler([Object], assertFalseWithoutMessage); 440 overload.addHandler([], assertFalseWithoutMessage); 441 return overload.forward(arguments); 442 } 443 444 /** 445 * Asserts if the passed-in {@code val} is {@code false} else it fails. 446 * 447 * @param val boolean that should be {@code false} 448 * @return {@code true} if no error occured else {@code false} 449 * @see #assertTrue 450 * @see #assertFalse 451 * @see #assertFalseWithMessage 452 */ 453 private function assertFalseWithoutMessage(val:Boolean):Boolean { 454 return assertFalseWithMessage("", val); 455 } 456 457 /** 458 * Asserts if the passed-in {@code val} is {@code false} or fails with the 459 * passed-in {@code message}. 460 * 461 * <p>This method asserts the same like {@code assertFalseWithoutMessage} 462 * but it adds a message to the failure. 463 * 464 * @param message message to be provided if the assertion fails 465 * @param val boolean that should be {@code false} 466 * @return {@code true} if no error occured else {@code false} 467 * @see #assertTrue 468 * @see #assertFalse 469 * @see #assertFalseWithoutMessage 470 */ 471 private function assertFalseWithMessage(message:String, val:Boolean):Boolean { 472 return addInfo(new AssertFalseInfo(message, val)); 473 } 474 475 /** 476 * @overload #assertEqualsWithMessage 477 * @overload #assertEqualsWithoutMessage 478 */ 479 private function assertEquals():Boolean { 480 var overload:Overload = new Overload(this); 481 overload.addHandler([String, Object, Object], assertEqualsWithMessage); 482 overload.addHandler([String, Object], assertEqualsWithMessage); 483 overload.addHandler([Object, Object], assertEqualsWithoutMessage); 484 overload.addHandler([String, String], assertEqualsWithoutMessage); 485 overload.addHandler([Object], assertEqualsWithoutMessage); 486 overload.addHandler([], assertEqualsWithoutMessage); 487 return overload.forward(arguments); 488 } 489 490 /** 491 * Asserts if the two passed-in parameters are equal. 492 * 493 * <p>This method compares two variables by {@link org.as2lib.util.ObjectUtil#compare}. 494 * 495 * <p>In contrast to {@code assertSame} that compares by "===" if both 496 * are exactly the same this method compares the value of the two 497 * parameters. 498 * 499 * @param val parameter that should be compared 500 * @param compareTo parameter to compare with {@code val} 501 * @return {@code true} if no error occured else {@code false} 502 * @see #assertSame 503 * @see #assertNotEquals 504 * @see #assertEquals 505 * @see #assertEqualsWithMessage 506 */ 507 private function assertEqualsWithoutMessage(val, compareTo):Boolean { 508 return assertEqualsWithMessage("", val, compareTo); 509 } 510 511 /** 512 * Asserts if the two passed-in parameters are equal or fails with the passed-in 513 * {@code message}. 514 * 515 * <p>This method asserts the same like {@code assertEqualsWithoutMessage} 516 * but it adds a message to the failure. 517 * 518 * @param message message to be provided if the assertion fails 519 * @param val parameter that should be compared 520 * @param compareTo parameter to compare with {@code val} 521 * @return {@code true} if no error occured else {@code false} 522 * @see #assertSame 523 * @see #assertNotEquals 524 * @see #assertEquals 525 * @see #assertEqualsWithoutMessage 526 */ 527 private function assertEqualsWithMessage(message:String, val, compareTo):Boolean { 528 return addInfo(new AssertEqualsInfo(message, val, compareTo)); 529 } 530 531 /** 532 * @overload #assertAlmostEqualsWithMessageWithMaxDiff 533 * @overload #assertAlmostEqualsWithoutMessageWithMaxDiff 534 * @overload #assertAlmostEqualsWithMessageWithoutMaxDiff 535 * @overload #assertAlmostEqualsWithoutMessageWithoutMaxDiff 536 */ 537 private function assertAlmostEquals():Boolean { 538 var overload:Overload = new Overload(this); 539 overload.addHandler( 540 [String, Number, Number, Number], 541 assertAlmostEqualsWithMessageWithMaxDiff); 542 overload.addHandler( 543 [String, Number, Number], 544 assertAlmostEqualsWithMessageWithoutMaxDiff); 545 overload.addHandler( 546 [Number, Number, Number], 547 assertAlmostEqualsWithoutMessageWithMaxDiff); 548 overload.addHandler( 549 [Number, Number], 550 assertAlmostEqualsWithoutMessageWithoutMaxDiff); 551 return overload.forward(arguments); 552 } 553 554 /** 555 * Asserts if the two passed-in numbers are the almost the same. 556 * 557 * <p>This method compares two numbers by using the unsharpening buffer 558 * {@link #DEFAULT_MAX_DIFF}. 559 * 560 * @param val {@code number} to be compared 561 * @param compareTo {@code number} to compare with {@code val} 562 * @return {@code true} if no error occured else {@code false} 563 * @see #assertSame 564 * @see #assertEquals 565 * @see #assertAlmostEquals 566 */ 567 private function assertAlmostEqualsWithoutMessageWithoutMaxDiff(val:Number, 568 compareTo:Number):Boolean { 569 return assertAlmostEqualsWithMessageWithMaxDiff("", val, compareTo, 570 DEFAULT_MAX_DIFF); 571 } 572 573 /** 574 * Asserts if the two passed-in numbers are the almost the same or fails 575 * with the passed-in {@code message}. 576 * 577 * <p>This method asserts the same like 578 * {@code assertAlmostEqualsWithoutMessageWithoutMaxDiff} but it adds a message 579 * to the failure. 580 * 581 * @param message message to be provided if the assertion fails 582 * @param val {@code number} to be compared 583 * @param compareTo {@code number} to compare with {@code val} 584 * @return {@code true} if no error occured else {@code false} 585 * @see #assertSame 586 * @see #assertEquals 587 * @see #assertAlmostEquals 588 */ 589 private function assertAlmostEqualsWithMessageWithoutMaxDiff(message:String, 590 val:Number, compareTo:Number):Boolean { 591 return assertAlmostEqualsWithMessageWithMaxDiff(message, val, compareTo, 592 DEFAULT_MAX_DIFF); 593 } 594 595 /** 596 * Asserts if the two passed-in numbers are the almost the same. 597 * 598 * <p>This method compares two numbers by using the passed-in unsharpening buffer 599 * {@code maxDiff}. 600 * 601 * @param val {@code number} to be compared 602 * @param compareTo {@code number} to compare with {@code val} 603 * @param maxDiff maximum difference between the passed-in numbers 604 * @return {@code true} if no error occured else {@code false} 605 * @see #assertSame 606 * @see #assertEquals 607 * @see #assertAlmostEquals 608 */ 609 private function assertAlmostEqualsWithoutMessageWithMaxDiff(val:Number, 610 compareTo:Number, maxDiff:Number):Boolean { 611 return assertAlmostEqualsWithMessageWithMaxDiff("", val, compareTo, maxDiff); 612 } 613 614 /** 615 * Asserts if the two passed-in numbers are the almost the same or fails 616 * with the passed-in {@code message}. 617 * 618 * <p>This method asserts the same like {@code assertAlmostEqualsWithoutMessage} 619 * but it adds a message to the failure. 620 * 621 * @param message message to be provided if the assertion fails 622 * @param val number1 to be compared. 623 * @param compareTo number2 to compare with val. 624 * @param maxDiff max. difference between those two numbers. 625 * @return {@code true} if no error occured else {@code false} 626 * @see #assertSame 627 * @see #assertEquals 628 * @see #assertAlmostEquals 629 */ 630 private function assertAlmostEqualsWithMessageWithMaxDiff(message:String, 631 val:Number, compareTo:Number, maxDiff:Number):Boolean { 632 return addInfo(new AssertAlmostEqualsInfo(message, val, compareTo, maxDiff)); 633 } 634 635 /** 636 * @overload #assertNotEqualsWithMessage 637 * @overload #assertNotEqualsWithoutMessage 638 */ 639 private function assertNotEquals():Boolean { 640 var overload:Overload = new Overload(this); 641 overload.addHandler([String, Object, Object], assertNotEqualsWithMessage); 642 overload.addHandler([String, Object], assertNotEqualsWithMessage); 643 overload.addHandler([Object, Object], assertNotEqualsWithoutMessage); 644 overload.addHandler([String, String], assertNotEqualsWithoutMessage); 645 overload.addHandler([Object], assertNotEqualsWithoutMessage); 646 overload.addHandler([], assertNotEqualsWithoutMessage); 647 return overload.forward(arguments); 648 } 649 650 /** 651 * Asserts if the two passed-in parameters are not equal. 652 * 653 * <p>This method compares two variables by {@link org.as2lib.util.ObjectUtil#compare} 654 * and fails if it returns {@code true}. 655 * 656 * <p>In contrast to {@code assertNotSame} that compares by "!==" if both 657 * are exactly the same this method compares the value of the two 658 * parameters. 659 * 660 * @param val parameter that should be compared 661 * @param compareTo parameter to compare with {@code val} 662 * @return {@code true} if no error occured else {@code false} 663 * @see #assertNotSame 664 * @see #assertEquals 665 * @see #assertNotEquals 666 * @see #assertNotEqualsWithMessage 667 */ 668 private function assertNotEqualsWithoutMessage(val, compareTo):Boolean { 669 return assertNotEqualsWithMessage("", val, compareTo); 670 } 671 672 /** 673 * Asserts if the two passed-in parameters are not equal of fails with the passed-in 674 * {@code message}. 675 * 676 * <p>This method asserts the same like {@code assertNotEqualsWithoutMessage} 677 * but it adds a message to the failure. 678 * 679 * @param message message to be provided if the assertion fails 680 * @param val parameter that should be compared 681 * @param compareTo parameter to compare with {@code val} 682 * @return {@code true} if no error occured else {@code false} 683 * @see #assertNotSame 684 * @see #assertEquals 685 * @see #assertNotEquals 686 * @see #assertNotEqualsWithoutMessage 687 */ 688 private function assertNotEqualsWithMessage(message:String, val, compareTo):Boolean { 689 return addInfo(new AssertNotEqualsInfo(message, val, compareTo)); 690 } 691 692 /** 693 * @overload #assertSameWithMessage 694 * @overload #assertSameWithoutMessage 695 */ 696 private function assertSame():Boolean { 697 var overload:Overload = new Overload(this); 698 overload.addHandler([String, Object, Object], assertSameWithMessage); 699 overload.addHandler([String, Object], assertSameWithMessage); 700 overload.addHandler([Object, Object], assertSameWithoutMessage); 701 overload.addHandler([String, String], assertSameWithoutMessage); 702 overload.addHandler([Object], assertSameWithoutMessage); 703 overload.addHandler([], assertSameWithoutMessage); 704 return overload.forward(arguments); 705 } 706 707 /** 708 * Asserts if the two passed-in parameters are the same. 709 * 710 * <p>This method compares two variables by "===". 711 * 712 * <p>In contrast to {@code assertEquals} that compares by {@code ObjectUtil.compare} 713 * the value this method compares if both parameters are exactly the same. 714 * 715 * @param val parameter that should be compared 716 * @param compareTo parameter to compare with {@code val} 717 * @return {@code true} if no error occured else {@code false} 718 * @see #assertNotSame 719 * @see #assertEquals 720 * @see #assertSame 721 * @see #assertSameWithMessage 722 */ 723 private function assertSameWithoutMessage(val, compareTo):Boolean { 724 return assertSameWithMessage("", val, compareTo); 725 } 726 727 /** 728 * Asserts if the two passed-in parameters are the same or fails with the passed-in 729 * {@code message}. 730 * 731 * <p>This method asserts the same like {@code assertSameWithoutMessage} 732 * but it adds a message to the failure. 733 * 734 * @param message message to be provided if the assertion fails 735 * @param val parameter that should be compared 736 * @param compareTo parameter to compare with {@code val} 737 * @return {@code true} if no error occured else {@code false} 738 * @see #assertNotSame 739 * @see #assertEquals 740 * @see #assertSame 741 * @see #assertSameWithoutMessage 742 */ 743 private function assertSameWithMessage(message:String, val, compareTo):Boolean { 744 return addInfo(new AssertSameInfo(message, val, compareTo)); 745 } 746 747 /** 748 * @overload #assertNotSameWithMessage 749 * @overload #assertNotSameWithoutMessage 750 */ 751 private function assertNotSame():Boolean { 752 var overload:Overload = new Overload(this); 753 overload.addHandler([String, Object, Object], assertNotSameWithMessage); 754 overload.addHandler([String, Object], assertNotSameWithMessage); 755 overload.addHandler([Object, Object], assertNotSameWithoutMessage); 756 overload.addHandler([String, String], assertNotSameWithoutMessage); 757 overload.addHandler([Object], assertNotSameWithoutMessage); 758 overload.addHandler([], assertNotSameWithoutMessage); 759 return overload.forward(arguments); 760 } 761 762 /** 763 * Asserts if the two passed-in parameters are the not same. 764 * 765 * <p>This method compares two variables by "!==". 766 * 767 * <p>In contrast to {@code assertNotEquals} that compares by !{@code ObjectUtil.compare} 768 * the value this method compares if both parameters are not exactly the same. 769 * 770 * @param val parameter that should be compared 771 * @param compareTo parameter to compare with {@code val} 772 * @return {@code true} if no error occured else {@code false} 773 * @see #assertSame 774 * @see #assertNotEquals 775 * @see #assertNotSame 776 * @see #assertNotSameWithMessage 777 */ 778 private function assertNotSameWithoutMessage(val, compareTo):Boolean { 779 return assertNotSameWithMessage("", val, compareTo); 780 } 781 782 /** 783 * Asserts if the two passed-in parameters are the not same or fails with the 784 * passed-in {@code message}. 785 * 786 * <p>This method asserts the same like {@code assertNotSameWithoutMessage} 787 * but it adds a message to the failure. 788 * 789 * @param message message to be provided if the assertion fails 790 * @param val parameter that should be compared 791 * @param compareTo parameter to compare with {@code val} 792 * @return {@code true} if no error occured else {@code false} 793 * @see #assertSame 794 * @see #assertNotEquals 795 * @see #assertNotSame 796 * @see #assertNotSameWithoutMessage 797 */ 798 private function assertNotSameWithMessage(message:String, val, compareTo):Boolean { 799 return addInfo(new AssertNotSameInfo(message, val, compareTo)); 800 } 801 802 /** 803 * @overload #assertNullWithMessage 804 * @overload #assertNullWithoutMessage 805 */ 806 private function assertNull():Boolean { 807 var overload:Overload = new Overload(this); 808 overload.addHandler([String, Object], assertNullWithMessage); 809 overload.addHandler([Object], assertNullWithoutMessage); 810 overload.addHandler([], assertNullWithoutMessage); 811 return overload.forward(arguments); 812 } 813 814 /** 815 * Asserts if the passed-in {@code val} is (===) {@code null}. 816 * 817 * @param val parameter that should be {@code null} 818 * @return {@code true} if no error occured else {@code false} 819 * @see #assertNotNull 820 * @see #assertUndefined 821 * @see #assertEmpty 822 * @see #assertNull 823 * @see #assertNullWithMessage 824 */ 825 private function assertNullWithoutMessage(val):Boolean { 826 return assertNullWithMessage("", val); 827 } 828 829 /** 830 * Asserts if the passed-in {@code val} is (===) {@code null} or fails with 831 * the passed-in {@code message}. 832 * 833 * <p>This method asserts the same like {@code assertNullWithoutMessage} 834 * but it adds a message to the failure. 835 * 836 * @param message message to be provided if the assertion fails 837 * @param val parameter that should be {@code null} 838 * @return {@code true} if no error occured else {@code false} 839 * @see #assertNotNull 840 * @see #assertUndefined 841 * @see #assertEmpty 842 * @see #assertNull 843 * @see #assertNullWithoutMessage 844 */ 845 private function assertNullWithMessage(message:String, val):Boolean { 846 return addInfo(new AssertNullInfo(message, val)); 847 } 848 849 /** 850 * @overload #assertNotNullWithMessage 851 * @overload #assertNotNullWithoutMessage 852 */ 853 private function assertNotNull():Boolean { 854 var overload:Overload = new Overload(this); 855 overload.addHandler([String, Object], assertNotNullWithMessage); 856 overload.addHandler([Object], assertNotNullWithoutMessage); 857 overload.addHandler([], assertNotNullWithoutMessage); 858 return overload.forward(arguments); 859 } 860 861 /** 862 * Asserts if the passed-in {@code val} is not (!==) {@code null}. 863 * 864 * @param val parameter that should not be {@code null} 865 * @return {@code true} if no error occured else {@code false} 866 * @see #assertNull 867 * @see #assertNotUndefined 868 * @see #assertNotEmpty 869 * @see #assertNotNull 870 * @see #assertNotNullWithMessage 871 */ 872 private function assertNotNullWithoutMessage(val):Boolean { 873 return assertNotNullWithMessage("", val); 874 } 875 876 /** 877 * Asserts if the passed-in {@code val} is not (!==) {@code null} or fails with 878 * the passed-in {@code message}. 879 * 880 * <p>This method asserts the same like {@code assertNotNullWithoutMessage} 881 * but it adds a message to the failure. 882 * 883 * @param message message to be provided if the assertion fails 884 * @param val parameter that should not be {@code null} 885 * @return {@code true} if no error occured else {@code false} 886 * @see #assertNull 887 * @see #assertNotUndefined 888 * @see #assertNotEmpty 889 * @see #assertNotNull 890 * @see #assertNotNullWithoutMessage 891 */ 892 private function assertNotNullWithMessage(message:String, val):Boolean { 893 return addInfo(new AssertNotNullInfo(message, val)); 894 } 895 896 /** 897 * @overload #assertUndefinedWithMessage 898 * @overload #assertUndefinedWithoutMessage 899 */ 900 private function assertUndefined():Boolean { 901 var overload:Overload = new Overload(this); 902 overload.addHandler([String, Object], assertUndefinedWithMessage); 903 overload.addHandler([Object], assertUndefinedWithoutMessage); 904 overload.addHandler([], assertUndefinedWithoutMessage); 905 return overload.forward(arguments); 906 } 907 908 /** 909 * Asserts if the passed-in {@code val} is (===) {@code undefined}. 910 * 911 * @param val parameter that should be {@code undefined} 912 * @return {@code true} if no error occured else {@code false} 913 * @see #assertNotUndefined 914 * @see #assertNull 915 * @see #assertEmpty 916 * @see #assertUndefined 917 * @see #assertUndefinedWithMessage 918 */ 919 private function assertUndefinedWithoutMessage(val):Boolean { 920 return assertUndefinedWithMessage("", val); 921 } 922 923 /** 924 * Asserts if the passed-in {@code val} is (===) {@code undefined} or fails 925 * with the passed-in {@code message}. 926 * 927 * <p>This method asserts the same like {@code assertUndefinedWithoutMessage} 928 * but it adds a message to the failure. 929 * 930 * @param message message to be provided if the assertion fails 931 * @param val parameter that should be {@code undefined} 932 * @return {@code true} if no error occured else {@code false} 933 * @see #assertNotUndefined 934 * @see #assertNull 935 * @see #assertEmpty 936 * @see #assertUndefined 937 * @see #assertUndefinedWithoutMessage 938 */ 939 private function assertUndefinedWithMessage(message:String, val):Boolean { 940 return addInfo(new AssertUndefinedInfo(message, val)); 941 } 942 943 /** 944 * @overload #assertNotUndefinedWithMessage 945 * @overload #assertNotUndefinedWithoutMessage 946 */ 947 private function assertNotUndefined():Boolean { 948 var overload:Overload = new Overload(this); 949 overload.addHandler([String, Object], assertNotUndefinedWithMessage); 950 overload.addHandler([Object], assertNotUndefinedWithoutMessage); 951 overload.addHandler([], assertNotUndefinedWithoutMessage); 952 return overload.forward(arguments); 953 } 954 955 /** 956 * Asserts if the passed-in {@code val} is not (!==) {@code undefined}. 957 * 958 * @param val parameter that should not be {@code undefined} 959 * @return {@code true} if no error occured else {@code false} 960 * @see #assertUndefined 961 * @see #assertNotNull 962 * @see #assertNotEmpty 963 * @see #assertNotUndefined 964 * @see #assertNotUndefinedWithMessage 965 */ 966 private function assertNotUndefinedWithoutMessage(val):Boolean { 967 return assertNotUndefined("", val); 968 } 969 970 /** 971 * Asserts if the passed-in {@code val} is not (!==) {@code undefined} or fails 972 * with the passed-in {@code message}. 973 * 974 * <p>This method asserts the same like {@code assertNotUndefinedWithoutMessage} 975 * but it adds a message to the failure. 976 * 977 * @param message message to be provided if the assertion fails 978 * @param val parameter that should not be {@code undefined} 979 * @return {@code true} if no error occured else {@code false} 980 * @see #assertUndefined 981 * @see #assertNotNull 982 * @see #assertNotEmpty 983 * @see #assertNotUndefined 984 * @see #assertNotUndefinedWithoutMessage 985 */ 986 private function assertNotUndefinedWithMessage(message:String, val):Boolean { 987 return addInfo(new AssertNotUndefinedInfo(message, val)); 988 } 989 990 /** 991 * @overload #assertInfinityWithMessage 992 * @overload #assertInfinityWithoutMessage 993 */ 994 private function assertInfinity():Boolean { 995 var overload:Overload = new Overload(this); 996 overload.addHandler([String, Object], assertInfinityWithMessage); 997 overload.addHandler([Object], assertInfinityWithoutMessage); 998 overload.addHandler([], assertInfinityWithoutMessage); 999 return overload.forward(arguments); 1000 } 1001 1002 /** 1003 * Asserts if the passed-in {@code val} is (===) {@code Infinity}. 1004 * 1005 * @param val parameter that should be {@code Infinity} 1006 * @return {@code true} if no error occured else {@code false} 1007 * @see #assertNotInfinity 1008 * @see #assertInfinity 1009 * @see #assertInfinityWithMessage 1010 */ 1011 private function assertInfinityWithoutMessage(val):Boolean { 1012 return assertInfinityWithMessage("", val); 1013 } 1014 1015 /** 1016 * Asserts if the passed-in {@code val} is (===) {@code Infinity} or fails 1017 * with the passed-in {@code message}. 1018 * 1019 * <p>This method asserts the same like {@code assertInfinityWithoutMessage} 1020 * but it adds a message to the failure. 1021 * 1022 * @param message message to be provided if the assertion fails 1023 * @param val parameter that should be {@code Infinity} 1024 * @return {@code true} if no error occured else {@code false} 1025 * @see #assertNotInfinity 1026 * @see #assertInfinity 1027 * @see #assertInfinityWithoutMessage 1028 */ 1029 private function assertInfinityWithMessage(message:String, val):Boolean { 1030 return addInfo(new AssertInfinityInfo(message, val)); 1031 } 1032 1033 /** 1034 * @overload #assertNotInfinityWithMessage 1035 * @overload #assertNotInfinityWithoutMessage 1036 */ 1037 private function assertNotInfinity():Boolean { 1038 var overload:Overload = new Overload(this); 1039 overload.addHandler([String, Object], assertNotInfinityWithMessage); 1040 overload.addHandler([Object], assertNotInfinityWithoutMessage); 1041 overload.addHandler([], assertNotInfinityWithoutMessage); 1042 return overload.forward(arguments); 1043 } 1044 1045 /** 1046 * Asserts if the passed-in {@code val} is not (!==) {@code Infinity}. 1047 * 1048 * @param val parameter that should not be {@code Infinity} 1049 * @return {@code true} if no error occured else {@code false} 1050 * @see #assertInfinity 1051 * @see #assertNotInfinity 1052 * @see #assertNotInfinityWithMessage 1053 */ 1054 private function assertNotInfinityWithoutMessage(val):Boolean { 1055 return assertNotInfinityWithMessage("", val); 1056 } 1057 1058 /** 1059 * Asserts if the passed-in {@code val} is not (!==) {@code Infinity} or fails 1060 * with the passed-in {@code message}. 1061 * 1062 * <p>This method asserts the same like {@code assertInfinityWithoutMessage} 1063 * but it adds a message to the failure. 1064 * 1065 * @param message message to be provided if the assertion fails 1066 * @param val parameter that should not be {@code Infinity} 1067 * @return {@code true} if no error occured else {@code false} 1068 * @see #assertInfinity 1069 * @see #assertNotInfinity 1070 * @see #assertNotInfinityWithoutMessage 1071 */ 1072 private function assertNotInfinityWithMessage(message:String, val):Boolean { 1073 return addInfo(new AssertNotInfinityInfo(message, val)); 1074 } 1075 1076 /** 1077 * @overload #assertEmptyWithMessage 1078 * @overload #assertEmptyWithoutMessage 1079 */ 1080 private function assertEmpty():Boolean { 1081 var overload:Overload = new Overload(this); 1082 overload.addHandler([String, Object], assertEmptyWithMessage); 1083 overload.addHandler([Object], assertEmptyWithoutMessage); 1084 overload.addHandler([], assertEmptyWithoutMessage); 1085 return overload.forward(arguments); 1086 } 1087 1088 /** 1089 * Asserts if the passed-in {@code val} is empty. 1090 * 1091 * <p>Empty means to be {@code === null} or {@code === undefined}. 1092 * 1093 * @param val parameter that should be empty 1094 * @return {@code true} if no error occured else {@code false} 1095 * @see #assertNull 1096 * @see #assertUndefined 1097 * @see #assertNotEmpty 1098 * @see #assertEmpty 1099 * @see #assertEmptyWithMessage 1100 */ 1101 private function assertEmptyWithoutMessage(val):Boolean { 1102 return assertEmptyWithMessage("", val); 1103 } 1104 1105 /** 1106 * Asserts if the passed-in {@code val} is empty or fails with the passed-in 1107 * {@code message}. 1108 * 1109 * <p>This method asserts the same like {@code assertEmptyWithoutMessage} 1110 * but it adds a message to the failure. 1111 * 1112 * @param message message to be provided if the assertion fails 1113 * @param val parameter that should be empty 1114 * @return {@code true} if no error occured else {@code false} 1115 * @see #assertNull 1116 * @see #assertUndefined 1117 * @see #assertNotEmpty 1118 * @see #assertEmpty 1119 * @see #assertEmptyWithoutMessage 1120 */ 1121 private function assertEmptyWithMessage(message:String, val):Boolean { 1122 return addInfo(new AssertEmptyInfo(message, val)); 1123 } 1124 1125 /** 1126 * @overload #assertNotEmptyWithMessage 1127 * @overload #assertNotEmptyWithoutMessage 1128 */ 1129 private function assertNotEmpty():Boolean { 1130 var overload:Overload = new Overload(this); 1131 overload.addHandler([String, Object], assertNotEmptyWithMessage); 1132 overload.addHandler([Object], assertNotEmptyWithoutMessage); 1133 overload.addHandler([], assertNotEmptyWithoutMessage); 1134 return overload.forward(arguments); 1135 } 1136 1137 /** 1138 * Asserts if the passed-in {@code val} is not empty. 1139 * 1140 * <p>Not empty means to be {@code !== null} and {@code !== undefined}. 1141 * 1142 * @param val parameter that should not be empty 1143 * @return {@code true} if no error occured else {@code false} 1144 * @see #assertNotNull 1145 * @see #assertNotUndefined 1146 * @see #assertEmpty 1147 * @see #assertNotEmpty 1148 * @see #assertNotEmptyWithMessage 1149 */ 1150 private function assertNotEmptyWithoutMessage(val):Boolean { 1151 return assertNotEmptyWithMessage("", val); 1152 } 1153 1154 /** 1155 * Asserts if the passed-in {@code val} is not empty or fails with the passed-in 1156 * {@code message}. 1157 * 1158 * <p>This method asserts the same like {@code assertNotEmptyWithoutMessage} 1159 * but it adds a message to the failure. 1160 * 1161 * @param message message to be provided if the assertion fails 1162 * @param val parameter that should not be empty 1163 * @return {@code true} if no error occured else {@code false} 1164 * @see #assertNotNull 1165 * @see #assertNotUndefined 1166 * @see #assertEmpty 1167 * @see #assertNotEmpty 1168 * @see #assertNotEmptyWithoutMessage 1169 */ 1170 private function assertNotEmptyWithMessage(message:String, val):Boolean { 1171 return addInfo(new AssertNotEmptyInfo(message, val)); 1172 } 1173 1174 /** 1175 * @overload #assertThrowsWithCall 1176 * @overload #assertThrowsWithCallAndType 1177 * @overload #assertThrowsWithCallAndMessage 1178 * @overload #assertThrowsWithCallAndMessageAndType 1179 * @overload #assertThrowsWithString 1180 * @overload #assertThrowsWithStringAndType 1181 * @overload #assertThrowsWithStringAndMessage 1182 * @overload #assertThrowsWithStringAndMessageAndType 1183 * @overload #assertThrowsWithFunction 1184 * @overload #assertThrowsWithFunctionAndType 1185 * @overload #assertThrowsWithFunctionAndMessage 1186 * @overload #assertThrowsWithFunctionAndMessageAndType 1187 */ 1188 private function assertThrows():Boolean { 1189 var overload:Overload = new Overload(this); 1190 overload.addHandler( 1191 [Executable, Array], 1192 assertThrowsWithCall); 1193 overload.addHandler( 1194 [Object, String, Array], 1195 assertThrowsWithString); 1196 overload.addHandler( 1197 [Object, Function, Array], 1198 assertThrowsWithFunction); 1199 overload.addHandler( 1200 [Object, Executable, Array], 1201 assertThrowsWithCallAndType); 1202 overload.addHandler( 1203 [Object, Object, String, Array], 1204 assertThrowsWithStringAndType); 1205 overload.addHandler( 1206 [Object, Object, Function, Array], 1207 assertThrowsWithFunctionAndType); 1208 overload.addHandler( 1209 [String, Executable, Array], 1210 assertThrowsWithCallAndMessage); 1211 overload.addHandler( 1212 [String, Object, String, Array], 1213 assertThrowsWithStringAndMessage); 1214 overload.addHandler( 1215 [String, Object, Function, Array], 1216 assertThrowsWithFunctionAndMessage); 1217 overload.addHandler( 1218 [String, Object, Executable, Array], 1219 assertThrowsWithCallAndMessageAndType); 1220 overload.addHandler( 1221 [String, Object, Object, String, Array], 1222 assertThrowsWithStringAndMessageAndType); 1223 overload.addHandler( 1224 [String, Object, Object, Function, Array], 1225 assertThrowsWithFunctionAndMessageAndType); 1226 return overload.forward(arguments); 1227 } 1228 1229 /** 1230 * Asserts if the execution of a {@link Executable} throws any exception. 1231 * 1232 * <p>This method executes at the passed-in {@code executable} the method 1233 * {@code execute} using the passed-in {@code args} and checks if it throws any 1234 * exception. 1235 * 1236 * <p>The assertion fails if the method did not throw any exception. 1237 * 1238 * @param executable {@code Executable} that should be executed 1239 * @param args arguments to be used for the execution 1240 * @return {@code true} if no error occured else {@code false} 1241 * @see #assertThrowsWithCallAndMessage 1242 */ 1243 private function assertThrowsWithCall(executable:Executable, args:Array):Boolean { 1244 return assertThrowsWithCallAndMessage("", executable, args); 1245 } 1246 1247 /** 1248 * Asserts if the execution of a {@link Executable} throws a certain exception. 1249 * 1250 * <p>This method executes at the passed-in {@code executable} the method 1251 * {@code execute} using the passed-in {@code args} and checks if it throws the 1252 * expected exception. 1253 * 1254 * <p>The assertion fails if the method did not throw any exception or if it 1255 * throw a exception of the wrong type. 1256 * 1257 * @param type type of the exception that should be thrown 1258 * @param executabe {@code Executable} to be executed 1259 * @param args arguments to be used for the execution 1260 * @return {@code true} if no error occured else {@code false} 1261 * @see #assertThrowsWithCallAndMessageAndType 1262 */ 1263 private function assertThrowsWithCallAndType(type, executable:Executable, 1264 args:Array):Boolean { 1265 return assertThrowsWithCallAndMessageAndType("", type, executable, args); 1266 } 1267 1268 /** 1269 * Asserts if the execution of the passed-in {@code name} to the passed-in 1270 * {@code scope} throws any exception. 1271 * 1272 * <p>This method executes within the passed-in {@code scope} the method with 1273 * the name of the passed-in {@code name} and checks if it throws any exception. 1274 * 1275 * <p>The assertion fails if the method did not throw any exception. 1276 * 1277 * @param scope object to be used a scope 1278 * @param name name of the method to be executed within the scope 1279 * @param args arguments to be used for the execution 1280 * @return {@code true} if no error occured else {@code false} 1281 * @see #assertThrowsWithStringAndMessage 1282 */ 1283 private function assertThrowsWithString(scope, name:String, args:Array):Boolean { 1284 return assertThrowsWithStringAndMessage("", scope, name, args); 1285 } 1286 1287 /** 1288 * Asserts if the execution of the passed-in {@code name} to the passed-in 1289 * {@code scope} throws any exception. 1290 * 1291 * <p>This method executes within the passed-in {@code scope} the method with 1292 * the name of the passed-in {@code name} and checks if it throws the 1293 * expected exception. 1294 * 1295 * <p>The assertion fails if the method did not throw any exception or if it 1296 * throw a exception of the wrong type. 1297 * 1298 * @param type type of the exception that should be thrown 1299 * @param scope object to be used a scope 1300 * @param name name of the method to be executed within the scope 1301 * @param args arguments to be used for the execution 1302 * @return {@code true} if no error occured else {@code false} 1303 * @see #assertThrowsWithStringAndMessageAndType 1304 */ 1305 private function assertThrowsWithStringAndType(type, scope, name:String, 1306 args:Array):Boolean { 1307 return assertThrowsWithStringAndMessageAndType("", type, scope, name, args); 1308 } 1309 1310 /** 1311 * Asserts if the passed-in {@code method} throw any exception during its execution 1312 * to the passed-in {@code scope}. 1313 * 1314 * <p>This method executes within the passed-in {@code scope} the passed-in 1315 * {@code method} using the passed-in {@code args} and checks if it throws 1316 * the expected exception. 1317 * 1318 * <p>The assertion fails if the method did not throw any exception. 1319 * 1320 * @param scope object to be used a scope 1321 * @param method method that should be executed with the certain scope 1322 * @param args arguments to be used for the execution 1323 * @return {@code true} if no error occured else {@code false} 1324 * @see #assertThrowsWithFunctionAndMessage 1325 */ 1326 private function assertThrowsWithFunction(scope, method:Function, 1327 args:Array):Boolean { 1328 return assertThrowsWithFunctionAndMessage("", scope, method, args); 1329 } 1330 1331 /** 1332 * Asserts if the passed-in {@code method} throw any exception during its execution 1333 * to the passed-in {@code scope}. 1334 * 1335 * <p>This method executes within the passed-in {@code scope} the passed-in 1336 * {@code method} using the passed-in {@code args} and checks if it throws 1337 * any exception. 1338 * 1339 * <p>The assertion fails if the method did not throw any exception or if it 1340 * throw a exception of the wrong type. 1341 * 1342 * @param type type of the exception that should be thrown 1343 * @param scope object to be used a scope 1344 * @param method method that should be executed with the certain scope 1345 * @param args arguments to be used for the execution 1346 * @return {@code true} if no error occured else {@code false} 1347 * @see #assertThrowsWithFunctionAndMessageAndType 1348 */ 1349 private function assertThrowsWithFunctionAndType(type, inObject, func:Function, 1350 args:Array):Boolean { 1351 return assertThrowsWithFunctionAndMessageAndType("", type, inObject, func, args); 1352 } 1353 1354 /** 1355 * Asserts if the execution of a {@link Executable} throws any exception. 1356 * 1357 * <p>This methods asserts the same like {@code assertThrowsWithCall} 1358 * but it adds a message to the failure. 1359 * 1360 * @param message message to be provided if the assertion fails 1361 * @param executable {@code Executable} that should be executed 1362 * @param args arguments to be used for the execution 1363 * @return {@code true} if no error occured else {@code false} 1364 * @see #assertThrowsWithCall 1365 */ 1366 private function assertThrowsWithCallAndMessage(message:String, executable:Executable, 1367 args:Array):Boolean { 1368 return assertThrowsWithCallAndMessageAndType(message, null, executable, args); 1369 } 1370 1371 /** 1372 * Asserts if the execution of a {@link Executable} throws a certain exception. 1373 * 1374 * <p>This methods asserts the same like {@code assertThrowsWithCallAndType} 1375 * but it adds a message to the failure. 1376 * 1377 * @param message message to be provided if the assertion fails 1378 * @param type type of the exception that should be thrown 1379 * @param executable {@code Executable} that should be executed 1380 * @param args arguments to be used for the execution 1381 * @return {@code true} if no error occured else {@code false} 1382 * @see #assertThrowsWithCallAndType 1383 */ 1384 private function assertThrowsWithCallAndMessageAndType(message:String, type, 1385 executable:Executable, args:Array):Boolean { 1386 return addInfo(new AssertThrowsInfo(message, type, executable, args)); 1387 } 1388 1389 /** 1390 * Asserts if the execution of the passed-in {@code name} to the passed-in 1391 * {@code scope} throws any exception. 1392 * 1393 * <p>This methods asserts the same like {@code assertThrowsWithString} 1394 * but it adds a message to the failure. 1395 * 1396 * @param message message to be provided if the assertion fails 1397 * @param scope object to be used a scope 1398 * @param name name of the method to be executed within the scope 1399 * @param args arguments to be used for the execution 1400 * @throws IllegalArgumentException if the method with the passed-in {@code name} 1401 * is not available with the passed-in {@code scope}. 1402 * @return {@code true} if no error occured else {@code false} 1403 * @see #assertThrowsWithString 1404 */ 1405 private function assertThrowsWithStringAndMessage(message:String, scope, 1406 name:String, args:Array):Boolean { 1407 if(ObjectUtil.isTypeOf(scope[name], "function")) { 1408 return assertThrowsWithCallAndMessage(message, new Call(scope, 1409 scope[name]), args); 1410 } else { 1411 throw new IllegalArgumentException("The method '"+name+"' is not available" 1412 +" within "+scope.toString(), this, arguments); 1413 } 1414 } 1415 1416 /** 1417 * Asserts if the execution of the passed-in {@code name} to the passed-in 1418 * {@code scope} throws a certain exception. 1419 * 1420 * <p>This methods asserts the same like {@code assertThrowsWithStringAndType} 1421 * but it adds a message to the failure. 1422 * 1423 * @param type type of the exception that should be thrown 1424 * @param message message to be provided if the assertion fails 1425 * @param scope object to be used a scope 1426 * @param name name of the method to be executed within the scope 1427 * @param args arguments to be used for the execution 1428 * @throws IllegalArgumentException if the method with the passed-in {@code name} 1429 * is not available with the passed-in {@code scope}. 1430 * @return {@code true} if no error occured else {@code false} 1431 * @see #assertThrowsWithStringAndType 1432 */ 1433 private function assertThrowsWithStringAndMessageAndType(message:String, type, 1434 scope, name:String,args:Array):Boolean { 1435 if(ObjectUtil.isTypeOf(scope[name], "function")) { 1436 return assertThrowsWithFunctionAndMessageAndType(message, type, 1437 scope, scope[name], args); 1438 } else { 1439 throw new IllegalArgumentException("The method '"+name+"' is not available" 1440 +" within "+scope.toString(), this, arguments); 1441 } 1442 } 1443 1444 /** 1445 * Asserts if the passed-in {@code method} throw any exception during its execution 1446 * to the passed-in {@code scope}. 1447 * 1448 * <p>This methods asserts the same like {@code assertThrowsWithFunction} 1449 * but it adds a message to the failure. 1450 * 1451 * @param message message to be provided if the assertion fails 1452 * @param scope object to be used a scope 1453 * @param method method that should be executed with the certain scope 1454 * @param args arguments to be used for the execution 1455 * @return {@code true} if no error occured else {@code false} 1456 * @see #assertThrowsWithFunction 1457 */ 1458 private function assertThrowsWithFunctionAndMessage(message:String, scope, 1459 method:Function, args:Array):Boolean { 1460 return assertThrowsWithCallAndMessage(message, new Call(scope, method), 1461 args); 1462 } 1463 1464 /** 1465 * Asserts if the passed-in {@code method} throw any exception during its execution 1466 * to the passed-in {@code scope}. 1467 * 1468 * <p>This methods asserts the same like {@code assertThrowsWithFunctionAnyType} 1469 * but it adds a message to the failure. 1470 * 1471 * @param message message to be provided if the assertion fails 1472 * @param type type of the exception that should be thrown 1473 * @param scope object to be used a scope 1474 * @param method method that should be executed with the certain scope 1475 * @param args arguments to be used for the execution 1476 * @return {@code true} if no error occured else {@code false} 1477 * @see #assertThrowsWithFunctionAndType 1478 */ 1479 private function assertThrowsWithFunctionAndMessageAndType(message:String, 1480 type, scope, method:Function, args:Array):Boolean { 1481 return assertThrowsWithCallAndMessageAndType(message, type, 1482 new Call(scope, method), args); 1483 } 1484 1485 /** 1486 * @overload #assertNotThrowsWithCall 1487 * @overload #assertNotThrowsWithCallAndType 1488 * @overload #assertNotThrowsWithCallAndMessage 1489 * @overload #assertNotThrowsWithCallAndMessageAndType 1490 * @overload #assertNotThrowsWithString 1491 * @overload #assertNotThrowsWithStringAndType 1492 * @overload #assertNotThrowsWithStringAndMessage 1493 * @overload #assertNotThrowsWithStringAndMessageAndType 1494 * @overload #assertNotThrowsWithFunction 1495 * @overload #assertNotThrowsWithFunctionAndType 1496 * @overload #assertNotThrowsWithFunctionAndMessage 1497 * @overload #assertNotThrowsWithFunctionAndMessageAndType 1498 */ 1499 private function assertNotThrows():Boolean { 1500 var overload:Overload = new Overload(this); 1501 overload.addHandler( 1502 [Executable, Array], 1503 assertNotThrowsWithCall); 1504 overload.addHandler( 1505 [Object, String, Array], 1506 assertNotThrowsWithString); 1507 overload.addHandler( 1508 [Object, Function, Array], 1509 assertNotThrowsWithFunction); 1510 overload.addHandler( 1511 [Object, Executable, Array], 1512 assertNotThrowsWithCallAndType); 1513 overload.addHandler( 1514 [Object, Object, String, Array], 1515 assertNotThrowsWithStringAndType); 1516 overload.addHandler( 1517 [Object, Object, Function, Array], 1518 assertNotThrowsWithFunctionAndType); 1519 overload.addHandler( 1520 [String, Executable, Array], 1521 assertNotThrowsWithCallAndMessage); 1522 overload.addHandler( 1523 [String, Object, String, Array], 1524 assertNotThrowsWithStringAndMessage); 1525 overload.addHandler( 1526 [String, Object, Function, Array], 1527 assertNotThrowsWithFunctionAndMessage); 1528 overload.addHandler( 1529 [String, Object, Executable, Array], 1530 assertNotThrowsWithCallAndMessageAndType); 1531 overload.addHandler( 1532 [String, Object, Object, String, Array], 1533 assertNotThrowsWithStringAndMessageAndType); 1534 overload.addHandler( 1535 [String, Object, Object, Function, Array], 1536 assertNotThrowsWithFunctionAndMessageAndType); 1537 return overload.forward(arguments); 1538 } 1539 1540 /** 1541 * Asserts if the execution of a {@link Executable} does not throw any exception. 1542 * 1543 * <p>This method executes at the passed-in {@code executable} the method 1544 * {@code execute} using the passed-in {@code args} and checks if it throws a 1545 * exception. 1546 * 1547 * <p>The assertion fails if the method throws any exception. 1548 * 1549 * @param executable {@code Executable} that should be executed 1550 * @param args arguments to be used for the execution 1551 * @return {@code true} if no error occured else {@code false} 1552 * @see #assertNotThrowsWithCallAndMessage 1553 */ 1554 private function assertNotThrowsWithCall(executable:Executable, args:Array):Boolean { 1555 return assertNotThrowsWithCallAndMessage("", executable, args); 1556 } 1557 1558 /** 1559 * Asserts if the execution of a {@link Executable} does not throw a certain 1560 * exception. 1561 * 1562 * <p>This method executes at the passed-in {@code executable} the method 1563 * {@code execute} using the passed-in {@code args} and checks if it does not 1564 * throw a expected exception. 1565 * 1566 * <p>The assertion fails if the method throws a exception of the passed-in 1567 * {@code type}. 1568 * 1569 * @param type type of the exception that should not be thrown 1570 * @param executabe {@code Executable} to be executed 1571 * @param args arguments to be used for the execution 1572 * @return {@code true} if no error occured else {@code false} 1573 * @see #assertNotThrowsWithCallAndMessageAndType 1574 */ 1575 private function assertNotThrowsWithCallAndType(type, executable:Executable, 1576 args:Array):Boolean { 1577 return assertNotThrowsWithCallAndMessageAndType("", type, executable, args); 1578 } 1579 1580 /** 1581 * Asserts if the execution of the passed-in {@code name} to the passed-in 1582 * {@code scope} does not throw any exception. 1583 * 1584 * <p>This method executes within the passed-in {@code scope} the method with 1585 * the name of the passed-in {@code name} and checks if it throws any exception. 1586 * 1587 * <p>The assertion fails if the method throws any exception. 1588 * 1589 * @param scope object to be used a scope 1590 * @param name name of the method to be executed within the scope 1591 * @param args arguments to be used for the execution 1592 * @return {@code true} if no error occured else {@code false} 1593 * @see #assertNotThrowsWithStringAndMessage 1594 */ 1595 private function assertNotThrowsWithString(scope, name:String, 1596 args:Array):Boolean { 1597 return assertNotThrowsWithStringAndMessage("", scope, name, args); 1598 } 1599 1600 /** 1601 * Asserts if the execution of the passed-in {@code name} to the passed-in 1602 * {@code scope} does not throws a certain exception. 1603 * 1604 * <p>This method executes within the passed-in {@code scope} the method with 1605 * the name of the passed-in {@code name} and checks if it does not throw the 1606 * expected exception. 1607 * 1608 * <p>The assertion fails if the method throws a exception of the passed-in 1609 * {@code type}. 1610 * 1611 * @param type type of the exception that should not be thrown 1612 * @param scope object to be used a scope 1613 * @param name name of the method to be executed within the scope 1614 * @param args arguments to be used for the execution 1615 * @return {@code true} if no error occured else {@code false} 1616 * @see #assertNotThrowsWithStringAndMessageAndType 1617 */ 1618 private function assertNotThrowsWithStringAndType(type, scope, name:String, 1619 args:Array):Boolean { 1620 return assertNotThrowsWithStringAndMessageAndType("", type, scope, 1621 name, args); 1622 } 1623 1624 /** 1625 * Asserts if the passed-in {@code method} does not throw any exception during 1626 * its execution to the passed-in {@code scope}. 1627 * 1628 * <p>This method executes within the passed-in {@code scope} the passed-in 1629 * {@code method} using the passed-in {@code args} and checks if it does not 1630 * throw the expected exception. 1631 * 1632 * <p>The assertion fails if the method throws any exception. 1633 * 1634 * @param scope object to be used a scope 1635 * @param method method that should be executed with the certain scope 1636 * @param args arguments to be used for the execution 1637 * @return {@code true} if no error occured else {@code false} 1638 * @see #assertNotThrowsWithFunctionAndMessage 1639 */ 1640 private function assertNotThrowsWithFunction(scope, method:Function, 1641 args:Array):Boolean { 1642 return assertNotThrowsWithFunctionAndMessage("", scope, method, args); 1643 } 1644 1645 /** 1646 * Asserts if the passed-in {@code method} throw a certain exception during 1647 * its execution to the passed-in {@code scope}. 1648 * 1649 * <p>This method executes within the passed-in {@code scope} the passed-in 1650 * {@code method} using the passed-in {@code args} and checks if it throws 1651 * a certain exception. 1652 * 1653 * <p>The assertion fails if the method throws a exception of the passed-in 1654 * {@code type}. 1655 * 1656 * @param type type of the exception that should not be thrown 1657 * @param scope object to be used a scope 1658 * @param method method that should be executed with the certain scope 1659 * @param args arguments to be used for the execution 1660 * @return {@code true} if no error occured else {@code false} 1661 * @see #assertNotThrowsWithFunctionAndMessageAndType 1662 */ 1663 private function assertNotThrowsWithFunctionAndType(type, scope, 1664 method:Function, args:Array):Boolean { 1665 return assertNotThrowsWithFunctionAndMessageAndType("", type, scope, 1666 method, args); 1667 } 1668 1669 /** 1670 * Asserts if the execution of a {@link Executable} does not throw any exception. 1671 * 1672 * <p>This methods asserts the same like {@code assertNotThrowsWithCall} 1673 * but it adds a message to the failure. 1674 * 1675 * @param message message to be provided if the assertion fails 1676 * @param executable {@code Executable} that should be executed 1677 * @param args arguments to be used for the execution 1678 * @return {@code true} if no error occured else {@code false} 1679 * @see #assertNotThrowsWithCall 1680 */ 1681 private function assertNotThrowsWithCallAndMessage(message:String, 1682 executable:Executable, args:Array):Boolean { 1683 return assertNotThrowsWithCallAndMessageAndType(message, null, executable, args); 1684 } 1685 1686 /** 1687 * Asserts if the execution of a {@link Executable} does not throw a certain 1688 * exception. 1689 * 1690 * <p>This methods asserts the same like {@code assertNotThrowsWithCallAndType} 1691 * but it adds a message to the failure. 1692 * 1693 * @param message message to be provided if the assertion fails 1694 * @param type type of the exception that should not be thrown 1695 * @param executable {@code Executable} that should be executed 1696 * @param args arguments to be used for the execution 1697 * @return {@code true} if no error occured else {@code false} 1698 * @see #assertThrowsWithCallAndType 1699 */ 1700 private function assertNotThrowsWithCallAndMessageAndType(message:String, 1701 type, executable:Executable, args:Array):Boolean { 1702 return addInfo(new AssertNotThrowsInfo(message, type, executable, args)); 1703 } 1704 1705 /** 1706 * Asserts if the execution of the passed-in {@code name} to the passed-in 1707 * {@code scope} does not throw any exception. 1708 * 1709 * <p>This methods asserts the same like {@code assertNotThrowsWithString} 1710 * but it adds a message to the failure. 1711 * 1712 * @param message message to be provided if the assertion fails 1713 * @param scope object to be used a scope 1714 * @param name name of the method to be executed within the scope 1715 * @param args arguments to be used for the execution 1716 * @return {@code true} if no error occured else {@code false} 1717 * @throws IllegalArgumentException if the method with the passed-in {@code name} 1718 * is not available with the passed-in {@code scope}. 1719 * @see #assertNotThrowsWithString 1720 */ 1721 private function assertNotThrowsWithStringAndMessage(message:String, inObject, 1722 name:String, args:Array):Boolean { 1723 if(ObjectUtil.isTypeOf(inObject[name], "function")) { 1724 return assertNotThrowsWithCallAndMessage(message, new Call(inObject, 1725 inObject[name]), args); 1726 } else { 1727 throw new IllegalArgumentException("The method '"+name+"' is not available" 1728 +" within "+inObject.toString(), this, arguments); 1729 } 1730 } 1731 1732 /** 1733 * Asserts if the execution of the passed-in {@code name} to the passed-in 1734 * {@code scope} does not throw a certain exception. 1735 * 1736 * <p>This methods asserts the same like {@code assertNotThrowsWithStringAndType} 1737 * but it adds a message to the failure. 1738 * 1739 * @param type type of the exception that should not be thrown 1740 * @param message message to be provided if the assertion fails 1741 * @param scope object to be used a scope 1742 * @param name name of the method to be executed within the scope 1743 * @param args arguments to be used for the execution 1744 * @throws IllegalArgumentException if the method with the passed-in {@code name} 1745 * is not available with the passed-in {@code scope}. 1746 * @return {@code true} if no error occured else {@code false} 1747 * @see #assertNotThrowsWithStringAndType 1748 */ 1749 private function assertNotThrowsWithStringAndMessageAndType(message:String, 1750 type, scope, name:String, args:Array):Boolean { 1751 if(ObjectUtil.isTypeOf(scope[name], "function")) { 1752 return assertNotThrowsWithCallAndMessageAndType(message, type, 1753 new Call(scope, scope[name]), args); 1754 } else { 1755 throw new IllegalArgumentException("The method '"+name+"' is not available" 1756 +" within "+scope.toString(), this, arguments); 1757 } 1758 } 1759 1760 /** 1761 * Asserts if the passed-in {@code method} does not throw any exception during 1762 * its execution to the passed-in {@code scope}. 1763 * 1764 * <p>This methods asserts the same like {@code assertNotThrowsWithFunction} 1765 * but it adds a message to the failure. 1766 * 1767 * @param message message to be provided if the assertion fails 1768 * @param scope object to be used a scope 1769 * @param method method that should be executed with the certain scope 1770 * @param args arguments to be used for the execution 1771 * @return {@code true} if no error occured else {@code false} 1772 * @see #assertNotThrowsWithFunction 1773 */ 1774 private function assertNotThrowsWithFunctionAndMessage(message:String, scope, 1775 method:Function, args:Array):Boolean { 1776 return assertNotThrowsWithCallAndMessage(message, new Call(scope, method), args); 1777 } 1778 1779 /** 1780 * Asserts if the passed-in {@code method} does not throw any exception during 1781 * its execution to the passed-in {@code scope}. 1782 * 1783 * <p>This methods asserts the same like {@code assertNotThrowsWithFunctionAnyType} 1784 * but it adds a message to the failure. 1785 * 1786 * @param message message to be provided if the assertion fails 1787 * @param type type of the exception that should not be thrown 1788 * @param scope object to be used a scope 1789 * @param method method that should be executed with the certain scope 1790 * @param args arguments to be used for the execution 1791 * @return {@code true} if no error occured else {@code false} 1792 * @see #assertThrowsWithFunctionAndType 1793 */ 1794 private function assertNotThrowsWithFunctionAndMessageAndType(message:String, 1795 type, scope, method:Function, args:Array):Boolean { 1796 return assertNotThrowsWithCallAndMessageAndType(message, type, 1797 new Call(scope, method), args); 1798 } 1799 1800 /** 1801 * @overload #assertTypeOfWithMessage 1802 * @overload #assertTypeOfWithoutMessage 1803 */ 1804 private function assertTypeOf():Boolean { 1805 var overload:Overload = new Overload(this); 1806 overload.addHandler([Object, String], assertTypeOfWithoutMessage); 1807 overload.addHandler([String, Object, String], assertTypeOfWithMessage); 1808 return overload.forward(arguments); 1809 } 1810 1811 /** 1812 * Asserts if the passed-in {@code val} matches the passed-in {@code type}. 1813 * 1814 * <p>Checks with {@code typeof} if the {@code typeof} of the passed-in 1815 * {@code val} matches the passed in {@code type}. 1816 * 1817 * @param val parameter to check the type 1818 * @param type expected type of {@code val} 1819 * @return {@code true} if no error occured else {@code false} 1820 * @see #assertTypeOfWithMessage 1821 * @see org.as2lib.util.ObjectUtil#isTypeOf 1822 */ 1823 private function assertTypeOfWithoutMessage(val, type:String):Boolean { 1824 return assertTypeOfWithMessage("", val, type); 1825 } 1826 1827 /** 1828 * Asserts if the passed-in {@code val} matches the passed-in {@code type} or 1829 * fails with the passed-in {@code message}. 1830 * 1831 * <p>This methods asserts the same like {@code assertTypeOfWithoutMessage} 1832 * but it adds a message to the failure. 1833 * 1834 * @param message message to be provided if the assertion fails 1835 * @param val parameter to check the type 1836 * @param type expected type of {@code val} 1837 * @return {@code true} if no error occured else {@code false} 1838 * @see #assertTypeOfWithoutMessage 1839 */ 1840 private function assertTypeOfWithMessage(message:String, val, 1841 type:String):Boolean { 1842 return addInfo(new AssertTypeOfInfo(message, val, type)); 1843 } 1844 1845 /** 1846 * @overload #assertInstanceOfWithMessage 1847 * @overload #assertInstanceOfWithoutMessage 1848 */ 1849 private function assertInstanceOf():Boolean { 1850 var overload:Overload = new Overload(this); 1851 overload.addHandler([Object, Function], assertInstanceOfWithoutMessage); 1852 overload.addHandler([String, Object, Function], assertInstanceOfWithMessage); 1853 return overload.forward(arguments); 1854 } 1855 1856 1857 /** 1858 * Asserts if the passed-in {@code val} is a instance of the passed-in 1859 * {@code type}. 1860 * 1861 * <p>Checks with {@code instanceof} if the passed-in {@code val} is a 1862 * instance of the passed in {@code type}. 1863 * 1864 * @param val parameter to check the type 1865 * @param type expected type of {@code val} 1866 * @return {@code true} if no error occured else {@code false} 1867 * @see #assertInstanceOfWithMessage 1868 * @see org.as2lib.util.ObjectUtil#isInstanceOf 1869 */ 1870 private function assertInstanceOfWithoutMessage(val, type:Function):Boolean { 1871 return assertInstanceOfWithMessage("", val, type); 1872 } 1873 1874 /** 1875 * Asserts if the passed-in {@code val} is a instance of the passed-in 1876 * {@code type} or fails with the passed-in {@code message} 1877 * 1878 * @param message message to be provided if the assertion fails 1879 * @param val parameter to check the type 1880 * @param type expected type of {@code val} 1881 * @return {@code true} if no error occured else {@code false} 1882 * @see #assertInstanceOfWithoutMessage 1883 */ 1884 private function assertInstanceOfWithMessage(message:String, val, 1885 type:Function):Boolean { 1886 return addInfo(new AssertInstanceOfInfo(message, val, type)); 1887 } 1888 1889 }