Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: lib/unittest/mock.dart

Issue 10855128: Added ability to reset Mocks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/unittest/mock_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * The error formatter for mocking is a bit different from the default one 6 * The error formatter for mocking is a bit different from the default one
7 * for unit testing; instead of the third argument being a 'reason' 7 * for unit testing; instead of the third argument being a 'reason'
8 * it is instead a [signature] describing the method signature filter 8 * it is instead a [signature] describing the method signature filter
9 * that was used to select the logs that were verified. 9 * that was used to select the logs that were verified.
10 */ 10 */
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 } 486 }
487 487
488 /** 488 /**
489 * Find the first log entry that satisfies [logFilter] and 489 * Find the first log entry that satisfies [logFilter] and
490 * return its position. A search [start] position can be provided 490 * return its position. A search [start] position can be provided
491 * to allow for repeated searches. [logFilter] can be a [CallMatcher], 491 * to allow for repeated searches. [logFilter] can be a [CallMatcher],
492 * or a predicate function that takes a [LogEntry] argument and returns 492 * or a predicate function that takes a [LogEntry] argument and returns
493 * a bool. If [logFilter] is null, it will match any [LogEntry]. 493 * a bool. If [logFilter] is null, it will match any [LogEntry].
494 * If no entry is found, then [failureReturnValue] is returned. 494 * If no entry is found, then [failureReturnValue] is returned.
495 * After each check the position is updated by [skip], so using 495 * After each check the position is updated by [skip], so using
496 * [skip] of -1 allows backward searches. 496 * [skip] of -1 allows backward searches, using a [skip] of 2 can
497 * be used to check pairs of adjacent entries, and so on.
497 */ 498 */
498 int findLogEntry(logFilter, [int start = 0, int failureReturnValue = -1, 499 int findLogEntry(logFilter, [int start = 0, int failureReturnValue = -1,
499 skip = 1]) { 500 skip = 1]) {
500 logFilter = _makePredicate(logFilter); 501 logFilter = _makePredicate(logFilter);
501 int pos = start; 502 int pos = start;
502 while (pos >= 0 && pos < logs.length) { 503 while (pos >= 0 && pos < logs.length) {
503 if (logFilter(logs[pos])) { 504 if (logFilter(logs[pos])) {
504 return pos; 505 return pos;
505 } 506 }
506 pos += skip; 507 pos += skip;
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 arg2 = _noArg, 1429 arg2 = _noArg,
1429 arg3 = _noArg, 1430 arg3 = _noArg,
1430 arg4 = _noArg, 1431 arg4 = _noArg,
1431 arg5 = _noArg, 1432 arg5 = _noArg,
1432 arg6 = _noArg, 1433 arg6 = _noArg,
1433 arg7 = _noArg, 1434 arg7 = _noArg,
1434 arg8 = _noArg, 1435 arg8 = _noArg,
1435 arg9 = _noArg]) => 1436 arg9 = _noArg]) =>
1436 getLogs(callsTo(method, arg0, arg1, arg2, arg3, arg4, 1437 getLogs(callsTo(method, arg0, arg1, arg2, arg3, arg4,
1437 arg5, arg6, arg7, arg8, arg9)); 1438 arg5, arg6, arg7, arg8, arg9));
1439
1440 /** Clear the behaviors for the Mock. */
1441 void resetBehavior() => _behaviors.clear();
1442
1443 /** Clear the logs for the Mock. */
1444 void clearLogs() {
1445 if (log != null) {
1446 if (name == null) { // This log is not shared.
1447 log.logs.clear();
1448 } else { // This log may be shared.
1449 log.logs = log.logs.filter((e) => e.mockName != name);
1450 }
1451 }
1452 }
1453
1454 /** Clear both logs and behavior. */
1455 void reset() {
1456 resetBehavior();
1457 clearLogs();
1458 }
1438 } 1459 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/unittest/mock_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698