Skip to content

verify*Interactions methods throw helpfully that they expect Mock #92

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

Merged
merged 3 commits into from
Feb 21, 2018
Merged
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
23 changes: 17 additions & 6 deletions lib/src/mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -706,17 +706,28 @@ _InOrderVerification get verifyInOrder {
};
}

void _throwMockArgumentError(method) =>
throw new ArgumentError('$method must only be given a Mock object');

void verifyNoMoreInteractions(var mock) {
var unverified = mock._realCalls.where((inv) => !inv.verified).toList();
if (unverified.isNotEmpty) {
fail("No more calls expected, but following found: " + unverified.join());
if (mock is Mock) {
var unverified = mock._realCalls.where((inv) => !inv.verified).toList();
if (unverified.isNotEmpty) {
fail("No more calls expected, but following found: " + unverified.join());
}
} else {
_throwMockArgumentError('verifyNoMoreInteractions');
}
}

void verifyZeroInteractions(var mock) {
if (mock._realCalls.isNotEmpty) {
fail("No interaction expected, but following found: " +
mock._realCalls.join());
if (mock is Mock) {
if (mock._realCalls.isNotEmpty) {
fail("No interaction expected, but following found: " +
mock._realCalls.join());
}
} else {
_throwMockArgumentError('verifyZeroInteractions');
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/mockito_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,11 @@ void main() {
verify(mock.methodWithoutArgs());
verifyNoMoreInteractions(mock);
});

test("throws if given a real object", () {
expect(
() => verifyNoMoreInteractions(new RealClass()), throwsArgumentError);
});
});

group("verifyInOrder()", () {
Expand Down