diff --git a/CHANGELOG.md b/CHANGELOG.md index a9263a91..e6fae870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 5.0.12-dev + +* Use an empty list with a correct type argument for a fallback value for a + method which returns Iterable. + [#445](https://github.com/dart-lang/mockito/issues/445) + ## 5.0.11 * Allow two mocks of the same class (with different type arguments) to be diff --git a/lib/src/builder.dart b/lib/src/builder.dart index 5e23b428..4a4ed2aa 100644 --- a/lib/src/builder.dart +++ b/lib/src/builder.dart @@ -1075,26 +1075,24 @@ class _MockClassInfo { .call(futureValueArguments); } else if (type.isDartCoreInt) { return literalNum(0); - } else if (type.isDartCoreIterable) { - return literalList([]); - } else if (type.isDartCoreList) { + } else if (type.isDartCoreIterable || type.isDartCoreList) { assert(typeArguments.length == 1); - var elementType = _typeReference(typeArguments[0]); + final elementType = _typeReference(typeArguments[0]); return literalList([], elementType); } else if (type.isDartCoreMap) { assert(typeArguments.length == 2); - var keyType = _typeReference(typeArguments[0]); - var valueType = _typeReference(typeArguments[1]); + final keyType = _typeReference(typeArguments[0]); + final valueType = _typeReference(typeArguments[1]); return literalMap({}, keyType, valueType); } else if (type.isDartCoreNum) { return literalNum(0); } else if (type.isDartCoreSet) { assert(typeArguments.length == 1); - var elementType = _typeReference(typeArguments[0]); + final elementType = _typeReference(typeArguments[0]); return literalSet({}, elementType); } else if (type.element.declaration == typeProvider.streamElement) { assert(typeArguments.length == 1); - var elementType = _typeReference(typeArguments[0]); + final elementType = _typeReference(typeArguments[0]); return TypeReference((b) { b ..symbol = 'Stream' diff --git a/lib/src/version.dart b/lib/src/version.dart index 546ddda8..32a586d7 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1 +1 @@ -const packageVersion = '5.0.11'; +const packageVersion = '5.0.12-dev'; diff --git a/pubspec.yaml b/pubspec.yaml index ee9b6432..f1668b25 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: mockito -version: 5.0.11 +version: 5.0.12-dev 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 35fa05ce..7550357d 100644 --- a/test/builder/auto_mocks_test.dart +++ b/test/builder/auto_mocks_test.dart @@ -120,7 +120,8 @@ void main() { /// Test [MockBuilder] on a single source file, in a package which has opted /// into null safety, and with the non-nullable experiment enabled. - Future expectSingleNonNullableOutput(String sourceAssetText, + Future expectSingleNonNullableOutput( + String sourceAssetText, /*String|Matcher>*/ Object output) async { await testWithNonNullable({ ...metaAssets, @@ -554,7 +555,7 @@ void main() { '''), _containsAllOf(dedent2(''' Iterable m() => - (super.noSuchMethod(Invocation.method(#m, []), returnValue: []) + (super.noSuchMethod(Invocation.method(#m, []), returnValue: []) as Iterable); ''')), ); @@ -1950,8 +1951,8 @@ void main() { }); test( - 'creates dummy non-null return values for Futures of known generic core classes', - () async { + 'creates dummy non-null return values for Futures of known generic core ' + 'classes', () async { await expectSingleNonNullableOutput( dedent(r''' class Foo { @@ -1961,7 +1962,7 @@ void main() { _containsAllOf(dedent2(''' _i3.Future> m() => (super.noSuchMethod(Invocation.method(#m, []), - returnValue: Future>.value([])) + returnValue: Future>.value([])) as _i3.Future>); ''')), );