@@ -6,7 +6,6 @@ import 'dart:convert';
66import 'dart:io' ;
77
88import 'package:http/http.dart' ;
9- import 'package:mockito/mockito.dart' ;
109import 'package:quiver/time.dart' ;
1110import 'package:sentry/sentry.dart' ;
1211import 'package:test/test.dart' ;
@@ -32,12 +31,17 @@ void main() {
3231 String postUri;
3332 Map <String , String > headers;
3433 List <int > body;
35- when (httpMock.post (any, headers: any, body: any))
36- .thenAnswer ((Invocation invocation) {
37- postUri = invocation.positionalArguments.single;
38- headers = invocation.namedArguments[#headers];
39- body = invocation.namedArguments[#body];
40- return new Response ('{"id": "test-event-id"}' , 200 );
34+ httpMock.answerWith ((Invocation invocation) {
35+ if (invocation.memberName == #close) {
36+ return null ;
37+ }
38+ if (invocation.memberName == #post) {
39+ postUri = invocation.positionalArguments.single;
40+ headers = invocation.namedArguments[#headers];
41+ body = invocation.namedArguments[#body];
42+ return new Response ('{"id": "test-event-id"}' , 200 );
43+ }
44+ fail ('Unexpected invocation of ${invocation .memberName } in HttpMock' );
4145 });
4246
4347 final SentryClient client = new SentryClient (
@@ -79,13 +83,13 @@ void main() {
7983
8084 expect (headers, expectedHeaders);
8185
82- Map <String , dynamic > json ;
86+ Map <String , dynamic > data ;
8387 if (compressPayload) {
84- json = JSON .decode (UTF8 .decode (GZIP .decode (body)));
88+ data = json .decode (utf8 .decode (GZIP .decode (body)));
8589 } else {
86- json = JSON .decode (UTF8 .decode (body));
90+ data = json .decode (utf8 .decode (body));
8791 }
88- final Map <String , dynamic > stacktrace = json .remove ('stacktrace' );
92+ final Map <String , dynamic > stacktrace = data .remove ('stacktrace' );
8993 expect (stacktrace['frames' ], const isInstanceOf <List >());
9094 expect (stacktrace['frames' ], isNotEmpty);
9195
@@ -98,7 +102,7 @@ void main() {
98102 expect (topFrame['in_app' ], true );
99103 expect (topFrame['filename' ], 'sentry_test.dart' );
100104
101- expect (json , {
105+ expect (data , {
102106 'project' : '1' ,
103107 'event_id' : 'X' * 32 ,
104108 'timestamp' : '2017-01-02T00:00:00' ,
@@ -128,11 +132,16 @@ void main() {
128132 final MockClient httpMock = new MockClient ();
129133 final Clock fakeClock = new Clock .fixed (new DateTime (2017 , 1 , 2 ));
130134
131- when (httpMock.post (any, headers: any, body: any))
132- .thenAnswer ((Invocation invocation) {
133- return new Response ('' , 401 , headers: < String , String > {
134- 'x-sentry-error' : 'Invalid api key' ,
135- });
135+ httpMock.answerWith ((Invocation invocation) {
136+ if (invocation.memberName == #close) {
137+ return null ;
138+ }
139+ if (invocation.memberName == #post) {
140+ return new Response ('' , 401 , headers: < String , String > {
141+ 'x-sentry-error' : 'Invalid api key' ,
142+ });
143+ }
144+ fail ('Unexpected invocation of ${invocation .memberName } in HttpMock' );
136145 });
137146
138147 final SentryClient client = new SentryClient (
@@ -199,4 +208,16 @@ void main() {
199208 });
200209}
201210
202- class MockClient extends Mock implements Client {}
211+ typedef Answer = dynamic Function (Invocation invocation);
212+
213+ class MockClient implements Client {
214+ Answer _answer;
215+
216+ void answerWith (Answer answer) {
217+ _answer = answer;
218+ }
219+
220+ noSuchMethod (Invocation invocation) {
221+ return _answer (invocation);
222+ }
223+ }
0 commit comments