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 of class with mixin that overrides operator #437

Open
0biWanKenobi opened this issue Jun 25, 2021 · 2 comments
Open
Labels
P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@0biWanKenobi
Copy link

I am using Mockito 5.0.10, and I do have read about various fixes regarding operators override:

However, I'm still having issues when using EquatableMixin from the package Equatable.

I have a class like this:

class AuctionLot {
   final int fie;   
}


class AuctionLotDetail extends Foo with EquatableMixin{
 final int fee;
}

EquatableMixin overrides the equality operator, and Mockito doesn't seem to handle that well:

test/mocks_repository.mocks.dart:53:7: Error: The implementation of '==' in the non-abstract class '_FakeAuctionLotDetail' does not conform to its interface.
class _FakeAuctionLotDetail extends _i1.Fake implements _i5.AuctionLotDetail {}
      ^^^^^^^^^^^^^^^^^^^^^
org-dartlang-sdk:///third_party/dart/sdk/lib/_internal/vm/lib/object_patch.dart:21:27: Context: The parameter 'other' of the method 'Object.==' has type 'Object', which does not match the corresponding type, 'Object?', in the overridden method, 'AuctionLot with EquatableMixin.=='.
 - 'Object' is from 'dart:core'.
Change to a supertype of 'Object?', or, for a covariant parameter, a subtype.
  bool operator ==(Object other) native "Object_equals";
                          ^
lib/model/auction_lot_detail.dart:8:7: Context: This is the overridden method ('==').
class AuctionLotDetail extends AuctionLot with EquatableMixin {
      ^
test/mocks_repository.mocks.dart:101:7: Error: The implementation of '==' in the non-abstract class 'MockAuctionLotDetail' does not conform to its interface.
class MockAuctionLotDetail extends _i1.Mock implements _i5.AuctionLotDetail {
      ^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter_2.0.6/.pub-cache/hosted/pub.dartlang.org/mockito-5.0.10/lib/src/mock.dart:196:20: Context: The parameter 'other' of the method 'Mock.==' has type 'Object', which does not match the corresponding type, 'Object?', in the overridden method, 'AuctionLot with EquatableMixin.=='.
 - 'Object' is from 'dart:core'.
Change to a supertype of 'Object?', or, for a covariant parameter, a subtype.

The generated Fakes:

class _FakeAuctionLotDetail extends _i1.Fake implements _i4.AuctionLotDetail {}

The generated Mock:

/// A class which mocks [AuctionLotDetail].
///
/// See the documentation for Mockito's code generation for more information.
class MockAuctionLotDetail extends _i1.Mock implements _i5.AuctionLotDetail {
  MockAuctionLotDetail() {
    _i1.throwOnMissingStub(this);
  }

[.. all the prop overrides omitted for brevity]

  @override
  String toString() => super.toString();
}
@srawlins
Copy link
Member

srawlins commented Jul 2, 2021

The workaround is to upgrade to equatable 2.0.3 which uses non-nullable Object as the parameter to ==.

@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 2, 2021
@0biWanKenobi
Copy link
Author

I already use equatable 2.0.3, but that hasn't helped

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