File tree Expand file tree Collapse file tree 9 files changed +92
-58
lines changed Expand file tree Collapse file tree 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+
18## 1.0.1
29
310* 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;
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' ;
Original file line number Diff line number Diff line change 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
54import 'package:meta/meta.dart' ;
65import 'package:test/test.dart' ;
Original file line number Diff line number Diff line change 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.
33import '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 ,
Original file line number Diff line number Diff 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),
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;
13import 'package:test/test.dart' ;
24
3- import 'package:mockito/src/mock.dart' ;
4- import 'package:mockito/src/spy.dart' ;
5-
65class 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 ();
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