Skip to content

Commit

Permalink
Import #404
Browse files Browse the repository at this point in the history
Fix missing interface's fields and methods in builder

PiperOrigin-RevId: 375105090
  • Loading branch information
srawlins committed May 24, 2021
1 parent 47dc01d commit f19b25c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,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 @@ -843,6 +848,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 @@ -615,6 +615,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

0 comments on commit f19b25c

Please sign in to comment.