Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix List args equality check #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/mockito.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library mockito;

import 'dart:mirrors';

import 'package:collection/equality.dart';
import 'package:test/test.dart';


Expand Down Expand Up @@ -170,6 +170,8 @@ class InvocationMatcher {
return roleArg._matcher.matches(actArg, {});
// } else if(roleArg is Mock){
// return identical(roleArg, actArg);
} else if(roleArg is List && actArg is List){
return new ListEquality().equals(roleArg, actArg);
} else {
return roleArg == actArg;
}
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: mockito
version: 0.10.1
version: 0.10.2
author: Dmitriy Fibulwinter <[email protected]>
description: A mock framework inspired by Mockito.
homepage: https://github.com/fibulwinter/dart-mockito
environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
test: '>=0.12.0 <0.13.0'
collection: ">=1.1.0 <2.0.0"
22 changes: 22 additions & 0 deletions test/mockito_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:mockito/mockito.dart';
class RealClass {
String methodWithoutArgs() => "Real";
String methodWithNormalArgs(int x) => "Real";
String methodWithListArgs(List x) => "Real";
String methodWithPositionalArgs(int x, [int y]) => "Real";
String methodWithNamedArgs(int x, {int y}) => "Real";
String methodWithTwoNamedArgs(int x, {int y, int z}) => "Real";
Expand Down Expand Up @@ -90,6 +91,11 @@ void main() {
expect(mock.methodWithNormalArgs(43), isNull);
expect(mock.methodWithNormalArgs(42), equals("Ultimate Answer"));
});
test("should mock method with list args", (){
when(mock.methodWithListArgs([42])).thenReturn("Ultimate Answer");
expect(mock.methodWithListArgs([43]), isNull);
expect(mock.methodWithListArgs([42]), equals("Ultimate Answer"));
});
test("should mock method with positional args", () {
when(mock.methodWithPositionalArgs(42, 17)).thenReturn("Answer and...");
expect(mock.methodWithPositionalArgs(42), isNull);
Expand Down Expand Up @@ -124,6 +130,11 @@ void main() {
.thenReturn("x y z");
expect(mock.methodWithTwoNamedArgs(42, y:18, z:17), equals("x y z"));
});
test("should mock method with any list argument matcher", (){
when(mock.methodWithListArgs(any)).thenReturn("A lot!");
expect(mock.methodWithListArgs([42]), equals("A lot!"));
expect(mock.methodWithListArgs([43]), equals("A lot!"));
});
test("should mock method with mix of argument matchers and real things",
() {
when(mock.methodWithPositionalArgs(argThat(greaterThan(100)), 17))
Expand Down Expand Up @@ -202,6 +213,13 @@ void main() {
});
verify(mock.methodWithNormalArgs(42));
});
test("should verify method with List args", (){
mock.methodWithListArgs([42]);
expectFail("No matching calls. All calls: MockedClass.methodWithListArgs([42])", (){
verify(mock.methodWithListArgs([43]));
});
verify(mock.methodWithListArgs([42]));
});
test("should mock method with positional args", () {
mock.methodWithPositionalArgs(42, 17);
expectFail(
Expand Down Expand Up @@ -439,6 +457,10 @@ void main() {
expect(verify(mock.methodWithNormalArgs(captureAny)).captured.single,
equals(42));
});
test("should captureOut list arguments", (){
mock.methodWithListArgs([42]);
expect(verify(mock.methodWithListArgs(captureAny)).captured.single, equals([42]));
});
test("should captureOut multiple arguments", () {
mock.methodWithPositionalArgs(1, 2);
expect(verify(
Expand Down