Skip to content

Commit f2b9b3f

Browse files
authored
verify*Interactions methods throw helpfully that they expect Mock (dart-lang/mockito#92)
verify*Interactions methods throw helpfully that they expect Mock
1 parent 82b9c12 commit f2b9b3f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

pkgs/mockito/lib/src/mock.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,28 @@ _InOrderVerification get verifyInOrder {
703703
};
704704
}
705705

706+
void _throwMockArgumentError(method) =>
707+
throw new ArgumentError('$method must only be given a Mock object');
708+
706709
void verifyNoMoreInteractions(var mock) {
707-
var unverified = mock._realCalls.where((inv) => !inv.verified).toList();
708-
if (unverified.isNotEmpty) {
709-
fail("No more calls expected, but following found: " + unverified.join());
710+
if (mock is Mock) {
711+
var unverified = mock._realCalls.where((inv) => !inv.verified).toList();
712+
if (unverified.isNotEmpty) {
713+
fail("No more calls expected, but following found: " + unverified.join());
714+
}
715+
} else {
716+
_throwMockArgumentError('verifyNoMoreInteractions');
710717
}
711718
}
712719

713720
void verifyZeroInteractions(var mock) {
714-
if (mock._realCalls.isNotEmpty) {
715-
fail("No interaction expected, but following found: " +
716-
mock._realCalls.join());
721+
if (mock is Mock) {
722+
if (mock._realCalls.isNotEmpty) {
723+
fail("No interaction expected, but following found: " +
724+
mock._realCalls.join());
725+
}
726+
} else {
727+
_throwMockArgumentError('verifyZeroInteractions');
717728
}
718729
}
719730

pkgs/mockito/test/mockito_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,11 @@ void main() {
936936
verify(mock.methodWithoutArgs());
937937
verifyNoMoreInteractions(mock);
938938
});
939+
940+
test("throws if given a real object", () {
941+
expect(
942+
() => verifyNoMoreInteractions(new RealClass()), throwsArgumentError);
943+
});
939944
});
940945

941946
group("verifyInOrder()", () {

0 commit comments

Comments
 (0)