Add some more capture tests (#162)
Add some more capture tests
diff --git a/test/capture_test.dart b/test/capture_test.dart
index 9c1e02b..b1335b8 100644
--- a/test/capture_test.dart
+++ b/test/capture_test.dart
@@ -22,6 +22,7 @@
String methodWithNormalArgs(int x) => 'Real';
String methodWithListArgs(List<int> x) => 'Real';
String methodWithPositionalArgs(int x, [int y]) => 'Real';
+ String methodWithTwoNamedArgs(int x, {int y, int z}) => "Real";
set setter(String arg) {
throw new StateError('I must be mocked');
}
@@ -67,6 +68,11 @@
equals([42]));
});
+ test('should capture setter invocations', () {
+ mock.setter = 'value';
+ expect(verify(mock.setter = captureAny).captured, equals(['value']));
+ });
+
test('should capture multiple arguments', () {
mock.methodWithPositionalArgs(1, 2);
expect(
@@ -91,8 +97,34 @@
expect(verify(mock.methodWithNormalArgs(captureAny)).captured,
equals([1, 2]));
});
- });
- // TODO(srawlins): Test capturing in a setter.
- // TODO(srawlins): Test capturing named arguments.
+ test('should capture invocations with named arguments', () {
+ mock.methodWithTwoNamedArgs(1, y: 42, z: 43);
+ expect(
+ verify(mock.methodWithTwoNamedArgs(any,
+ y: captureAnyNamed('y'), z: captureAnyNamed('z')))
+ .captured,
+ equals([42, 43]));
+ });
+
+ test('should capture invocations with named arguments', () {
+ mock.methodWithTwoNamedArgs(1, y: 42, z: 43);
+ mock.methodWithTwoNamedArgs(1, y: 44, z: 45);
+ expect(
+ verify(mock.methodWithTwoNamedArgs(any,
+ y: captureAnyNamed('y'), z: captureAnyNamed('z')))
+ .captured,
+ equals([42, 43, 44, 45]));
+ });
+
+ test('should capture invocations with named arguments', () {
+ mock.methodWithTwoNamedArgs(1, z: 42, y: 43);
+ mock.methodWithTwoNamedArgs(1, y: 44, z: 45);
+ expect(
+ verify(mock.methodWithTwoNamedArgs(any,
+ y: captureAnyNamed('y'), z: captureAnyNamed('z')))
+ .captured,
+ equals([43, 42, 44, 45]));
+ });
+ });
}
diff --git a/test/deprecated_apis/capture_test.dart b/test/deprecated_apis/capture_test.dart
index d20c069..11725a9 100644
--- a/test/deprecated_apis/capture_test.dart
+++ b/test/deprecated_apis/capture_test.dart
@@ -101,7 +101,4 @@
equals([1, 2]));
});
});
-
- // TODO(srawlins): Test capturing in a setter.
- // TODO(srawlins): Test capturing named arguments.
}
diff --git a/test/mockito_test.dart b/test/mockito_test.dart
index fc2b62d..3369522 100644
--- a/test/mockito_test.dart
+++ b/test/mockito_test.dart
@@ -31,9 +31,6 @@
Future<String> methodReturningFuture() => new Future.value("Real");
Stream<String> methodReturningStream() => new Stream.fromIterable(["Real"]);
String get getter => "Real";
- set setter(String arg) {
- throw new StateError("I must be mocked");
- }
}
abstract class _Foo {
@@ -213,7 +210,6 @@
expect(mock == mock, isTrue);
});
- //no need to mock setter, except if we will have spies later...
test("should mock method with thrown result", () {
when(mock.methodWithNormalArgs(any)).thenThrow(new StateError('Boo'));
expect(() => mock.methodWithNormalArgs(42), throwsStateError);