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

Enable MockSpec superclasses #728

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ build/
coverage/

# ignore generated mocks
**/*.mocks.dart
**/*.mocks.dart

# ide folders
.idea
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.4.5-wip

* Allow usage of GetMock superclasses.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Allow usage of GetMock superclasses.
* Allow usage of MockSpec subclasses.


## 5.4.4

* Use `posix` style for local imports.
Expand Down
11 changes: 8 additions & 3 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ class _MockTargetGatherer {
int index,
List<ast.CollectionElement> mockSpecAsts,
{bool nice = false}) {
// need to get the parent until type name is not MockSpec to allow inheritance
while (mockSpec.type?.element?.name != "MockSpec") {
mockSpec = mockSpec.getField("(super)")!;
}

final mockSpecType = mockSpec.type as analyzer.InterfaceType;
assert(mockSpecType.typeArguments.length == 1);
final mockType = _mockType(mockSpecAsts[index]);
Expand Down Expand Up @@ -681,10 +686,10 @@ class _MockTargetGatherer {
throw InvalidMockitoAnnotationException(
'The GenerateNiceMocks "mockSpecs" argument is missing');
}
final mockSpecAsts = _niceMocksAst(annotation.annotationAst).elements;
final mockSpecAsts =
_niceMocksAst(annotation.annotationAst).elements.toList();
return mockSpecsField.toListValue()!.mapIndexed((index, mockSpec) =>
_mockTargetFromMockSpec(
mockSpec, entryLib, index, mockSpecAsts.toList(),
_mockTargetFromMockSpec(mockSpec, entryLib, index, mockSpecAsts,
nice: true));
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mockito
version: 5.4.4
version: 5.4.5-wip
description: >-
A mock framework inspired by Mockito with APIs for Fakes, Mocks,
behavior verification, and stubbing.
Expand Down