Support Function and Future<Function> return types
Without this support, mockito tried to create a FakeFunction which implemented Function, which is not allowed.
Fixes https://github.com/dart-lang/mockito/issues/442
PiperOrigin-RevId: 384852004
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac0bc1d..a9263a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,11 @@
-## 5.0.11-dev
+## 5.0.11
* Allow two mocks of the same class (with different type arguments) to be
specified with different fallback generators.
* Allow fallback generators on super types of a mocked class.
+* Avoid `inference_failure_on_instance_creation` errors in generated code.
+* Ignore `implementation_imports` lint in generated code.
+* Support methods with `Function` and `Future<Function>` return types.
## 5.0.10
diff --git a/lib/src/builder.dart b/lib/src/builder.dart
index 0b23589..5e23b42 100644
--- a/lib/src/builder.dart
+++ b/lib/src/builder.dart
@@ -1062,6 +1062,8 @@
return literalFalse;
} else if (type.isDartCoreDouble) {
return literalNum(0.0);
+ } else if (type.isDartCoreFunction) {
+ return refer('() {}');
} else if (type.isDartAsyncFuture || type.isDartAsyncFutureOr) {
final typeArgument = typeArguments.first;
final futureValueArguments =
diff --git a/lib/src/version.dart b/lib/src/version.dart
index 1b9e3c1..546ddda 100644
--- a/lib/src/version.dart
+++ b/lib/src/version.dart
@@ -1 +1 @@
-const packageVersion = '5.0.10';
+const packageVersion = '5.0.11';
diff --git a/pubspec.yaml b/pubspec.yaml
index 0f1b805..ee9b643 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: mockito
-version: 5.0.10
+version: 5.0.11
description: >-
A mock framework inspired by Mockito with APIs for Fakes, Mocks,
diff --git a/test/builder/auto_mocks_test.dart b/test/builder/auto_mocks_test.dart
index a1aaa60..35fa05c 100644
--- a/test/builder/auto_mocks_test.dart
+++ b/test/builder/auto_mocks_test.dart
@@ -1898,6 +1898,22 @@
);
});
+ test(
+ 'creates dummy non-null return values for Futures of core Function class',
+ () async {
+ await expectSingleNonNullableOutput(
+ dedent('''
+ abstract class Foo {
+ Future<Function> m();
+ }
+ '''),
+ _containsAllOf(dedent2('''
+ _i3.Future<Function> m() => (super.noSuchMethod(Invocation.method(#m, []),
+ returnValue: Future<Function>.value(() {})) as _i3.Future<Function>);
+ ''')),
+ );
+ });
+
test('creates dummy non-null return values for Futures of nullable types',
() async {
await expectSingleNonNullableOutput(