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

Fix missing interface's fields and methods in builder #404

Conversation

markgravity
Copy link
Contributor

Steps to Reproduce

abstract class DemoDelegate {
  String get title;
  void show();
}

abstract class DemoClass implements DemoDelegate {
  String get description;

  void close();
}

@GenerateMocks([DemoClass])
void main() {}

Expected

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

  @override
  String get description =>
      (super.noSuchMethod(Invocation.getter(#description), returnValue: '')
          as String);
  @override
  String get title =>
      (super.noSuchMethod(Invocation.getter(#title), returnValue: '')
          as String);
  @override
  void close() => super.noSuchMethod(Invocation.method(#close, []),
      returnValueForMissingStub: null);
  @override
  void show() => super.noSuchMethod(Invocation.method(#show, []),
      returnValueForMissingStub: null);
}

Actual

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

  @override
  String get description =>
      (super.noSuchMethod(Invocation.getter(#description), returnValue: '')
          as String);
  @override
  void close() => super.noSuchMethod(Invocation.method(#close, []),
      returnValueForMissingStub: null);
}

@google-cla google-cla bot added the cla: yes label May 5, 2021
@srawlins
Copy link
Member

srawlins commented May 5, 2021

This is an interesting case. Do you have a real use case like what you described? I honestly didn't know that a class like DemoClass was legal.

@markgravity
Copy link
Contributor Author

This is an interesting case. Do you have a real use case like what you described? I honestly didn't know that a class like DemoClass was legal.

Yea. I faced it in my repo

My LandingViewDelegate is an abstract class that implements AlertViewMixinDelegate
So my expectation that MockLandingViewDelegate should contain fields and methods from AlertViewMixinDelegate

@srawlins
Copy link
Member

srawlins commented May 5, 2021

Cool, it makes sense to me. Could you add some tests in auto_mocks_test? Maybe just one for methods and one for fields.

@markgravity
Copy link
Contributor Author

Cool, it makes sense to me. Could you add some tests in auto_mocks_test? Maybe just one for methods and one for fields.

Sure. Let's me update it now 👍

@markgravity markgravity force-pushed the bug/missing-interface-fields-and-methods branch from 3e6b43b to 677d6f9 Compare May 8, 2021 03:53
@markgravity
Copy link
Contributor Author

@srawlins I added 2 tests into auto_mocks_test 👌

@srawlins
Copy link
Member

Apologies for letting this languish; can you reformat auto_mocks_test, as CI complains about it?

@markgravity markgravity force-pushed the bug/missing-interface-fields-and-methods branch from 677d6f9 to 1126084 Compare May 20, 2021 08:24
@markgravity
Copy link
Contributor Author

Apologies for letting this languish; can you reformat auto_mocks_test, as CI complains about it?

Done it! 👌

@srawlins srawlins merged commit 4809c09 into dart-lang:master May 20, 2021
@srawlins
Copy link
Member

Thanks much!

srawlins added a commit that referenced this pull request May 24, 2021
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
srawlins added a commit that referenced this pull request May 25, 2021
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
srawlins added a commit that referenced this pull request May 25, 2021
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
srawlins added a commit that referenced this pull request May 25, 2021
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
srawlins added a commit that referenced this pull request May 25, 2021
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
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

Successfully merging this pull request may close these issues.

None yet

2 participants