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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/unittest/mock_test.dart » ('j') | tests/lib/unittest/mock_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/mock.dart
===================================================================
--- lib/unittest/mock.dart (revision 10584)
+++ lib/unittest/mock.dart (working copy)
@@ -493,7 +493,8 @@
* a bool. If [logFilter] is null, it will match any [LogEntry].
* If no entry is found, then [failureReturnValue] is returned.
* After each check the position is updated by [skip], so using
- * [skip] of -1 allows backward searches.
+ * [skip] of -1 allows backward searches, using a [skip] of 2 can
+ * be used to check pairs of adjacent entries, and so on.
*/
int findLogEntry(logFilter, [int start = 0, int failureReturnValue = -1,
skip = 1]) {
@@ -1435,4 +1436,24 @@
arg9 = _noArg]) =>
getLogs(callsTo(method, arg0, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8, arg9));
+
+ /** Clear the behaviors for the Mock. */
+ void resetBehavior() => _behaviors.clear();
Siggi Cherem (dart-lang) 2012/08/13 17:09:12 do you expect people will want to call these separ
gram 2012/08/13 17:26:58 Yes. For example, I may want to set up the behavio
+
+ /** Clear the logs for the Mock. */
+ void clearLogs() {
+ if (log != null) {
+ if (name == null) { // This log is not shared.
+ log.logs.clear();
+ } else { // This log may be shared.
+ log.logs = log.logs.filter((e) => e.mockName != name);
+ }
+ }
+ }
+
+ /** Clear both logs and behavior. */
+ void reset() {
+ resetBehavior();
+ clearLogs();
+ }
}
« no previous file with comments | « no previous file | tests/lib/unittest/mock_test.dart » ('j') | tests/lib/unittest/mock_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698