Skip to content

Commit

Permalink
Import #605
Browse files Browse the repository at this point in the history
Latest build_web_compilers, move to pkg:lints, fix breaks

PiperOrigin-RevId: 511423456
  • Loading branch information
srawlins authored and natebosch committed Mar 23, 2023
1 parent ed5bd84 commit 7e925c3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Require analyzer 5.2.0.
* Fix nice mocks generation in mixed mode (generated code is pre null-safety,
while mocked class is null-safe).
* Require Dart >= 2.18.0.
* Require Dart >= 2.17.0.
* Support typedef-aliased classes in `@GenerateMocks` and `@GenerateNiceMocks`

## 5.3.2
Expand Down
3 changes: 2 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include: package:lints/recommended.yaml

analyzer:
language:
strict-casts: true
Expand All @@ -7,4 +8,4 @@ linter:
rules:
- comment_references
- test_types_in_equals
- throw_in_finally
- throw_in_finally
5 changes: 5 additions & 0 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,11 @@ class _MockTargetGatherer {
}
final mixinInterfaceType =
_determineDartType(typeToMixin, entryLib.typeProvider);
if (!mixinInterfaceType.interfaces.contains(type)) {
throw InvalidMockitoAnnotationException('The "mixingIn" type, '
'${typeToMixin.getDisplayString(withNullability: false)}, must '
'implement the class to mock, ${typeToMock.getDisplayString(withNullability: false)}');
}
mixins.add(mixinInterfaceType);
}

Expand Down
44 changes: 21 additions & 23 deletions test/builder/custom_mocks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,29 +415,6 @@ void main() {
);
});

test('generates a mock class with a marker mixin', () async {
var mocksContent = await buildWithNonNullable({
...annotationsAsset,
'foo|lib/foo.dart': '''
class Foo {}
class FooMarkerMixin {}
''',
'foo|test/foo_test.dart': '''
import 'package:foo/foo.dart';
import 'package:mockito/annotations.dart';
@GenerateMocks([], customMocks: [
MockSpec<Foo>(mixingIn: [FooMarkerMixin])
])
void main() {}
'''
});
expect(
mocksContent,
contains(
'class MockFoo extends _i1.Mock with _i2.FooMarkerMixin implements _i2.Foo {'),
);
});

test(
'generates a mock class which uses the old behavior of returning null on '
'missing stubs', () async {
Expand Down Expand Up @@ -1238,6 +1215,27 @@ void main() {
);
});

test('throws when MockSpec mixes in a non-mixinable type', () async {
_expectBuilderThrows(
assets: {
...annotationsAsset,
'foo|lib/foo.dart': dedent('''
class Foo {}
'''),
'foo|test/foo_test.dart': dedent('''
import 'package:mockito/annotations.dart';
import 'package:foo/foo.dart';
@GenerateMocks([], customMocks: [MockSpec<Foo>(mixingIn: [FooMixin])])
void main() {}
mixin FooMixin {}
'''),
},
message: contains(
'The "mixingIn" type, FooMixin, must implement the class to mock, Foo'),
);
});

test('throws when type argument is unknown type', () async {
_expectBuilderThrows(
assets: {
Expand Down

0 comments on commit 7e925c3

Please sign in to comment.