dart-lang / mockito

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

Change `== null` to `is T` to handle "double nullable" case #705

Closed copybara-service[bot] closed 11 months ago

copybara-service[bot] commented 11 months ago

Change == null to is T to handle "double nullable" case

We use dummyValueOrNull<T>/ifNotNull combination to return a proper Future<T> when T is not known at compile time but a dummy value for T exists at run time, instead of falling back to creating a FakeFuture (that can't be awaited for example).

This works fine unless T itself allows null (is nullable or void). In this case dummyValueOrNull<T> returns null, but it's a proper T, not a failure. This CL changes ifNotNull to check is T instead of == null to handle this properly.