Skip to content

Commit 75972a7

Browse files
committed
Comments
1 parent 0d48651 commit 75972a7

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,17 @@ being passed into:
214214
```dart
215215
when(cat.walk(
216216
typed/*<List<String>>*/(any),
217-
gaits: typed/*<Map<String, String>>*/(any), name: 'gaits')).thenReturn(true);
217+
gaits: typed/*<Map<String, String>>*/(any, named: 'gaits'))).thenReturn(true);
218218
```
219219

220-
Note the `name` argument. Mockito should fail gracefully if you forget to name a `typed`
220+
Note the `named` argument. Mockito should fail gracefully if you forget to name a `typed`
221221
call passed in as a named argument, or name the argument incorrectly.
222222

223223
One more note about the `typed` API: you cannot mix `typed` arguments with `null`
224224
arguments:
225225

226226
```dart
227-
when(cat.eatFood(null, typed/*<List<String>>*/(any))).thenReturn(true) // Throws!
227+
when(cat.eatFood(null, typed/*<List<String>>*/(any))).thenReturn(true); // Throws!
228228
when(cat.eatFood(
229229
argThat(equals(null)),
230230
typed/*<List<String>>*/(any))).thenReturn(true); // Works.

lib/mockito.dart

+12-14
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ class Mock {
5555

5656
// Return a new [Invocation], reconstituted from [invocation], [_typedArgs],
5757
// and [_typedNamedArgs].
58-
Invocation _reconstituteInvocation(Invocation invocation) {
59-
var newInvocation = new FakeInvocation(invocation);
60-
return newInvocation;
61-
}
58+
Invocation _reconstituteInvocation(Invocation invocation) =>
59+
new FakeInvocation(invocation);
6260

6361
/// An Invocation implementation that allows all attributes to be passed into
6462
/// the constructor.
@@ -104,9 +102,9 @@ class FakeInvocation extends Invocation {
104102
// `when(obj.fn(a: typed(any)))`.
105103
throw new ArgumentError(
106104
'A typed argument was passed in as a named argument named "$name", '
107-
'but did not a value for its name. Each typed argument that is '
108-
'passed as a named argument needs to specify the `name` argument. '
109-
'For example: `when(obj.fn(x: typed(any, name: "x")))`.');
105+
'but did not pass a value for `named`. Each typed argument that is '
106+
'passed as a named argument needs to specify the `named` argument. '
107+
'For example: `when(obj.fn(x: typed(any, named: "x")))`.');
110108
}
111109
} else {
112110
// Add each real named argument that was _not_ passed with [typed].
@@ -118,16 +116,16 @@ class FakeInvocation extends Invocation {
118116
Symbol nameSymbol = new Symbol(name);
119117
if (!invocation.namedArguments.containsKey(nameSymbol)) {
120118
// Incorrect usage of [name], something like:
121-
// `when(obj.fn(typed(any, name: 'a')))`.
119+
// `when(obj.fn(typed(any, named: 'a')))`.
122120
throw new ArgumentError(
123-
'A typed argument was declared with name $name, but was not passed '
121+
'A typed argument was declared as named $name, but was not passed '
124122
'as an argument named $name.');
125123
}
126124
if (invocation.namedArguments[nameSymbol] != null) {
127125
// Incorrect usage of [name], something like:
128-
// `when(obj.fn(a: typed(any, name: 'b'), b: "string"))`.
126+
// `when(obj.fn(a: typed(any, named: 'b'), b: "string"))`.
129127
throw new ArgumentError(
130-
'A typed argument was declared with name $name, but a different '
128+
'A typed argument was declared as named $name, but a different '
131129
'value (${invocation.namedArguments[nameSymbol]}) was passed as '
132130
'$name.');
133131
}
@@ -422,11 +420,11 @@ get captureAny => new _ArgMatcher(anything, true);
422420
captureThat(Matcher matcher) => new _ArgMatcher(matcher, true);
423421
argThat(Matcher matcher) => new _ArgMatcher(matcher, false);
424422

425-
/*=T*/ typed/*<T>*/(_ArgMatcher matcher, {String name}) {
426-
if (name == null) {
423+
/*=T*/ typed/*<T>*/(_ArgMatcher matcher, {String named}) {
424+
if (named == null) {
427425
_typedArgs.add(matcher);
428426
} else {
429-
_typedNamedArgs[name] = matcher;
427+
_typedNamedArgs[named] = matcher;
430428
}
431429
return null;
432430
}

test/mockito_test.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void main() {
267267
});
268268
test("should mock method with named, typed arg matcher", () {
269269
when(mock.methodWithSpecialNamedArgs(
270-
typed/*<List<int>>*/(any), [43], y: typed/*<List<int>>*/(any, name: "y")))
270+
typed/*<List<int>>*/(any), [43], y: typed/*<List<int>>*/(any, named: "y")))
271271
.thenReturn("A lot!");
272272
expect(mock.methodWithSpecialNamedArgs([42], [43], y: [44]), equals("A lot!"));
273273
});
@@ -276,7 +276,7 @@ void main() {
276276
mock.methodWithSpecialNamedArgs(
277277
typed/*<List<int>>*/(any),
278278
[43],
279-
y: typed/*<List<int>>*/(any, name: "y"),
279+
y: typed/*<List<int>>*/(any, named: "y"),
280280
z: argThat(contains(45))))
281281
.thenReturn("A lot!");
282282
expect(mock.methodWithSpecialNamedArgs([42], [43], y: [44], z: [45]),
@@ -287,25 +287,25 @@ void main() {
287287
mock.methodWithSpecialNamedArgs(
288288
typed/*<List<int>>*/(any),
289289
[43],
290-
y: typed/*<List<int>>*/(any, name: "y"),
290+
y: typed/*<List<int>>*/(any, named: "y"),
291291
z: [45]))
292292
.thenReturn("A lot!");
293293
expect(mock.methodWithSpecialNamedArgs([42], [43], y: [44], z: [45]),
294294
equals("A lot!"));
295295
});
296-
test("should throw when [typed] used as a named arg, without `name:`", () {
296+
test("should throw when [typed] used as a named arg, without `named:`", () {
297297
expect(() => when(mock.methodWithSpecialNamedArgs(
298298
typed/*<List<int>>*/(any), [43], y: typed/*<List<int>>*/(any))),
299299
throwsArgumentError);
300300
});
301-
test("should throw when [typed] used as a positional arg, with `name:`", () {
301+
test("should throw when [typed] used as a positional arg, with `named:`", () {
302302
expect(() => when(mock.methodWithSpecialNamedArgs(
303-
typed/*<List<int>>*/(any), typed/*<List<int>>*/(any, name: "y"))),
303+
typed/*<List<int>>*/(any), typed/*<List<int>>*/(any, named: "y"))),
304304
throwsArgumentError);
305305
});
306-
test("should throw when [typed] used as a named arg, with the wrong `name:`", () {
306+
test("should throw when [typed] used as a named arg, with the wrong `named:`", () {
307307
expect(() => when(mock.methodWithSpecialNamedArgs(
308-
typed/*<List<int>>*/(any), [43], y: typed/*<List<int>>*/(any, name: "z"))),
308+
typed/*<List<int>>*/(any), [43], y: typed/*<List<int>>*/(any, named: "z"))),
309309
throwsArgumentError);
310310
});
311311
});

0 commit comments

Comments
 (0)