-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmocker_with_custom_mockito_annotation_test.dart
48 lines (41 loc) · 1.51 KB
/
mocker_with_custom_mockito_annotation_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:mockor/mockor.dart';
import 'mocker_with_custom_mockito_annotation_test.mocks.dart';
part 'mocker_with_custom_mockito_annotation_test.mockor.dart';
abstract class MockerWithCustomMockitoUseCase {
void test();
}
abstract class MockerWithCustomMockitoUseCase2 {
void test();
}
@GenerateMocker([MockerWithCustomMockitoUseCase], generateMockitoAnnotation: false)
@GenerateNiceMocks([
MockSpec<MockerWithCustomMockitoUseCase>(),
MockSpec<MockerWithCustomMockitoUseCase>(as: #MockMockerWithCustomMockitoUseCaseRelaxed)
])
T _mock<T extends Object>({bool relaxed = false}) => _$_mock<T>(relaxed: relaxed);
void main() {
test("given MockerWithCustomMockitoUseCase type is provided to both annotations, it can be found",
() {
try {
MockerWithCustomMockitoUseCase useCase1 = _mock();
expect(useCase1, isNotNull);
} on UnimplementedError {
fail("could not find mock but expected it be found");
}
});
test(
"given MockerWithCustomMockitoUseCase2 type is not provided to $GenerateMocker annotation, it cannot be found",
() {
try {
_mock<MockerWithCustomMockitoUseCase2>();
fail("expected exception");
} on UnimplementedError {}
});
test("MockerWithCustomMockitoUseCaseRelaxed gets generated", () {
MockerWithCustomMockitoUseCase useCase = MockMockerWithCustomMockitoUseCaseRelaxed();
useCase.test();
});
}