-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mockito and compatibility with generic methods #155
Comments
One extra itch I hit internally, the latter example can be example if someone writes: when(rpcHandler.any(any)).thenAnswer((_) => new Future.value(new Cat()); ... so we might not want to ban this, perhaps this should just be documented cleanly. |
Is this related to this issue? import 'package:mockito/mockito.dart';
typedef MyHandler<T>(T arg1);
defaultHandler<T>(T arg1) {}
class Foo {
bar<T>({MyHandler<T> arg: defaultHandler}) {}
}
class MockMandrillClient extends Mock implements Foo {}
main() {} When trying to run this "test", I get this exception:
Without mockito, this code works fine. |
@enyo That is a head scratcher; can you do a |
@srawlins I'm running dart
It's quite interesting, because when you remove |
For better or worse, @enyo, this is a Dart SDK bug. dart-lang/sdk#34122 |
I thought that was very likely. Thanks for looking into it! |
Hi, how are you guys doing with this issue? I actually ran into the same problem, I'm using this https://pub.dev/packages/injector and apparently mock classes is having problems with generic types.
and
it would return the same object (the first object type alphabetically) because mock's inability to match generic type arguments. |
We haven't looked into this issue in a long time. It just doesn't seem to crop up. An injector does sound like a case where it might be warranted. One tricky catch to fixing this issue: it will be a breaking change. Where currently a method call would be matched, it may no longer, due to unequal type arguments. |
Potentially off topic tip: A dependency injector is something you really don't want to mock. There shouldn't be any behavior that is tied to something expensive or unstable, and it should be safe to set up a real injector within a test, and shouldn't have the type of side effects to warrant a |
This is supported in v0.3.0 of mocktail in case that helps anyone. |
Related issue was #152.
In Dart2, it is impossible to implement generic methods (correctly) with Mockito.
Specifically:
Unfortunately today we give no helpful hints or documentation. I think we should change this, and in default, in Mockito 4, make it impossible to mock a method with one or more generic type arguments (at least by default). We could start with making this opt-in:
This was just hit (critically) internally, and hidden by DDC whitelisting :(
The text was updated successfully, but these errors were encountered: