Skip to content

'Object.==' ('bool Function(Object)') #354

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

Closed
radvansky-tomas opened this issue Mar 10, 2021 · 8 comments
Closed

'Object.==' ('bool Function(Object)') #354

radvansky-tomas opened this issue Mar 10, 2021 · 8 comments

Comments

@radvansky-tomas
Copy link

I see this a lot when I am trying to mock firebase libs:

'Object.==' ('bool Function(Object)') isn't a valid concrete implementation of 'Reference.==' ('bool Function(Object?)').

And thats because of their:

 @override
  bool operator ==(Object? other) =>
      other is Reference &&
      other.fullPath == fullPath &&
      other.storage == storage;

Any idea how to use generator for such thing ?

@srawlins
Copy link
Member

Oooh yikes. That's not great. Object.== indeed accepts a non-nullable Object as an argument. It is a bit strange that Reference would expand that parameter type to be Object?. I don't think we can or perhaps should support mocking classes which change the types of Object's method parameters...

@radvansky-tomas
Copy link
Author

Thats not only reference, there are plenty classes under flutter fire, which has same issue this is documentReference:

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  bool operator ==(dynamic other) =>
      other is DocumentReference &&
      other.firestore == firestore &&
      other.path == path;

A saw more with storage, etc..

@srawlins
Copy link
Member

I suggest opening bugs against those packages, perhaps asking why they expanded the parameter type on the == operator. It may be accidental.

@srawlins
Copy link
Member

srawlins commented Jun 7, 2021

This should be fixed in mockito 5.0.10.

@srawlins srawlins closed this as completed Jun 7, 2021
@MoustafaMesbah
Copy link

issue still existed in mockito 5.0.10

@cedvdb
Copy link

cedvdb commented Aug 9, 2021

on 5.0.14 it is an issue when trying to mock just_audio AudioPlayer

@Samin-youki
Copy link

Samin-youki commented Dec 6, 2021

@srawlins any update on this?
the issue exist on version 5.0.15
'Object.==' ('bool Function(Object)') isn't a valid concrete implementation of 'EtherAmount.==' ('bool Function(dynamic)')
trying to mock the web3dart client.

@ihorvitruk
Copy link

ihorvitruk commented Jan 23, 2022

@srawlins I have the same issue with google_sign_in plugin.

 class MockGoogleSignInAccount_ extends _i1.Mock 'Mock.==' ('bool Function(Object)') isn't a valid concrete implementation of
                                                    'GoogleSignInAccount.==' ('bool Function(dynamic)'). #invalid_implementation_override

This is because == operator takes dynamic argument for GoogleSignInAccount class:

@override
  bool operator ==(dynamic other) {
    ...

Insight: It (generated mock) used to work until I performed migration of the package to null-safety.

@Samin-youki The workaround is to temporarily use stub for your EtherAmount with override == and hashCode:

class _TestEtherAmount implements EtherAmount {
 @override
  bool operator ==(dynamic other) => super == other;

  @override
  int get hashCode => super.hashCode;

  ...

github-actions bot pushed a commit to gnoliyil/fuchsia that referenced this issue Aug 14, 2022
The base method[0] accepts Object, and using dynamic is apparently
hostile to mockito[1], which is used downstream.

[0] https://api.dart.dev/stable/2.12.0/dart-core/Object/operator_equals.html
[1] dart-lang/mockito#354

Change-Id: I0cd6f1a8ad4fccf41f0671d774a0694fa2d28e6a
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/712023
API-Review: Adam Barth <[email protected]>
Fuchsia-Auto-Submit: Tamir Duberstein <[email protected]>
Reviewed-by: Adam Barth <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants