File tree 9 files changed +92
-58
lines changed
9 files changed +92
-58
lines changed Original file line number Diff line number Diff line change
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
+
1
8
## 1.0.1
2
9
3
10
* Add a new ` thenThrow ` method to the API.
Original file line number Diff line number Diff line change
1
+ export 'mockito.dart' ;
2
+ export 'src/spy.dart' show spy;
Original file line number Diff line number Diff line change 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;
Original file line number Diff line number Diff line change 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;
5
3
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' ;
Original file line number Diff line number Diff line change 1
1
// 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.
4
3
5
4
import 'package:meta/meta.dart' ;
6
5
import 'package:test/test.dart' ;
Original file line number Diff line number Diff line change 1
1
// 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.
3
3
import 'dart:mirrors' ;
4
4
5
- import 'mock.dart' show CannedResponse, setDefaultResponse;
5
+ import 'mock.dart' show CannedResponse, Mock, setDefaultResponse;
6
6
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);
9
15
setDefaultResponse (
10
16
mock,
11
17
() => new CannedResponse (null ,
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ void main() {
54
54
var call2 = stub.value;
55
55
stub.value = true ;
56
56
var call3 = Stub .lastInvocation;
57
- shouldPass (call1, isInvocation (call2));
57
+ shouldPass (call1, isInvocation (call2 as Invocation ));
58
58
shouldFail (
59
59
call1,
60
60
isInvocation (call3),
Original file line number Diff line number Diff line change
1
+ import 'package:mockito/mockito.dart' ;
2
+ import 'package:mockito/src/mock.dart' show resetMockitoState;
1
3
import 'package:test/test.dart' ;
2
4
3
- import 'package:mockito/src/mock.dart' ;
4
- import 'package:mockito/src/spy.dart' ;
5
-
6
5
class RealClass {
7
6
String methodWithoutArgs () => "Real" ;
8
7
String methodWithNormalArgs (int x) => "Real" ;
@@ -69,24 +68,6 @@ void main() {
69
68
resetMockitoState ();
70
69
});
71
70
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
-
90
71
group ("mixin support" , () {
91
72
test ("should work" , () {
92
73
var foo = new MockFoo ();
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments