Skip to content

Commit 1f2f4e5

Browse files
committed
Use auto-generated mocks
1 parent d06c140 commit 1f2f4e5

File tree

2 files changed

+218
-61
lines changed

2 files changed

+218
-61
lines changed

test/network_logger_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import 'package:mockito/mockito.dart';
1111

1212
import 'network_logger_test.mocks.dart';
1313

14-
class MockHttpClientRequest extends Mock implements HttpClientRequest {}
15-
16-
class MockHttpClientResponse extends Mock implements HttpClientResponse {}
17-
18-
class MockHttpClientCredentials extends Mock implements HttpClientCredentials {}
19-
20-
@GenerateMocks([HttpClient, HttpClientLogger])
14+
@GenerateMocks([
15+
HttpClient,
16+
HttpClientLogger,
17+
HttpClientRequest,
18+
HttpClientResponse,
19+
HttpClientCredentials,
20+
])
2121
void main() {
2222
WidgetsFlutterBinding.ensureInitialized();
2323

test/network_logger_test.mocks.dart

Lines changed: 211 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// in instabug_flutter/test/network_logger_test.dart.
33
// Do not manually edit this file.
44

5-
import 'dart:_http' as _i2;
6-
import 'dart:async' as _i3;
7-
import 'dart:io' as _i4;
5+
import 'dart:async' as _i4;
6+
import 'dart:io' as _i3;
87

98
import 'package:instabug_flutter/models/network_data.dart' as _i6;
109
import 'package:instabug_flutter/utils/http_client_logger.dart' as _i5;
@@ -19,13 +18,22 @@ import 'package:mockito/mockito.dart' as _i1;
1918

2019
class _FakeDuration extends _i1.Fake implements Duration {}
2120

22-
class _FakeHttpClientRequest extends _i1.Fake implements _i2.HttpClientRequest {
21+
class _FakeHttpClientRequest extends _i1.Fake implements _i3.HttpClientRequest {
2322
}
2423

24+
class _FakeUri extends _i1.Fake implements Uri {}
25+
26+
class _FakeHttpHeaders extends _i1.Fake implements _i3.HttpHeaders {}
27+
28+
class _FakeHttpClientResponse extends _i1.Fake
29+
implements _i3.HttpClientResponse {}
30+
31+
class _FakeSocket extends _i1.Fake implements _i3.Socket {}
32+
2533
/// A class which mocks [HttpClient].
2634
///
2735
/// See the documentation for Mockito's code generation for more information.
28-
class MockHttpClient extends _i1.Mock implements _i2.HttpClient {
36+
class MockHttpClient extends _i1.Mock implements _i3.HttpClient {
2937
MockHttpClient() {
3038
_i1.throwOnMissingStub(this);
3139
}
@@ -59,7 +67,7 @@ class MockHttpClient extends _i1.Mock implements _i2.HttpClient {
5967
super.noSuchMethod(Invocation.setter(#userAgent, _userAgent),
6068
returnValueForMissingStub: null);
6169
@override
62-
set authenticate(_i3.Future<bool> Function(Uri, String, String)? f) =>
70+
set authenticate(_i4.Future<bool> Function(Uri, String, String)? f) =>
6371
super.noSuchMethod(Invocation.setter(#authenticate, f),
6472
returnValueForMissingStub: null);
6573
@override
@@ -68,114 +76,114 @@ class MockHttpClient extends _i1.Mock implements _i2.HttpClient {
6876
returnValueForMissingStub: null);
6977
@override
7078
set authenticateProxy(
71-
_i3.Future<bool> Function(String, int, String, String)? f) =>
79+
_i4.Future<bool> Function(String, int, String, String)? f) =>
7280
super.noSuchMethod(Invocation.setter(#authenticateProxy, f),
7381
returnValueForMissingStub: null);
7482
@override
7583
set badCertificateCallback(
76-
bool Function(_i4.X509Certificate, String, int)? callback) =>
84+
bool Function(_i3.X509Certificate, String, int)? callback) =>
7785
super.noSuchMethod(Invocation.setter(#badCertificateCallback, callback),
7886
returnValueForMissingStub: null);
7987
@override
80-
_i3.Future<_i2.HttpClientRequest> open(
88+
_i4.Future<_i3.HttpClientRequest> open(
8189
String? method, String? host, int? port, String? path) =>
8290
(super.noSuchMethod(Invocation.method(#open, [method, host, port, path]),
8391
returnValue:
84-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
85-
as _i3.Future<_i2.HttpClientRequest>);
92+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
93+
as _i4.Future<_i3.HttpClientRequest>);
8694
@override
87-
_i3.Future<_i2.HttpClientRequest> openUrl(String? method, Uri? url) =>
95+
_i4.Future<_i3.HttpClientRequest> openUrl(String? method, Uri? url) =>
8896
(super.noSuchMethod(Invocation.method(#openUrl, [method, url]),
8997
returnValue:
90-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
91-
as _i3.Future<_i2.HttpClientRequest>);
98+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
99+
as _i4.Future<_i3.HttpClientRequest>);
92100
@override
93-
_i3.Future<_i2.HttpClientRequest> get(
101+
_i4.Future<_i3.HttpClientRequest> get(
94102
String? host, int? port, String? path) =>
95103
(super.noSuchMethod(Invocation.method(#get, [host, port, path]),
96104
returnValue:
97-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
98-
as _i3.Future<_i2.HttpClientRequest>);
105+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
106+
as _i4.Future<_i3.HttpClientRequest>);
99107
@override
100-
_i3.Future<_i2.HttpClientRequest> getUrl(Uri? url) =>
108+
_i4.Future<_i3.HttpClientRequest> getUrl(Uri? url) =>
101109
(super.noSuchMethod(Invocation.method(#getUrl, [url]),
102110
returnValue:
103-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
104-
as _i3.Future<_i2.HttpClientRequest>);
111+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
112+
as _i4.Future<_i3.HttpClientRequest>);
105113
@override
106-
_i3.Future<_i2.HttpClientRequest> post(
114+
_i4.Future<_i3.HttpClientRequest> post(
107115
String? host, int? port, String? path) =>
108116
(super.noSuchMethod(Invocation.method(#post, [host, port, path]),
109117
returnValue:
110-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
111-
as _i3.Future<_i2.HttpClientRequest>);
118+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
119+
as _i4.Future<_i3.HttpClientRequest>);
112120
@override
113-
_i3.Future<_i2.HttpClientRequest> postUrl(Uri? url) =>
121+
_i4.Future<_i3.HttpClientRequest> postUrl(Uri? url) =>
114122
(super.noSuchMethod(Invocation.method(#postUrl, [url]),
115123
returnValue:
116-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
117-
as _i3.Future<_i2.HttpClientRequest>);
124+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
125+
as _i4.Future<_i3.HttpClientRequest>);
118126
@override
119-
_i3.Future<_i2.HttpClientRequest> put(
127+
_i4.Future<_i3.HttpClientRequest> put(
120128
String? host, int? port, String? path) =>
121129
(super.noSuchMethod(Invocation.method(#put, [host, port, path]),
122130
returnValue:
123-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
124-
as _i3.Future<_i2.HttpClientRequest>);
131+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
132+
as _i4.Future<_i3.HttpClientRequest>);
125133
@override
126-
_i3.Future<_i2.HttpClientRequest> putUrl(Uri? url) =>
134+
_i4.Future<_i3.HttpClientRequest> putUrl(Uri? url) =>
127135
(super.noSuchMethod(Invocation.method(#putUrl, [url]),
128136
returnValue:
129-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
130-
as _i3.Future<_i2.HttpClientRequest>);
137+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
138+
as _i4.Future<_i3.HttpClientRequest>);
131139
@override
132-
_i3.Future<_i2.HttpClientRequest> delete(
140+
_i4.Future<_i3.HttpClientRequest> delete(
133141
String? host, int? port, String? path) =>
134142
(super.noSuchMethod(Invocation.method(#delete, [host, port, path]),
135143
returnValue:
136-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
137-
as _i3.Future<_i2.HttpClientRequest>);
144+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
145+
as _i4.Future<_i3.HttpClientRequest>);
138146
@override
139-
_i3.Future<_i2.HttpClientRequest> deleteUrl(Uri? url) =>
147+
_i4.Future<_i3.HttpClientRequest> deleteUrl(Uri? url) =>
140148
(super.noSuchMethod(Invocation.method(#deleteUrl, [url]),
141149
returnValue:
142-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
143-
as _i3.Future<_i2.HttpClientRequest>);
150+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
151+
as _i4.Future<_i3.HttpClientRequest>);
144152
@override
145-
_i3.Future<_i2.HttpClientRequest> patch(
153+
_i4.Future<_i3.HttpClientRequest> patch(
146154
String? host, int? port, String? path) =>
147155
(super.noSuchMethod(Invocation.method(#patch, [host, port, path]),
148156
returnValue:
149-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
150-
as _i3.Future<_i2.HttpClientRequest>);
157+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
158+
as _i4.Future<_i3.HttpClientRequest>);
151159
@override
152-
_i3.Future<_i2.HttpClientRequest> patchUrl(Uri? url) =>
160+
_i4.Future<_i3.HttpClientRequest> patchUrl(Uri? url) =>
153161
(super.noSuchMethod(Invocation.method(#patchUrl, [url]),
154162
returnValue:
155-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
156-
as _i3.Future<_i2.HttpClientRequest>);
163+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
164+
as _i4.Future<_i3.HttpClientRequest>);
157165
@override
158-
_i3.Future<_i2.HttpClientRequest> head(
166+
_i4.Future<_i3.HttpClientRequest> head(
159167
String? host, int? port, String? path) =>
160168
(super.noSuchMethod(Invocation.method(#head, [host, port, path]),
161169
returnValue:
162-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
163-
as _i3.Future<_i2.HttpClientRequest>);
170+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
171+
as _i4.Future<_i3.HttpClientRequest>);
164172
@override
165-
_i3.Future<_i2.HttpClientRequest> headUrl(Uri? url) =>
173+
_i4.Future<_i3.HttpClientRequest> headUrl(Uri? url) =>
166174
(super.noSuchMethod(Invocation.method(#headUrl, [url]),
167175
returnValue:
168-
Future<_i2.HttpClientRequest>.value(_FakeHttpClientRequest()))
169-
as _i3.Future<_i2.HttpClientRequest>);
176+
Future<_i3.HttpClientRequest>.value(_FakeHttpClientRequest()))
177+
as _i4.Future<_i3.HttpClientRequest>);
170178
@override
171179
void addCredentials(
172-
Uri? url, String? realm, _i2.HttpClientCredentials? credentials) =>
180+
Uri? url, String? realm, _i3.HttpClientCredentials? credentials) =>
173181
super.noSuchMethod(
174182
Invocation.method(#addCredentials, [url, realm, credentials]),
175183
returnValueForMissingStub: null);
176184
@override
177185
void addProxyCredentials(String? host, int? port, String? realm,
178-
_i2.HttpClientCredentials? credentials) =>
186+
_i3.HttpClientCredentials? credentials) =>
179187
super.noSuchMethod(
180188
Invocation.method(
181189
#addProxyCredentials, [host, port, realm, credentials]),
@@ -199,16 +207,165 @@ class MockHttpClientLogger extends _i1.Mock implements _i5.HttpClientLogger {
199207
(super.noSuchMethod(Invocation.getter(#requests),
200208
returnValue: <int, _i6.NetworkData>{}) as Map<int, _i6.NetworkData>);
201209
@override
202-
void onRequest(_i2.HttpClientRequest? request, {dynamic requestBody}) =>
210+
void onRequest(_i3.HttpClientRequest? request, {dynamic requestBody}) =>
203211
super.noSuchMethod(
204212
Invocation.method(#onRequest, [request], {#requestBody: requestBody}),
205213
returnValueForMissingStub: null);
206214
@override
207215
void onResponse(
208-
_i2.HttpClientResponse? response, _i2.HttpClientRequest? request,
216+
_i3.HttpClientResponse? response, _i3.HttpClientRequest? request,
209217
{dynamic responseBody}) =>
210218
super.noSuchMethod(
211219
Invocation.method(
212220
#onResponse, [response, request], {#responseBody: responseBody}),
213221
returnValueForMissingStub: null);
214222
}
223+
224+
/// A class which mocks [HttpClientRequest].
225+
///
226+
/// See the documentation for Mockito's code generation for more information.
227+
class MockHttpClientRequest extends _i1.Mock implements _i3.HttpClientRequest {
228+
MockHttpClientRequest() {
229+
_i1.throwOnMissingStub(this);
230+
}
231+
232+
@override
233+
bool get persistentConnection =>
234+
(super.noSuchMethod(Invocation.getter(#persistentConnection),
235+
returnValue: false) as bool);
236+
@override
237+
set persistentConnection(bool? _persistentConnection) => super.noSuchMethod(
238+
Invocation.setter(#persistentConnection, _persistentConnection),
239+
returnValueForMissingStub: null);
240+
@override
241+
bool get followRedirects => (super
242+
.noSuchMethod(Invocation.getter(#followRedirects), returnValue: false)
243+
as bool);
244+
@override
245+
set followRedirects(bool? _followRedirects) =>
246+
super.noSuchMethod(Invocation.setter(#followRedirects, _followRedirects),
247+
returnValueForMissingStub: null);
248+
@override
249+
int get maxRedirects =>
250+
(super.noSuchMethod(Invocation.getter(#maxRedirects), returnValue: 0)
251+
as int);
252+
@override
253+
set maxRedirects(int? _maxRedirects) =>
254+
super.noSuchMethod(Invocation.setter(#maxRedirects, _maxRedirects),
255+
returnValueForMissingStub: null);
256+
@override
257+
int get contentLength =>
258+
(super.noSuchMethod(Invocation.getter(#contentLength), returnValue: 0)
259+
as int);
260+
@override
261+
set contentLength(int? _contentLength) =>
262+
super.noSuchMethod(Invocation.setter(#contentLength, _contentLength),
263+
returnValueForMissingStub: null);
264+
@override
265+
bool get bufferOutput =>
266+
(super.noSuchMethod(Invocation.getter(#bufferOutput), returnValue: false)
267+
as bool);
268+
@override
269+
set bufferOutput(bool? _bufferOutput) =>
270+
super.noSuchMethod(Invocation.setter(#bufferOutput, _bufferOutput),
271+
returnValueForMissingStub: null);
272+
@override
273+
String get method =>
274+
(super.noSuchMethod(Invocation.getter(#method), returnValue: '')
275+
as String);
276+
@override
277+
Uri get uri =>
278+
(super.noSuchMethod(Invocation.getter(#uri), returnValue: _FakeUri())
279+
as Uri);
280+
@override
281+
_i3.HttpHeaders get headers =>
282+
(super.noSuchMethod(Invocation.getter(#headers),
283+
returnValue: _FakeHttpHeaders()) as _i3.HttpHeaders);
284+
@override
285+
List<_i3.Cookie> get cookies =>
286+
(super.noSuchMethod(Invocation.getter(#cookies),
287+
returnValue: <_i3.Cookie>[]) as List<_i3.Cookie>);
288+
@override
289+
_i4.Future<_i3.HttpClientResponse> get done => (super.noSuchMethod(
290+
Invocation.getter(#done),
291+
returnValue:
292+
Future<_i3.HttpClientResponse>.value(_FakeHttpClientResponse()))
293+
as _i4.Future<_i3.HttpClientResponse>);
294+
@override
295+
_i4.Future<_i3.HttpClientResponse> close() async => MockHttpClientResponse();
296+
@override
297+
void abort([Object? exception, StackTrace? stackTrace]) =>
298+
super.noSuchMethod(Invocation.method(#abort, [exception, stackTrace]),
299+
returnValueForMissingStub: null);
300+
}
301+
302+
/// A class which mocks [HttpClientResponse].
303+
///
304+
/// See the documentation for Mockito's code generation for more information.
305+
class MockHttpClientResponse extends _i1.Mock
306+
implements _i3.HttpClientResponse {
307+
MockHttpClientResponse() {
308+
_i1.throwOnMissingStub(this);
309+
}
310+
311+
@override
312+
int get statusCode =>
313+
(super.noSuchMethod(Invocation.getter(#statusCode), returnValue: 0)
314+
as int);
315+
@override
316+
String get reasonPhrase =>
317+
(super.noSuchMethod(Invocation.getter(#reasonPhrase), returnValue: '')
318+
as String);
319+
@override
320+
int get contentLength =>
321+
(super.noSuchMethod(Invocation.getter(#contentLength), returnValue: 0)
322+
as int);
323+
@override
324+
_i3.HttpClientResponseCompressionState get compressionState =>
325+
(super.noSuchMethod(Invocation.getter(#compressionState),
326+
returnValue: _i3.HttpClientResponseCompressionState.notCompressed)
327+
as _i3.HttpClientResponseCompressionState);
328+
@override
329+
bool get persistentConnection =>
330+
(super.noSuchMethod(Invocation.getter(#persistentConnection),
331+
returnValue: false) as bool);
332+
@override
333+
bool get isRedirect =>
334+
(super.noSuchMethod(Invocation.getter(#isRedirect), returnValue: false)
335+
as bool);
336+
@override
337+
List<_i3.RedirectInfo> get redirects =>
338+
(super.noSuchMethod(Invocation.getter(#redirects),
339+
returnValue: <_i3.RedirectInfo>[]) as List<_i3.RedirectInfo>);
340+
@override
341+
_i3.HttpHeaders get headers =>
342+
(super.noSuchMethod(Invocation.getter(#headers),
343+
returnValue: _FakeHttpHeaders()) as _i3.HttpHeaders);
344+
@override
345+
List<_i3.Cookie> get cookies =>
346+
(super.noSuchMethod(Invocation.getter(#cookies),
347+
returnValue: <_i3.Cookie>[]) as List<_i3.Cookie>);
348+
@override
349+
_i4.Future<_i3.HttpClientResponse> redirect(
350+
[String? method, Uri? url, bool? followLoops]) =>
351+
(super.noSuchMethod(
352+
Invocation.method(#redirect, [method, url, followLoops]),
353+
returnValue: Future<_i3.HttpClientResponse>.value(
354+
_FakeHttpClientResponse()))
355+
as _i4.Future<_i3.HttpClientResponse>);
356+
@override
357+
_i4.Future<_i3.Socket> detachSocket() =>
358+
(super.noSuchMethod(Invocation.method(#detachSocket, []),
359+
returnValue: Future<_i3.Socket>.value(_FakeSocket()))
360+
as _i4.Future<_i3.Socket>);
361+
}
362+
363+
/// A class which mocks [HttpClientCredentials].
364+
///
365+
/// See the documentation for Mockito's code generation for more information.
366+
class MockHttpClientCredentials extends _i1.Mock
367+
implements _i3.HttpClientCredentials {
368+
MockHttpClientCredentials() {
369+
_i1.throwOnMissingStub(this);
370+
}
371+
}

0 commit comments

Comments
 (0)