Skip to content

Commit 2421d78

Browse files
authored
Merge pull request #42 from matanlurey/flip_api_defaults
Move all mirrors-based API to mirrors.dart
2 parents 9820ba3 + 6975b6e commit 2421d78

9 files changed

+92
-58
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.0.0-dev
2+
3+
* Remove export of `spy` and any `dart:mirrors` based API from
4+
`mockito.dart`. Users may import as `package:mockito/mirrors.dart`
5+
going forward.
6+
* Deprecated `mockito_no_mirrors.dart`; replace with `mockito.dart`.
7+
18
## 1.0.1
29

310
* Add a new `thenThrow` method to the API.

Diff for: lib/mirrors.dart

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export 'mockito.dart';
2+
export 'src/spy.dart' show spy;

Diff for: lib/mockito.dart

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
export 'mockito_no_mirrors.dart';
2-
export 'src/spy.dart' show spy;
1+
export 'src/mock.dart'
2+
show
3+
Mock,
4+
named,
5+
6+
// -- setting behaviour
7+
when,
8+
any,
9+
argThat,
10+
captureAny,
11+
captureThat,
12+
typed,
13+
Answering,
14+
Expectation,
15+
PostExpectation,
16+
17+
// -- verification
18+
verify,
19+
verifyInOrder,
20+
verifyNever,
21+
verifyNoMoreInteractions,
22+
verifyZeroInteractions,
23+
VerificationResult,
24+
Verification,
25+
26+
// -- misc
27+
clearInteractions,
28+
reset,
29+
logInvocations;

Diff for: lib/mockito_no_mirrors.dart

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,4 @@
1-
export 'src/mock.dart'
2-
show
3-
Mock,
4-
named,
1+
@Deprecated('Import "package:mockito/mockito.dart" instead.')
2+
library mockito.mockito_no_mirrors;
53

6-
// -- setting behaviour
7-
when,
8-
any,
9-
argThat,
10-
captureAny,
11-
captureThat,
12-
typed,
13-
Answering,
14-
Expectation,
15-
PostExpectation,
16-
17-
// -- verification
18-
verify,
19-
verifyInOrder,
20-
verifyNever,
21-
verifyNoMoreInteractions,
22-
verifyZeroInteractions,
23-
VerificationResult,
24-
Verification,
25-
26-
// -- misc
27-
clearInteractions,
28-
reset,
29-
logInvocations;
4+
export 'mockito.dart';

Diff for: lib/src/mock.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Warning: Do not import dart:mirrors in this library, as it's exported via
2-
// lib/mockito_no_mirrors.dart, which is used for Dart AOT projects such as
3-
// Flutter.
2+
// lib/mockito.dart, which is used for Dart AOT projects such as Flutter.
43

54
import 'package:meta/meta.dart';
65
import 'package:test/test.dart';

Diff for: lib/src/spy.dart

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// This file is intentionally separated from 'mock.dart' in order to avoid
2-
// bringing in the mirrors dependency into mockito_no_mirrors.dart.
2+
// bringing in the mirrors dependency into mockito.dart.
33
import 'dart:mirrors';
44

5-
import 'mock.dart' show CannedResponse, setDefaultResponse;
5+
import 'mock.dart' show CannedResponse, Mock, setDefaultResponse;
66

7-
dynamic spy(dynamic mock, dynamic spiedObject) {
8-
var mirror = reflect(spiedObject);
7+
/// Sets the default response of [mock] to be delegated to [spyOn].
8+
///
9+
/// __Example use__:
10+
/// var mockAnimal = new MockAnimal();
11+
/// var realAnimal = new RealAnimal();
12+
/// spy(mockAnimal, realAnimal);
13+
/*=E*/ spy/*<E>*/(Mock mock, Object /*=E*/ spyOn) {
14+
var mirror = reflect(spyOn);
915
setDefaultResponse(
1016
mock,
1117
() => new CannedResponse(null,

Diff for: test/invocation_matcher_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void main() {
5454
var call2 = stub.value;
5555
stub.value = true;
5656
var call3 = Stub.lastInvocation;
57-
shouldPass(call1, isInvocation(call2));
57+
shouldPass(call1, isInvocation(call2 as Invocation));
5858
shouldFail(
5959
call1,
6060
isInvocation(call3),

Diff for: test/mockito_test.dart

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import 'package:mockito/mockito.dart';
2+
import 'package:mockito/src/mock.dart' show resetMockitoState;
13
import 'package:test/test.dart';
24

3-
import 'package:mockito/src/mock.dart';
4-
import 'package:mockito/src/spy.dart';
5-
65
class RealClass {
76
String methodWithoutArgs() => "Real";
87
String methodWithNormalArgs(int x) => "Real";
@@ -69,24 +68,6 @@ void main() {
6968
resetMockitoState();
7069
});
7170

72-
group("spy", () {
73-
setUp(() {
74-
mock = spy(new MockedClass(), new RealClass());
75-
});
76-
77-
test("should delegate to real object by default", () {
78-
expect(mock.methodWithoutArgs(), 'Real');
79-
});
80-
test("should record interactions delegated to real object", () {
81-
mock.methodWithoutArgs();
82-
verify(mock.methodWithoutArgs());
83-
});
84-
test("should behave as mock when expectation are set", () {
85-
when(mock.methodWithoutArgs()).thenReturn('Spied');
86-
expect(mock.methodWithoutArgs(), 'Spied');
87-
});
88-
});
89-
9071
group("mixin support", () {
9172
test("should work", () {
9273
var foo = new MockFoo();

Diff for: test/spy_test.dart

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:mockito/src/mock.dart' show resetMockitoState;
2+
import 'package:mockito/mirrors.dart';
3+
import 'package:test/test.dart';
4+
5+
import 'mockito_test.dart' show MockedClass, RealClass;
6+
7+
void main() {
8+
RealClass mock;
9+
10+
setUp(() {
11+
mock = new MockedClass();
12+
});
13+
14+
tearDown(() {
15+
// In some of the tests that expect an Error to be thrown, Mockito's
16+
// global state can become invalid. Reset it.
17+
resetMockitoState();
18+
});
19+
20+
group("spy", () {
21+
setUp(() {
22+
mock = spy/*<RealClass>*/(new MockedClass(), new RealClass());
23+
});
24+
25+
test("should delegate to real object by default", () {
26+
expect(mock.methodWithoutArgs(), 'Real');
27+
});
28+
test("should record interactions delegated to real object", () {
29+
mock.methodWithoutArgs();
30+
verify(mock.methodWithoutArgs());
31+
});
32+
test("should behave as mock when expectation are set", () {
33+
when(mock.methodWithoutArgs()).thenReturn('Spied');
34+
expect(mock.methodWithoutArgs(), 'Spied');
35+
});
36+
});
37+
}

0 commit comments

Comments
 (0)