Skip to content
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

Cannot generate mock for a class that extends GetxController #456

Closed
jimbengtsson92 opened this issue Jul 27, 2021 · 1 comment
Closed
Assignees
Labels
P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jimbengtsson92
Copy link

When generating a mock for a class that extends GetxController, the generated file contains the following error:

'MockTestControllerToMock.addListener' ('void Function(void Function()?)') isn't a valid override of 'ListNotifierMixin.addListener' ('void Function() Function(void Function())')

Minimal GitHub repo that shows the error.

Screenshot 2021-07-27 at 14 50 16

@srawlins
Copy link
Member

srawlins commented Jul 29, 2021

Here's the type hierarchy:

class Listenable {
  void addListener(VoidCallback listener) { /*...*/ }
}

mixin ListenableMixin implements Listenable {}
mixin ListNotifierMixin on ListenableMixin {
  @override
  Disposer addListener(GetStateUpdate listener) { /*...*/ }
}

abstract class GetxController extends DisposableInterface
    with ListenableMixin, ListNotifierMixin { /*...*/ }

Mockito appears to be going for the overridden signature, instead of the proper signature.

@srawlins srawlins self-assigned this Jul 29, 2021
@srawlins srawlins added P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 29, 2021
srawlins added a commit that referenced this issue Jul 30, 2021
…rarchy.

Previously, mixins were being applied in the wrong order. By using analyzer's InheritanceManager3, instead of my homespun inheritance-walking algorithm, we
solve this problem, and perhaps other unreported issues.

Fixes #456

PiperOrigin-RevId: 387741287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants