@@ -935,6 +935,39 @@ void main() {
935935 expect (mocksContent, contains ('returnValue: _i3.mShim<T>(a: a),' ));
936936 });
937937
938+ test (
939+ 'generates mock classes including a fallback generator and '
940+ 'OnMissingStub.returnDefault' , () async {
941+ var mocksContent = await buildWithNonNullable ({
942+ ...annotationsAsset,
943+ 'foo|lib/foo.dart' : dedent (r'''
944+ abstract class Foo<T> {
945+ T get f;
946+ }
947+ ''' ),
948+ 'foo|test/foo_test.dart' : '''
949+ import 'package:foo/foo.dart';
950+ import 'package:mockito/annotations.dart';
951+
952+ T fShim<T>() {
953+ throw 'unknown';
954+ }
955+
956+ @GenerateMocks(
957+ [],
958+ customMocks: [
959+ MockSpec<Foo>(
960+ fallbackGenerators: {#f: fShim},
961+ onMissingStub: OnMissingStub.returnDefault),
962+ ],
963+ )
964+ void main() {}
965+ '''
966+ });
967+ expect (mocksContent, contains ('returnValue: _i3.fShim(),' ));
968+ expect (mocksContent, contains ('returnValueForMissingStub: _i3.fShim(),' ));
969+ });
970+
938971 test (
939972 'throws when GenerateMocks is given a class with a type parameter with a '
940973 'private bound' , () async {
@@ -1265,7 +1298,36 @@ void main() {
12651298 '''
12661299 });
12671300 expect (mocksContent, isNot (contains ('throwOnMissingStub' )));
1268- expect (mocksContent, contains ('returnValueForMissingStub:' ));
1301+ expect (mocksContent, contains ('returnValue: 0' ));
1302+ expect (mocksContent, contains ('returnValueForMissingStub: 0' ));
1303+ });
1304+
1305+ test (
1306+ 'generates a mock class which uses the new behavior of returning '
1307+ 'a valid value for missing stubs, if GenerateNiceMocks and '
1308+ 'fallbackGenerators were used' , () async {
1309+ var mocksContent = await buildWithNonNullable ({
1310+ ...annotationsAsset,
1311+ 'foo|lib/foo.dart' : dedent (r'''
1312+ class Foo<T> {
1313+ int m();
1314+ }
1315+ ''' ),
1316+ 'foo|test/foo_test.dart' : '''
1317+ import 'package:foo/foo.dart';
1318+ import 'package:mockito/annotations.dart';
1319+
1320+ int mShim() {
1321+ return 1;
1322+ }
1323+
1324+ @GenerateNiceMocks([MockSpec<Foo>(fallbackGenerators: {#m: mShim})])
1325+ void main() {}
1326+ '''
1327+ });
1328+ expect (mocksContent, isNot (contains ('throwOnMissingStub' )));
1329+ expect (mocksContent, contains ('returnValue: _i3.mShim(),' ));
1330+ expect (mocksContent, contains ('returnValueForMissingStub: _i3.mShim(),' ));
12691331 });
12701332
12711333 test ('mixed GenerateMocks and GenerateNiceMocks annotations could be used' ,
0 commit comments