| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A simple mocking/spy library. | 6 * A simple mocking/spy library. |
| 7 * | 7 * |
| 8 * To create a mock objects for some class T, create a new class using: | 8 * To create a mock objects for some class T, create a new class using: |
| 9 * | 9 * |
| 10 * class MockT extends Mock implements T {}; | 10 * class MockT extends Mock implements T {}; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 * Foo real; | 83 * Foo real; |
| 84 * MockFoo() { | 84 * MockFoo() { |
| 85 * real = new Foo(); | 85 * real = new Foo(); |
| 86 * this.when(callsTo('bar')).alwaysCall(real.bar); | 86 * this.when(callsTo('bar')).alwaysCall(real.bar); |
| 87 * } | 87 * } |
| 88 * } | 88 * } |
| 89 * | 89 * |
| 90 */ | 90 */ |
| 91 | 91 |
| 92 library mock; | 92 library mock; |
| 93 |
| 94 import 'dart:mirrors' show MirrorSystem; |
| 95 |
| 93 import 'matcher.dart'; | 96 import 'matcher.dart'; |
| 94 | 97 |
| 95 /** | 98 /** |
| 96 * The error formatter for mocking is a bit different from the default one | 99 * The error formatter for mocking is a bit different from the default one |
| 97 * for unit testing; instead of the third argument being a 'reason' | 100 * for unit testing; instead of the third argument being a 'reason' |
| 98 * it is instead a [signature] describing the method signature filter | 101 * it is instead a [signature] describing the method signature filter |
| 99 * that was used to select the logs that were verified. | 102 * that was used to select the logs that were verified. |
| 100 */ | 103 */ |
| 101 String _mockingErrorFormatter(actual, Matcher matcher, String signature, | 104 String _mockingErrorFormatter(actual, Matcher matcher, String signature, |
| 102 MatchState matchState, bool verbose) { | 105 MatchState matchState, bool verbose) { |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 } | 1289 } |
| 1287 | 1290 |
| 1288 /** | 1291 /** |
| 1289 * This is the handler for method calls. We loop through the list | 1292 * This is the handler for method calls. We loop through the list |
| 1290 * of [Behavior]s, and find the first match that still has return | 1293 * of [Behavior]s, and find the first match that still has return |
| 1291 * values available, and then do the action specified by that | 1294 * values available, and then do the action specified by that |
| 1292 * return value. If we find no [Behavior] to apply an exception is | 1295 * return value. If we find no [Behavior] to apply an exception is |
| 1293 * thrown. | 1296 * thrown. |
| 1294 */ | 1297 */ |
| 1295 noSuchMethod(Invocation invocation) { | 1298 noSuchMethod(Invocation invocation) { |
| 1296 var method = invocation.memberName; | 1299 var method = MirrorSystem.getName(invocation.memberName); |
| 1297 var args = invocation.positionalArguments; | 1300 var args = invocation.positionalArguments; |
| 1298 if (invocation.isGetter) { | 1301 if (invocation.isGetter) { |
| 1299 method = 'get $method'; | 1302 method = 'get $method'; |
| 1300 } else if (invocation.isSetter) { | 1303 } else if (invocation.isSetter) { |
| 1301 method = 'set $method'; | 1304 method = 'set $method'; |
| 1302 // Remove the trailing '='. | 1305 // Remove the trailing '='. |
| 1303 if (method[method.length-1] == '=') { | 1306 if (method[method.length-1] == '=') { |
| 1304 method = method.substring(0, method.length - 1); | 1307 method = method.substring(0, method.length - 1); |
| 1305 } | 1308 } |
| 1306 } | 1309 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 } | 1482 } |
| 1480 } | 1483 } |
| 1481 } | 1484 } |
| 1482 | 1485 |
| 1483 /** Clear both logs and behavior. */ | 1486 /** Clear both logs and behavior. */ |
| 1484 void reset() { | 1487 void reset() { |
| 1485 resetBehavior(); | 1488 resetBehavior(); |
| 1486 clearLogs(); | 1489 clearLogs(); |
| 1487 } | 1490 } |
| 1488 } | 1491 } |
| OLD | NEW |