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

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

Issue 11194025: Second round of cleanups for new optional parameter semantics. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 * to see what parameters were passed in, in which case we would set 822 * to see what parameters were passed in, in which case we would set
823 * [includeKeys]. 823 * [includeKeys].
824 * 824 *
825 * As another simple example, say we wanted to know the three method 825 * As another simple example, say we wanted to know the three method
826 * calls that immediately preceded each failing call to commit(): 826 * calls that immediately preceded each failing call to commit():
827 * 827 *
828 * print(log.preceding(log.getLogs(callsTo('commit'), returning(-1)), 828 * print(log.preceding(log.getLogs(callsTo('commit'), returning(-1)),
829 * distance: 3).toString()); 829 * distance: 3).toString());
830 */ 830 */
831 LogEntryList preceding(LogEntryList keys, 831 LogEntryList preceding(LogEntryList keys,
832 [mockNameFilter = null, 832 {mockNameFilter: null,
833 logFilter = null, 833 logFilter: null,
834 int distance = 1, 834 int distance: 1,
835 bool includeKeys = false]) => 835 bool includeKeys: false}) =>
836 _neighboring(true, keys, mockNameFilter, logFilter, 836 _neighboring(true, keys, mockNameFilter, logFilter,
837 distance, includeKeys); 837 distance, includeKeys);
838 838
839 /** 839 /**
840 * Iterate through the LogEntryList looking for matches to the entries 840 * Iterate through the LogEntryList looking for matches to the entries
841 * in [keys]; for each match found the closest [distance] subsequent log 841 * in [keys]; for each match found the closest [distance] subsequent log
842 * entries that match [mocknameFilter] and [logFilter] will be included in 842 * entries that match [mocknameFilter] and [logFilter] will be included in
843 * the result. If [includeKeys] is true then the entries in [keys] that 843 * the result. If [includeKeys] is true then the entries in [keys] that
844 * resulted in entries in the output list are themselves included in the 844 * resulted in entries in the output list are themselves included in the
845 * output list. If [distance] is zero then all matches are included. 845 * output list. If [distance] is zero then all matches are included.
846 * See [preceding] for a usage example. 846 * See [preceding] for a usage example.
847 */ 847 */
848 LogEntryList following(LogEntryList keys, 848 LogEntryList following(LogEntryList keys,
849 [mockNameFilter = null, 849 {mockNameFilter: null,
850 logFilter = null, 850 logFilter: null,
851 int distance = 1, 851 int distance: 1,
852 bool includeKeys = false]) => 852 bool includeKeys: false}) =>
853 _neighboring(false, keys, mockNameFilter, logFilter, 853 _neighboring(false, keys, mockNameFilter, logFilter,
854 distance, includeKeys); 854 distance, includeKeys);
855 } 855 }
856 856
857 /** 857 /**
858 * [_TimesMatcher]s are used to make assertions about the number of 858 * [_TimesMatcher]s are used to make assertions about the number of
859 * times a method was called. 859 * times a method was called.
860 */ 860 */
861 class _TimesMatcher extends BaseMatcher { 861 class _TimesMatcher extends BaseMatcher {
862 final int min, max; 862 final int min, max;
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 } 1229 }
1230 1230
1231 /** 1231 /**
1232 * This constructor makes a mock that has a [name] and possibly uses 1232 * This constructor makes a mock that has a [name] and possibly uses
1233 * a shared [log]. If [throwIfNoBehavior] is true, any calls to methods 1233 * a shared [log]. If [throwIfNoBehavior] is true, any calls to methods
1234 * that have no defined behaviors will throw an exception; otherwise they 1234 * that have no defined behaviors will throw an exception; otherwise they
1235 * will be allowed and logged (but will not do anything). 1235 * will be allowed and logged (but will not do anything).
1236 * If [enableLogging] is false, no logging will be done initially (whether 1236 * If [enableLogging] is false, no logging will be done initially (whether
1237 * or not a [log] is supplied), but [logging] can be set to true later. 1237 * or not a [log] is supplied), but [logging] can be set to true later.
1238 */ 1238 */
1239 Mock.custom([this.name, 1239 Mock.custom({this.name,
1240 this.log, 1240 this.log,
1241 throwIfNoBehavior = false, 1241 throwIfNoBehavior: false,
1242 enableLogging = true]) : _throwIfNoBehavior = throwIfNoBehavior { 1242 enableLogging: true}) : _throwIfNoBehavior = throwIfNoBehavior {
1243 if (log != null && name == null) { 1243 if (log != null && name == null) {
1244 throw new Exception("Mocks with shared logs must have a name."); 1244 throw new Exception("Mocks with shared logs must have a name.");
1245 } 1245 }
1246 logging = enableLogging; 1246 logging = enableLogging;
1247 _behaviors = new Map<String,Behavior>(); 1247 _behaviors = new Map<String,Behavior>();
1248 } 1248 }
1249 1249
1250 /** 1250 /**
1251 * [when] is used to create a new or extend an existing [Behavior]. 1251 * [when] is used to create a new or extend an existing [Behavior].
1252 * A [CallMatcher] [filter] must be supplied, and the [Behavior]s for 1252 * A [CallMatcher] [filter] must be supplied, and the [Behavior]s for
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 } 1450 }
1451 } 1451 }
1452 } 1452 }
1453 1453
1454 /** Clear both logs and behavior. */ 1454 /** Clear both logs and behavior. */
1455 void reset() { 1455 void reset() {
1456 resetBehavior(); 1456 resetBehavior();
1457 clearLogs(); 1457 clearLogs();
1458 } 1458 }
1459 } 1459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698