Skip to content
This repository was archived by the owner on Mar 25, 2026. It is now read-only.

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

Merged
srawlins merged 1 commit into
dart-archive:masterfrom
markgravity:bug/missing-interface-fields-and-methods
May 20, 2021
Merged

Fix missing interface's fields and methods in builder#404
srawlins merged 1 commit into
dart-archive:masterfrom
markgravity:bug/missing-interface-fields-and-methods

Conversation

@markgravity
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
Contributor Author

@srawlins I added 2 tests into auto_mocks_test 👌

@srawlins
Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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-archive:master May 20, 2021
@srawlins
Copy link
Copy Markdown
Collaborator

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
mosuem pushed a commit to dart-lang/test that referenced this pull request Oct 17, 2024
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
davidmorgan pushed a commit to dart-lang/build that referenced this pull request Mar 23, 2026
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants