DescriptionAdjust method parameters in noSuchMethod helper stubs.
If we have code like:
class Cat {
int eatFood(List<String> foods, [List<String> mixins]) => 0;
int walk(List<String> places, {Map<String, String> gaits}) => 0;
}
class MockCat extends Mock implements Cat {}
Then the eatFood stub on MockCat cannot just always pass foods and mixins to the new Invocation; it must only pass mixins if mixins was passed originally. This CL fixes that.
Here's a Mockito script that verifies the right behavior (and doesn't work with today's DDC):
import 'package:test/test.dart';
import 'lib/mockito.dart';
class Cat {
int eatFood(List<String> foods, [List<String> mixins]) => 0;
int walk(List<String> places, {Map<String, String> gaits}) => 0;
}
class MockCat extends Mock implements Cat {}
void main() {
print('Should print 1 through 5:');
dynamic cat = new MockCat();
when(cat.eatFood(typed/*<List<String>>*/(any))).thenReturn(1);
when(cat.eatFood(typed/*<List<String>>*/(any), ['tuna'])).thenReturn(2);
when(cat.eatFood(typed/*<List<String>>*/(any),
typed/*<List<String>>*/(argThat(hasLength(2)))))
.thenReturn(3);
print(cat.eatFood(<String>['mouse']));
print(cat.eatFood(<String>['mouse'], ['tuna']));
print(cat.eatFood(<String>['mouse'], ['tuna', 'chicken']));
when(cat.walk(typed/*<List<String>>*/(any))).thenReturn(4);
when(cat.walk(typed/*<List<String>>*/(any), gaits: typed/*<Map<String, String>>*/(any, named: 'gaits'))).thenReturn(5);
print(cat.walk(<String>['window']));
print(cat.walk(<String>['window'], gaits: {'window': 'quickly'}));
}
Steps to test this file (its a pain):
1. Clone My typed branch of the mockito repo (https://github.com/srawlins/dart-mockito/tree/typed-api).
2. $ pub get
3. Write this file into the root directory of the mockito repo.
4. $ dart --packages=/Users/srawlins/code/dart-dev_compiler/.packages ../dart-dev_compiler/tool/global_compile.dart cat.dart (adjust for your DDC path)
5. $ node out.js
Patch Set 1 #
Total comments: 1
Messages
Total messages: 6 (2 generated)
|