dart-lang / mockito

Mockito-inspired mock library for Dart
https://pub.dev/packages/mockito
Apache License 2.0
623 stars 160 forks source link

Generate valid functions with optional non-nullable arguments #717

Closed copybara-service[bot] closed 7 months ago

copybara-service[bot] commented 7 months ago

Generate valid functions with optional non-nullable arguments

If a method of a mocked class returns a function with optional yet non-nullable argument, Mockito currently produces something like

(int x, {int y}) => /* doesn't matter */

which is not a valid Dart, since y must either be required or have a default value. required won't fit into the desired type and coming up with a default value is not easy, since it has to be a constant, but dummyValue doesn't always produce one.

Fortunately, we can just widen the type here and make it nullable.