| OLD | NEW |
| 1 part of angular.mock; | 1 part of angular.mock; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * Mock implementation of [ExceptionHandler] that rethrows exceptions. | 4 * Mock implementation of [ExceptionHandler] that rethrows exceptions. |
| 5 */ | 5 */ |
| 6 class RethrowExceptionHandler extends ExceptionHandler { | 6 class RethrowExceptionHandler extends ExceptionHandler { |
| 7 call(error, stack, [reason]){ | 7 call(error, stack, [reason]){ |
| 8 throw "$error $reason \nORIGINAL STACKTRACE:\n $stack"; | 8 throw "$error $reason \nORIGINAL STACKTRACE:\n $stack"; |
| 9 } | 9 } |
| 10 } | 10 } |
| 11 | 11 |
| 12 class ExceptionWithStack { | 12 class ExceptionWithStack { |
| 13 final dynamic error; | 13 final dynamic error; |
| 14 final dynamic stack; | 14 final dynamic stack; |
| 15 ExceptionWithStack(this.error, this.stack); | 15 ExceptionWithStack(this.error, this.stack); |
| 16 toString() => "$error\n$stack"; | 16 toString() => "$error\n$stack"; |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Mock implementation of [ExceptionHandler] that logs all exceptions for | 20 * Mock implementation of [ExceptionHandler] that logs all exceptions for |
| 21 * later processing. | 21 * later processing. |
| 22 */ | 22 */ |
| 23 class LoggingExceptionHandler implements ExceptionHandler { | 23 class LoggingExceptionHandler implements ExceptionHandler { |
| 24 /** | 24 /** |
| 25 * All exceptions are stored here for later examining. | 25 * All exceptions are stored here for later examining. |
| 26 */ | 26 */ |
| 27 final errors = <ExceptionWithStack>[]; | 27 final List<ExceptionWithStack> errors = []; |
| 28 | 28 |
| 29 call(error, stack, [reason]) { | 29 call(error, stack, [reason]) { |
| 30 errors.add(new ExceptionWithStack(error, stack)); | 30 errors.add(new ExceptionWithStack(error, stack)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * This method throws an exception if the errors is not empty. | 34 * This method throws an exception if the errors is not empty. |
| 35 * It is recommended that this method is called on test tear-down | 35 * It is recommended that this method is called on test tear-down |
| 36 * to verify that all exceptions have been processed. | 36 * to verify that all exceptions have been processed. |
| 37 */ | 37 */ |
| 38 assertEmpty() { | 38 assertEmpty() { |
| 39 if (errors.isNotEmpty) { | 39 if (errors.length > 0) { |
| 40 throw new ArgumentError('Exception Logger not empty:\n$errors'); | 40 throw new ArgumentError('Exception Logger not empty:\n$errors'); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 } | 43 } |
| OLD | NEW |