@@ -27,6 +27,8 @@ void main() {
27
27
const String path = '/posts' ;
28
28
29
29
late InstabugCustomHttpClient instabugCustomHttpClient;
30
+ late MockHttpClientRequest mockRequest;
31
+ late MockHttpClientResponse mockResponse;
30
32
31
33
setUpAll (() async {
32
34
const MethodChannel ('instabug_flutter' )
@@ -39,6 +41,11 @@ void main() {
39
41
instabugCustomHttpClient = InstabugCustomHttpClient ();
40
42
instabugCustomHttpClient.client = MockHttpClient ();
41
43
instabugCustomHttpClient.logger = MockHttpClientLogger ();
44
+
45
+ mockRequest = MockHttpClientRequest ();
46
+ mockResponse = MockHttpClientResponse ();
47
+
48
+ when < dynamic > (mockRequest.close ()).thenAnswer ((_) async => mockResponse);
42
49
});
43
50
44
51
tearDown (() async {
@@ -49,226 +56,209 @@ void main() {
49
56
() async {
50
57
when < dynamic > (
51
58
(instabugCustomHttpClient.client as MockHttpClient ).getUrl (any))
52
- .thenAnswer ((_) async => MockHttpClientRequest () );
59
+ .thenAnswer ((_) async => mockRequest );
53
60
54
- final request = await instabugCustomHttpClient.getUrl (Uri .parse (url));
55
- final response = await request.close ();
56
- expect (request, isInstanceOf <HttpClientRequest >());
57
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
58
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
59
- .called (1 );
61
+ await instabugCustomHttpClient.getUrl (Uri .parse (url));
62
+
63
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
64
+ verify (
65
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
60
66
});
61
67
62
68
test ('expect instabug custom http client GET to return request and log' ,
63
69
() async {
64
70
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
65
71
.get (any, any, any))
66
- .thenAnswer ((_) async => MockHttpClientRequest () );
72
+ .thenAnswer ((_) async => mockRequest );
67
73
68
- final request = await instabugCustomHttpClient.get (url, port, path);
69
- final response = await request.close ();
70
- expect (request, isInstanceOf <HttpClientRequest >());
71
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
72
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
73
- .called (1 );
74
+ await instabugCustomHttpClient.get (url, port, path);
75
+
76
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
77
+ verify (
78
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
74
79
});
75
80
76
81
test (
77
82
'expect instabug custom http client DELETE URL to return request and log' ,
78
83
() async {
79
84
when < dynamic > (
80
85
(instabugCustomHttpClient.client as MockHttpClient ).deleteUrl (any))
81
- .thenAnswer ((_) async => MockHttpClientRequest () );
86
+ .thenAnswer ((_) async => mockRequest );
82
87
83
- final request = await instabugCustomHttpClient.deleteUrl (Uri .parse (url));
84
- final response = await request.close ();
85
- expect (request, isInstanceOf <HttpClientRequest >());
86
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
87
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
88
- .called (1 );
88
+ await instabugCustomHttpClient.deleteUrl (Uri .parse (url));
89
+
90
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
91
+ verify (
92
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
89
93
});
90
94
91
95
test ('expect instabug custom http client DELETE to return request and log' ,
92
96
() async {
93
97
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
94
98
.delete (any, any, any))
95
- .thenAnswer ((_) async => MockHttpClientRequest () );
99
+ .thenAnswer ((_) async => mockRequest );
96
100
97
- final request = await instabugCustomHttpClient.delete (url, port, path);
98
- final response = await request.close ();
99
- expect (request, isInstanceOf <HttpClientRequest >());
100
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
101
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
102
- .called (1 );
101
+ await instabugCustomHttpClient.delete (url, port, path);
102
+
103
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
104
+ verify (
105
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
103
106
});
104
107
105
108
test ('expect instabug custom http client POST URL to return request and log' ,
106
109
() async {
107
110
when < dynamic > (
108
111
(instabugCustomHttpClient.client as MockHttpClient ).postUrl (any))
109
- .thenAnswer ((_) async => MockHttpClientRequest () );
112
+ .thenAnswer ((_) async => mockRequest );
110
113
111
- final request = await instabugCustomHttpClient.postUrl (Uri .parse (url));
112
- final response = await request.close ();
113
- expect (request, isInstanceOf <HttpClientRequest >());
114
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
115
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
116
- .called (1 );
114
+ await instabugCustomHttpClient.postUrl (Uri .parse (url));
115
+
116
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
117
+ verify (
118
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
117
119
});
118
120
119
121
test ('expect instabug custom http client POST to return request and log' ,
120
122
() async {
121
123
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
122
124
.post (any, any, any))
123
- .thenAnswer ((_) async => MockHttpClientRequest () );
125
+ .thenAnswer ((_) async => mockRequest );
124
126
125
- final request = await instabugCustomHttpClient.post (url, port, path);
126
- final response = await request.close ();
127
- expect (request, isInstanceOf <HttpClientRequest >());
128
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
129
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
130
- .called (1 );
127
+ await instabugCustomHttpClient.post (url, port, path);
128
+
129
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
130
+ verify (
131
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
131
132
});
132
133
133
134
test ('expect instabug custom http client HEAD URL to return request and log' ,
134
135
() async {
135
136
when < dynamic > (
136
137
(instabugCustomHttpClient.client as MockHttpClient ).headUrl (any))
137
- .thenAnswer ((_) async => MockHttpClientRequest () );
138
+ .thenAnswer ((_) async => mockRequest );
138
139
139
- final request = await instabugCustomHttpClient.headUrl (Uri .parse (url));
140
- final response = await request.close ();
141
- expect (request, isInstanceOf <HttpClientRequest >());
142
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
143
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
144
- .called (1 );
140
+ await instabugCustomHttpClient.headUrl (Uri .parse (url));
141
+
142
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
143
+ verify (
144
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
145
145
});
146
146
147
147
test ('expect instabug custom http client HEAD to return request and log' ,
148
148
() async {
149
149
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
150
150
.head (any, any, any))
151
- .thenAnswer ((_) async => MockHttpClientRequest () );
151
+ .thenAnswer ((_) async => mockRequest );
152
152
153
- final request = await instabugCustomHttpClient.head (url, port, path);
154
- final response = await request.close ();
155
- expect (request, isInstanceOf <HttpClientRequest >());
156
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
157
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
158
- .called (1 );
153
+ await instabugCustomHttpClient.head (url, port, path);
154
+
155
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
156
+ verify (
157
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
159
158
});
160
159
161
160
test ('expect instabug custom http client PATCH URL to return request and log' ,
162
161
() async {
163
162
when < dynamic > (
164
163
(instabugCustomHttpClient.client as MockHttpClient ).patchUrl (any))
165
- .thenAnswer ((_) async => MockHttpClientRequest () );
164
+ .thenAnswer ((_) async => mockRequest );
166
165
167
- final request = await instabugCustomHttpClient.patchUrl (Uri .parse (url));
168
- final response = await request.close ();
169
- expect (request, isInstanceOf <HttpClientRequest >());
170
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
171
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
172
- .called (1 );
166
+ await instabugCustomHttpClient.patchUrl (Uri .parse (url));
167
+
168
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
169
+ verify (
170
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
173
171
});
174
172
175
173
test ('expect instabug custom http client PATCH to return request and log' ,
176
174
() async {
177
175
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
178
176
.patch (any, any, any))
179
- .thenAnswer ((_) async => MockHttpClientRequest () );
177
+ .thenAnswer ((_) async => mockRequest );
180
178
181
- final request = await instabugCustomHttpClient.patch (url, port, path);
182
- final response = await request.close ();
183
- expect (request, isInstanceOf <HttpClientRequest >());
184
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
185
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
186
- .called (1 );
179
+ await instabugCustomHttpClient.patch (url, port, path);
180
+
181
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
182
+ verify (
183
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
187
184
});
188
185
189
186
test ('expect instabug custom http client OPEN URL to return request and log' ,
190
187
() async {
191
188
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
192
189
.openUrl (any, any))
193
- .thenAnswer ((_) async => MockHttpClientRequest ());
194
-
195
- final request =
196
- await instabugCustomHttpClient.openUrl ('GET' , Uri .parse (url));
197
- final response = await request.close ();
198
- expect (request, isInstanceOf <HttpClientRequest >());
199
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
200
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
201
- .called (1 );
190
+ .thenAnswer ((_) async => mockRequest);
191
+
192
+ await instabugCustomHttpClient.openUrl ('GET' , Uri .parse (url));
193
+
194
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
195
+ verify (
196
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
202
197
});
203
198
204
199
test ('expect instabug custom http client OPEN to return request and log' ,
205
200
() async {
206
201
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
207
202
.open (any, any, any, any))
208
- .thenAnswer ((_) async => MockHttpClientRequest () );
203
+ .thenAnswer ((_) async => mockRequest );
209
204
210
- final request = await instabugCustomHttpClient.open ('GET' , url, port, path);
211
- final response = await request.close ();
212
- expect (request, isInstanceOf <HttpClientRequest >());
213
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
214
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
215
- .called (1 );
205
+ await instabugCustomHttpClient.open ('GET' , url, port, path);
206
+
207
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
208
+ verify (
209
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
216
210
});
217
211
218
212
test ('expect instabug custom http client PUT URL to return request and log' ,
219
213
() async {
220
214
when < dynamic > (
221
215
(instabugCustomHttpClient.client as MockHttpClient ).putUrl (any))
222
- .thenAnswer ((_) async => MockHttpClientRequest () );
216
+ .thenAnswer ((_) async => mockRequest );
223
217
224
- final request = await instabugCustomHttpClient.putUrl (Uri .parse (url));
225
- final response = await request.close ();
226
- expect (request, isInstanceOf <HttpClientRequest >());
227
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
228
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
229
- .called (1 );
218
+ await instabugCustomHttpClient.putUrl (Uri .parse (url));
219
+
220
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
221
+ verify (
222
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
230
223
});
231
224
232
225
test ('expect instabug custom http client PUT to return request and log' ,
233
226
() async {
234
227
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
235
228
.put (any, any, any))
236
- .thenAnswer ((_) async => MockHttpClientRequest () );
229
+ .thenAnswer ((_) async => mockRequest );
237
230
238
- final request = await instabugCustomHttpClient.put (url, port, path);
239
- final response = await request.close ();
240
- expect (request, isInstanceOf <HttpClientRequest >());
241
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
242
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
243
- .called (1 );
231
+ await instabugCustomHttpClient.put (url, port, path);
232
+
233
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
234
+ verify (
235
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
244
236
});
245
237
246
238
test ('expect instabug custom http client POST URL to return request and log' ,
247
239
() async {
248
240
when < dynamic > (
249
241
(instabugCustomHttpClient.client as MockHttpClient ).postUrl (any))
250
- .thenAnswer ((_) async => MockHttpClientRequest () );
242
+ .thenAnswer ((_) async => mockRequest );
251
243
252
- final request = await instabugCustomHttpClient.postUrl (Uri .parse (url));
253
- final response = await request.close ();
254
- expect (request, isInstanceOf <HttpClientRequest >());
255
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
256
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
257
- .called (1 );
244
+ await instabugCustomHttpClient.postUrl (Uri .parse (url));
245
+
246
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
247
+ verify (
248
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
258
249
});
259
250
260
251
test ('expect instabug custom http client POST to return request and log' ,
261
252
() async {
262
253
when < dynamic > ((instabugCustomHttpClient.client as MockHttpClient )
263
254
.post (any, any, any))
264
- .thenAnswer ((_) async => MockHttpClientRequest () );
255
+ .thenAnswer ((_) async => mockRequest );
265
256
266
- final request = await instabugCustomHttpClient.post (url, port, path);
267
- final response = await request.close ();
268
- expect (request, isInstanceOf <HttpClientRequest >());
269
- verify (instabugCustomHttpClient.logger.onRequest (request)).called (1 );
270
- verify (instabugCustomHttpClient.logger.onResponse (response, request))
271
- .called (1 );
257
+ await instabugCustomHttpClient.post (url, port, path);
258
+
259
+ verify (instabugCustomHttpClient.logger.onRequest (mockRequest));
260
+ verify (
261
+ instabugCustomHttpClient.logger.onResponse (mockResponse, mockRequest));
272
262
});
273
263
274
264
test ('expect instabug custom http client to get client autoUncompress' ,
@@ -411,7 +401,7 @@ void main() {
411
401
test ('Stress test on GET URL method' , () async {
412
402
when < dynamic > (
413
403
(instabugCustomHttpClient.client as MockHttpClient ).getUrl (any))
414
- .thenAnswer ((_) async => MockHttpClientRequest () );
404
+ .thenAnswer ((_) async => mockRequest );
415
405
416
406
for (int i = 0 ; i < 10000 ; i++ ) {
417
407
await instabugCustomHttpClient.getUrl (Uri .parse (url));
0 commit comments