Only print non-verified calls when calling verifyNever.

I have a tests that calls the mock > 50times and it's super hard to read through all the calls to find the one that triggered failure. With this I just see the unexpected calls.

#dart #testing #mockito

PiperOrigin-RevId: 298644968
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d485e1..cfe10bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,6 @@
   clients who use the Mock class in unconventional ways, such as overriding
   `noSuchMethod` on a class which extends Mock. To fix, or prepare such code,
   add a second parameter to such overriding `noSuchMethod` declaration.
-* Increase minimum Dart SDK to `2.4.0`.
 
 ## 4.1.1
 
diff --git a/lib/src/mock.dart b/lib/src/mock.dart
index 6552a1d..5d5afc4 100644
--- a/lib/src/mock.dart
+++ b/lib/src/mock.dart
@@ -154,8 +154,9 @@
   @override
   String toString() => _givenName ?? runtimeType.toString();
 
-  String _realCallsToString() {
-    var stringRepresentations = _realCalls.map((call) => call.toString());
+  String _realCallsToString([Iterable<RealCall> realCalls]) {
+    var stringRepresentations =
+        (realCalls ?? _realCalls).map((call) => call.toString());
     if (stringRepresentations.any((s) => s.contains('\n'))) {
       // As each call contains newlines, put each on its own line, for better
       // readability.
@@ -165,6 +166,9 @@
       return stringRepresentations.join(', ');
     }
   }
+
+  String _unverifiedCallsToString() =>
+      _realCallsToString(_realCalls.where((call) => !call.verified));
 }
 
 /// Extend or mixin this class to mark the implementation as a [Fake].
@@ -666,8 +670,8 @@
           '`verifyNever(...);`.)');
     }
     if (never && matchingInvocations.isNotEmpty) {
-      var calls = mock._realCallsToString();
-      fail('Unexpected calls. All calls: $calls');
+      var calls = mock._unverifiedCallsToString();
+      fail('Unexpected calls: $calls');
     }
     matchingInvocations.forEach((inv) {
       inv.verified = true;
diff --git a/pubspec.yaml b/pubspec.yaml
index f89993c..e76d7aa 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,11 +1,15 @@
 name: mockito
 version: 4.1.2-dev
 
+authors:
+  - Dmitriy Fibulwinter <fibulwinter@gmail.com>
+  - Dart Team <misc@dartlang.org>
+
 description: A mock framework inspired by Mockito.
 homepage: https://github.com/dart-lang/mockito
 
 environment:
-  sdk: '>=2.4.0 <3.0.0'
+  sdk: '>=2.3.0 <3.0.0'
 
 dependencies:
   analyzer: ^0.38.0
diff --git a/test/verify_test.dart b/test/verify_test.dart
index 7622a2b..c66d325 100644
--- a/test/verify_test.dart
+++ b/test/verify_test.dart
@@ -362,9 +362,13 @@
       });
 
       test('one fails', () {
+        // Add one verified method that should not appear in message.
+        mock.methodWithNormalArgs(1);
+        verify(mock.methodWithNormalArgs(1)).called(1);
+
         mock.methodWithoutArgs();
         expectFail(
-            'Unexpected calls. All calls: _MockedClass.methodWithoutArgs()',
+            'Unexpected calls: _MockedClass.methodWithoutArgs()',
             () {
           verifyNever(mock.methodWithoutArgs());
         });