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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,11 @@ class _MockLibraryInfo {
yield* fieldOverrides(mixin, overriddenFields);
}
}
if (type.interfaces != null) {
for (var interface in type.interfaces) {
yield* fieldOverrides(interface, overriddenFields);
}
}
var superclass = type.superclass;
if (superclass != null && !superclass.isDartCoreObject) {
yield* fieldOverrides(superclass, overriddenFields);
Expand Down Expand Up @@ -802,6 +807,11 @@ class _MockLibraryInfo {
yield* methodOverrides(mixin, overriddenMethods);
}
}
if (type.interfaces != null) {
for (var interface in type.interfaces) {
yield* methodOverrides(interface, overriddenMethods);
}
}
var superclass = type.superclass;
if (superclass != null && !superclass.isDartCoreObject) {
yield* methodOverrides(superclass, overriddenMethods);
Expand Down
31 changes: 31 additions & 0 deletions test/builder/auto_mocks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,37 @@ void main() {
);
});

test('contains methods of implemented classes', () async {
await expectSingleNonNullableOutput(
dedent(r'''
class Interface<T> {
void m(T a) {}
}
class Foo implements Interface<int> {}
'''),
_containsAllOf(
'void m(int? a) => super.noSuchMethod(Invocation.method(#m, [a])'),
);
});

test('contains fields of implemented classes', () async {
await expectSingleNonNullableOutput(
dedent(r'''
class Interface<T> {
int m;
}
class Foo implements Interface<int> {}
'''),
_containsAllOf(dedent2('''
int get m =>
(super.noSuchMethod(Invocation.getter(#m), returnValue: 0) as int);
'''), dedent2('''
set m(int? _m) => super
.noSuchMethod(Invocation.setter(#m, _m), returnValueForMissingStub: null);
''')),
);
});

test(
'overrides methods of indirect generic super classes, substituting types',
() async {
Expand Down