Skip to content

Commit 5d466a7

Browse files
author
Sourcegraph
committed
Replace mockito with mocktail
1 parent f2c5e8c commit 5d466a7

26 files changed

+87
-91
lines changed

_test_server/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dev_dependencies:
88
http_parser: ^4.0.0
99
http_server: ^1.0.0
1010
mime: ^1.0.4
11-
mockito: ^5.3.1
11+
mocktail: ^1.0.3
1212
uuid: ^3.0.5
1313
workiva_analysis_options: ^1.0.0
1414
w_transport:

build.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
targets:
22
$default:
33
builders:
4-
# mockito's builder is not needed until this package is migrated to
5-
# null-safety. At that point, it should be scoped only to relevant files.
6-
mockito|mockBuilder:
7-
enabled: false

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dev_dependencies:
2525
dart_style: ^2.2.4
2626
dependency_validator: ^3.0.0
2727
http_server: ^1.0.0
28-
mockito: ^5.3.1
28+
mocktail: ^1.0.3
2929
test: ^1.16.5
3030
uuid: ^3.0.5
3131
workiva_analysis_options: ^1.0.2

test/integration/http/mock_endpoints/download.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'dart:convert';
1818
import 'package:w_transport/mock.dart';
1919

2020
void mockDownloadEndpoint(Uri uri) {
21-
MockTransports.http.when(uri, (_) async {
21+
MockTransports.http.when(() => uri, (_) async {
2222
final byteStream = Stream.fromIterable([utf8.encode('file')]);
2323
return MockStreamedResponse.ok(byteStream: byteStream);
2424
});

test/integration/http/mock_endpoints/echo.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'package:w_transport/w_transport.dart';
1616
import 'package:w_transport/mock.dart';
1717

1818
void mockEchoEndpoint(Uri uri) {
19-
MockTransports.http.when(uri, (request) async {
19+
MockTransports.http.when(() => uri, (request) async {
2020
final headers = <String, String>{
2121
'content-type': request.headers['content-type'] ?? ''
2222
};

test/integration/http/mock_endpoints/not_found.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
import 'package:w_transport/mock.dart';
1616

1717
void mock404Endpoint(Uri uri) {
18-
MockTransports.http.when(uri, (request) async => MockResponse.notFound());
18+
MockTransports.http.when(() => uri, (request) async => MockResponse.notFound());
1919
}

test/integration/http/mock_endpoints/ping.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import 'package:w_transport/mock.dart';
1616

1717
void mockPingEndpoint(Uri uri) {
18-
MockTransports.http.when(uri, (_) async {
18+
MockTransports.http.when(() => uri, (_) async {
1919
return MockResponse.ok();
2020
});
2121
}

test/integration/http/mock_endpoints/reflect.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'dart:convert';
1616
import 'package:w_transport/mock.dart';
1717

1818
void mockReflectEndpoint(Uri uri) {
19-
MockTransports.http.when(uri, (request) async {
19+
MockTransports.http.when(() => uri, (request) async {
2020
final reflection = <String, Object?>{
2121
'method': request.method,
2222
'path': request.uri.path,

test/integration/http/mock_endpoints/timeout.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'package:w_transport/mock.dart';
1818
import 'package:w_transport/w_transport.dart' as transport;
1919

2020
void mockTimeoutEndpoint(Uri uri) {
21-
MockTransports.http.when(uri, (_) async {
21+
MockTransports.http.when(() => uri, (_) async {
2222
return Completer<transport.BaseResponse>().future;
2323
});
2424
}

test/integration/http/mock_endpoints/upload.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'package:w_transport/w_transport.dart' as transport;
1717
import 'package:w_transport/w_transport.dart';
1818

1919
void mockUploadEndpoint(Uri uri) {
20-
MockTransports.http.when(uri, (request) async {
20+
MockTransports.http.when(() => uri, (request) async {
2121
transport.StreamedHttpBody body = request.body as StreamedHttpBody;
2222
await body.byteStream.drain();
2323
return MockResponse.ok();

test/integration/platforms/browser_transport_platform_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void main() {
234234
});
235235

236236
test('requests with matching handler should be handled', () async {
237-
MockTransports.http.when(IntegrationPaths.pingEndpointUri,
237+
MockTransports.http.when(() => IntegrationPaths.pingEndpointUri,
238238
(request) async => MockResponse.ok());
239239

240240
final formRequest = transport.FormRequest(
@@ -313,7 +313,7 @@ void main() {
313313
test('websockets with matching handler should be handled', () async {
314314
final mockWebSocketServer = MockWebSocketServer();
315315

316-
MockTransports.webSocket.when(IntegrationPaths.pingUri,
316+
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
317317
handler: (Uri uri,
318318
{Map<String, dynamic>? headers,
319319
Iterable<String>? protocols}) async =>
@@ -487,7 +487,7 @@ void main() {
487487
});
488488

489489
test('requests with matching handler should be handled', () async {
490-
MockTransports.http.when(IntegrationPaths.pingEndpointUri,
490+
MockTransports.http.when(() => IntegrationPaths.pingEndpointUri,
491491
(request) async => MockResponse.ok());
492492

493493
final formRequest = transport.FormRequest(
@@ -566,7 +566,7 @@ void main() {
566566
test('websockets with matching handler should be handled', () async {
567567
final mockWebSocketServer = MockWebSocketServer();
568568

569-
MockTransports.webSocket.when(IntegrationPaths.pingUri,
569+
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
570570
handler: (Uri uri,
571571
{Map<String, dynamic>? headers,
572572
Iterable<String>? protocols}) async =>

test/integration/platforms/transport_platform_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@TestOn('vm || browser')
1616
import 'dart:async';
1717

18-
import 'package:mockito/mockito.dart';
18+
import 'package:mocktail/mocktail.dart';
1919
import 'package:test/test.dart';
2020
import 'package:w_transport/w_transport.dart' as transport;
2121

test/integration/platforms/vm_transport_platform_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void main() {
155155
});
156156

157157
test('requests with matching handler should be handled', () async {
158-
MockTransports.http.when(IntegrationPaths.pingEndpointUri,
158+
MockTransports.http.when(() => IntegrationPaths.pingEndpointUri,
159159
(request) async => MockResponse.ok());
160160

161161
final formRequest =
@@ -227,7 +227,7 @@ void main() {
227227
test('websockets with matching handler should be handled', () async {
228228
final mockWebSocketServer = MockWebSocketServer();
229229

230-
MockTransports.webSocket.when(IntegrationPaths.pingUri,
230+
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
231231
handler: (Uri uri,
232232
{Map<String, dynamic>? headers,
233233
Iterable<String>? protocols}) async =>
@@ -390,7 +390,7 @@ void main() {
390390
});
391391

392392
test('requests with matching handler should be handled', () async {
393-
MockTransports.http.when(IntegrationPaths.pingEndpointUri,
393+
MockTransports.http.when(() => IntegrationPaths.pingEndpointUri,
394394
(request) async => MockResponse.ok());
395395

396396
final formRequest =
@@ -462,7 +462,7 @@ void main() {
462462
test('websockets with matching handler should be handled', () async {
463463
final mockWebSocketServer = MockWebSocketServer();
464464

465-
MockTransports.webSocket.when(IntegrationPaths.pingUri,
465+
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
466466
handler: (Uri uri,
467467
{Map<String, dynamic>? headers,
468468
Iterable<String>? protocols}) async =>

test/integration/ws/mock_test.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ void main() {
7878
});
7979

8080
MockTransports.webSocket
81-
.when(IntegrationPaths.fourOhFourUri, reject: true);
81+
.when(() => IntegrationPaths.fourOhFourUri, reject: true);
8282

83-
MockTransports.webSocket.when(IntegrationPaths.closeUri,
83+
MockTransports.webSocket.when(() => IntegrationPaths.closeUri,
8484
handler: (Uri uri,
8585
{Iterable<String>? protocols,
8686
Map<String, dynamic>? headers}) async =>
8787
mockCloseWebSocketServer);
8888

89-
MockTransports.webSocket.when(IntegrationPaths.echoUri,
89+
MockTransports.webSocket.when(() => IntegrationPaths.echoUri,
9090
handler: (Uri uri,
9191
{Iterable<String>? protocols,
9292
Map<String, dynamic>? headers}) async =>
9393
mockEchoWebSocketServer);
9494

95-
MockTransports.webSocket.when(IntegrationPaths.pingUri,
95+
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
9696
handler: (Uri uri,
9797
{Iterable<String>? protocols,
9898
Map<String, dynamic>? headers}) async =>
@@ -117,9 +117,9 @@ void main() {
117117
MockTransports.install();
118118

119119
MockTransports.webSocket
120-
.when(IntegrationPaths.fourOhFourUri, reject: true);
120+
.when(() => IntegrationPaths.fourOhFourUri, reject: true);
121121

122-
MockTransports.webSocket.when(IntegrationPaths.closeUri, handler:
122+
MockTransports.webSocket.when(() => IntegrationPaths.closeUri, handler:
123123
(Uri uri,
124124
{Iterable<String>? protocols,
125125
Map<String, dynamic>? headers}) async {
@@ -145,7 +145,7 @@ void main() {
145145
return webSocket;
146146
});
147147

148-
MockTransports.webSocket.when(IntegrationPaths.echoUri, handler: (Uri uri,
148+
MockTransports.webSocket.when(() => IntegrationPaths.echoUri, handler: (Uri uri,
149149
{Iterable<String>? protocols, Map<String, dynamic>? headers}) async {
150150
// ignore: deprecated_member_use_from_same_package
151151
final webSocket = MockWSocket();
@@ -154,7 +154,7 @@ void main() {
154154
return webSocket;
155155
});
156156

157-
MockTransports.webSocket.when(IntegrationPaths.pingUri, handler: (Uri uri,
157+
MockTransports.webSocket.when(() => IntegrationPaths.pingUri, handler: (Uri uri,
158158
{Iterable<String>? protocols, Map<String, dynamic>? headers}) async {
159159
// ignore: deprecated_member_use_from_same_package
160160
final webSocket = MockWSocket();

test/unit/http/client_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void _runHttpClientSuite(transport.Client getClient()) {
210210
for (final request in createAllRequestTypes(client)) {
211211
final uri = Uri.parse('/test');
212212
final c = Completer<Null>();
213-
MockTransports.http.when(uri, (FinalizedRequest request) async {
213+
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
214214
request.withCredentials
215215
? c.complete()
216216
: c.completeError(Exception('withCredentials should be true'));

test/unit/http/form_request_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void main() {
6161
final uri = Uri.parse('/test');
6262

6363
final c = Completer<String>();
64-
MockTransports.http.when(uri, (FinalizedRequest request) async {
64+
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
6565
transport.HttpBody body = request.body as transport.HttpBody;
6666
c.complete(body.asString());
6767
return MockResponse.ok();

test/unit/http/http_static_test.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747

4848
test('DELETE withCredentials', () async {
4949
final c = Completer<Null>();
50-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
50+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
5151
if (request.withCredentials) {
5252
c.complete();
5353
} else {
@@ -68,7 +68,7 @@ void main() {
6868

6969
test('GET withCredentials', () async {
7070
final c = Completer<Null>();
71-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
71+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
7272
if (request.withCredentials) {
7373
c.complete();
7474
} else {
@@ -87,7 +87,7 @@ void main() {
8787

8888
test('HEAD withCredentials', () async {
8989
final c = Completer<Null>();
90-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
90+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
9191
if (request.withCredentials) {
9292
c.complete();
9393
} else {
@@ -106,7 +106,7 @@ void main() {
106106

107107
test('OPTIONS withCredentials', () async {
108108
final c = Completer<Null>();
109-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
109+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
110110
if (request.withCredentials) {
111111
c.complete();
112112
} else {
@@ -127,7 +127,7 @@ void main() {
127127

128128
test('PATCH with body', () async {
129129
final c = Completer<String>();
130-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
130+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
131131
transport.HttpBody body = request.body as transport.HttpBody;
132132
c.complete(body.asString());
133133
return MockResponse.ok();
@@ -139,7 +139,7 @@ void main() {
139139

140140
test('PATCH withCredentials', () async {
141141
final c = Completer<Null>();
142-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
142+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
143143
if (request.withCredentials) {
144144
c.complete();
145145
} else {
@@ -160,7 +160,7 @@ void main() {
160160

161161
test('POST with body', () async {
162162
final c = Completer<String>();
163-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
163+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
164164
transport.HttpBody body = request.body as transport.HttpBody;
165165
c.complete(body.asString());
166166
return MockResponse.ok();
@@ -172,7 +172,7 @@ void main() {
172172

173173
test('POST withCredentials', () async {
174174
final c = Completer<Null>();
175-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
175+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
176176
if (request.withCredentials) {
177177
c.complete();
178178
} else {
@@ -191,7 +191,7 @@ void main() {
191191

192192
test('PUT with body', () async {
193193
final c = Completer<String>();
194-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
194+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
195195
transport.HttpBody body = request.body as transport.HttpBody;
196196
c.complete(body.asString());
197197
return MockResponse.ok();
@@ -203,7 +203,7 @@ void main() {
203203

204204
test('PUT withCredentials', () async {
205205
final c = Completer<Null>();
206-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
206+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
207207
if (request.withCredentials) {
208208
c.complete();
209209
} else {
@@ -222,7 +222,7 @@ void main() {
222222

223223
test('custom method with body', () async {
224224
final c = Completer<String>();
225-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
225+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
226226
transport.HttpBody body = request.body as transport.HttpBody;
227227
c.complete(body.asString());
228228
return MockResponse.ok();
@@ -234,7 +234,7 @@ void main() {
234234

235235
test('custom method withCredentials', () async {
236236
final c = Completer<Null>();
237-
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
237+
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
238238
if (request.withCredentials) {
239239
c.complete();
240240
} else {

test/unit/http/json_request_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void main() {
7272
final uri = Uri.parse('/test');
7373

7474
final c = Completer<String>();
75-
MockTransports.http.when(uri, (FinalizedRequest request) async {
75+
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
7676
transport.HttpBody body = request.body as transport.HttpBody;
7777
c.complete(body.asString());
7878
return MockResponse.ok();
@@ -88,7 +88,7 @@ void main() {
8888
final uri = Uri.parse('/test');
8989

9090
final c = Completer<String>();
91-
MockTransports.http.when(uri, (FinalizedRequest request) async {
91+
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
9292
transport.HttpBody body = request.body as transport.HttpBody;
9393
c.complete(body.asString());
9494
return MockResponse.ok();

test/unit/http/plain_text_request_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void main() {
6868
final uri = Uri.parse('/test');
6969

7070
final c = Completer<String>();
71-
MockTransports.http.when(uri, (FinalizedRequest request) async {
71+
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
7272
transport.HttpBody body = request.body as transport.HttpBody;
7373
c.complete(body.asString());
7474
return MockResponse.ok();
@@ -83,7 +83,7 @@ void main() {
8383
final uri = Uri.parse('/test');
8484

8585
final c = Completer<String>();
86-
MockTransports.http.when(uri, (FinalizedRequest request) async {
86+
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
8787
transport.HttpBody body = request.body as transport.HttpBody;
8888
c.complete(body.asString());
8989
return MockResponse.ok();

test/unit/http/request_exception_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@TestOn('vm || browser')
2-
import 'package:mockito/mockito.dart';
2+
import 'package:mocktail/mocktail.dart';
33
import 'package:test/test.dart';
44
import 'package:w_transport/mock.dart';
55
import 'package:w_transport/src/http/auto_retry.dart';

0 commit comments

Comments
 (0)