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 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 } | 1285 } |
1286 } | 1286 } |
1287 | 1287 |
1288 /** | 1288 /** |
1289 * This is the handler for method calls. We loop through the list | 1289 * 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 | 1290 * of [Behavior]s, and find the first match that still has return |
1291 * values available, and then do the action specified by that | 1291 * values available, and then do the action specified by that |
1292 * return value. If we find no [Behavior] to apply an exception is | 1292 * return value. If we find no [Behavior] to apply an exception is |
1293 * thrown. | 1293 * thrown. |
1294 */ | 1294 */ |
1295 noSuchMethod(InvocationMirror invocation) { | 1295 noSuchMethod(Invocation invocation) { |
1296 var method = invocation.memberName; | 1296 var method = invocation.memberName; |
1297 var args = invocation.positionalArguments; | 1297 var args = invocation.positionalArguments; |
1298 if (invocation.isGetter) { | 1298 if (invocation.isGetter) { |
1299 method = 'get $method'; | 1299 method = 'get $method'; |
1300 } else if (invocation.isSetter) { | 1300 } else if (invocation.isSetter) { |
1301 method = 'set $method'; | 1301 method = 'set $method'; |
1302 // Remove the trailing '='. | 1302 // Remove the trailing '='. |
1303 if (method[method.length-1] == '=') { | 1303 if (method[method.length-1] == '=') { |
1304 method = method.substring(0, method.length - 1); | 1304 method = method.substring(0, method.length - 1); |
1305 } | 1305 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 } | 1479 } |
1480 } | 1480 } |
1481 } | 1481 } |
1482 | 1482 |
1483 /** Clear both logs and behavior. */ | 1483 /** Clear both logs and behavior. */ |
1484 void reset() { | 1484 void reset() { |
1485 resetBehavior(); | 1485 resetBehavior(); |
1486 clearLogs(); | 1486 clearLogs(); |
1487 } | 1487 } |
1488 } | 1488 } |
OLD | NEW |