Skip to content

Commit

Permalink
Replace mockito with mocktail
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcegraph committed Apr 26, 2024
1 parent f2c5e8c commit ba36845
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 90 deletions.
4 changes: 0 additions & 4 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
targets:
$default:
builders:
# mockito's builder is not needed until this package is migrated to
# null-safety. At that point, it should be scoped only to relevant files.
mockito|mockBuilder:
enabled: false
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dev_dependencies:
dart_style: ^2.2.4
dependency_validator: ^3.0.0
http_server: ^1.0.0
mockito: ^5.3.1
mocktail: ^1.0.3
test: ^1.16.5
uuid: ^3.0.5
workiva_analysis_options: ^1.0.2
Expand Down
2 changes: 1 addition & 1 deletion test/integration/http/mock_endpoints/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'dart:convert';
import 'package:w_transport/mock.dart';

void mockDownloadEndpoint(Uri uri) {
MockTransports.http.when(uri, (_) async {
MockTransports.http.when(() => uri, (_) async {
final byteStream = Stream.fromIterable([utf8.encode('file')]);
return MockStreamedResponse.ok(byteStream: byteStream);
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/http/mock_endpoints/echo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:w_transport/w_transport.dart';
import 'package:w_transport/mock.dart';

void mockEchoEndpoint(Uri uri) {
MockTransports.http.when(uri, (request) async {
MockTransports.http.when(() => uri, (request) async {
final headers = <String, String>{
'content-type': request.headers['content-type'] ?? ''
};
Expand Down
2 changes: 1 addition & 1 deletion test/integration/http/mock_endpoints/not_found.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
import 'package:w_transport/mock.dart';

void mock404Endpoint(Uri uri) {
MockTransports.http.when(uri, (request) async => MockResponse.notFound());
MockTransports.http.when(() => uri, (request) async => MockResponse.notFound());
}
2 changes: 1 addition & 1 deletion test/integration/http/mock_endpoints/ping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import 'package:w_transport/mock.dart';

void mockPingEndpoint(Uri uri) {
MockTransports.http.when(uri, (_) async {
MockTransports.http.when(() => uri, (_) async {
return MockResponse.ok();
});
}
2 changes: 1 addition & 1 deletion test/integration/http/mock_endpoints/reflect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'dart:convert';
import 'package:w_transport/mock.dart';

void mockReflectEndpoint(Uri uri) {
MockTransports.http.when(uri, (request) async {
MockTransports.http.when(() => uri, (request) async {
final reflection = <String, Object?>{
'method': request.method,
'path': request.uri.path,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/http/mock_endpoints/timeout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'package:w_transport/mock.dart';
import 'package:w_transport/w_transport.dart' as transport;

void mockTimeoutEndpoint(Uri uri) {
MockTransports.http.when(uri, (_) async {
MockTransports.http.when(() => uri, (_) async {
return Completer<transport.BaseResponse>().future;
});
}
2 changes: 1 addition & 1 deletion test/integration/http/mock_endpoints/upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:w_transport/w_transport.dart' as transport;
import 'package:w_transport/w_transport.dart';

void mockUploadEndpoint(Uri uri) {
MockTransports.http.when(uri, (request) async {
MockTransports.http.when(() => uri, (request) async {
transport.StreamedHttpBody body = request.body as StreamedHttpBody;
await body.byteStream.drain();
return MockResponse.ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void main() {
});

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

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

MockTransports.webSocket.when(IntegrationPaths.pingUri,
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
handler: (Uri uri,
{Map<String, dynamic>? headers,
Iterable<String>? protocols}) async =>
Expand Down Expand Up @@ -487,7 +487,7 @@ void main() {
});

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

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

MockTransports.webSocket.when(IntegrationPaths.pingUri,
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
handler: (Uri uri,
{Map<String, dynamic>? headers,
Iterable<String>? protocols}) async =>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/platforms/transport_platform_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@TestOn('vm || browser')
import 'dart:async';

import 'package:mockito/mockito.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
import 'package:w_transport/w_transport.dart' as transport;

Expand Down
8 changes: 4 additions & 4 deletions test/integration/platforms/vm_transport_platform_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void main() {
});

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

final formRequest =
Expand Down Expand Up @@ -227,7 +227,7 @@ void main() {
test('websockets with matching handler should be handled', () async {
final mockWebSocketServer = MockWebSocketServer();

MockTransports.webSocket.when(IntegrationPaths.pingUri,
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
handler: (Uri uri,
{Map<String, dynamic>? headers,
Iterable<String>? protocols}) async =>
Expand Down Expand Up @@ -390,7 +390,7 @@ void main() {
});

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

final formRequest =
Expand Down Expand Up @@ -462,7 +462,7 @@ void main() {
test('websockets with matching handler should be handled', () async {
final mockWebSocketServer = MockWebSocketServer();

MockTransports.webSocket.when(IntegrationPaths.pingUri,
MockTransports.webSocket.when(() => IntegrationPaths.pingUri,
handler: (Uri uri,
{Map<String, dynamic>? headers,
Iterable<String>? protocols}) async =>
Expand Down
16 changes: 8 additions & 8 deletions test/integration/ws/mock_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ void main() {
});

MockTransports.webSocket
.when(IntegrationPaths.fourOhFourUri, reject: true);
.when(() => IntegrationPaths.fourOhFourUri, reject: true);

MockTransports.webSocket.when(IntegrationPaths.closeUri,
MockTransports.webSocket.when(() => IntegrationPaths.closeUri,
handler: (Uri uri,
{Iterable<String>? protocols,
Map<String, dynamic>? headers}) async =>
mockCloseWebSocketServer);

MockTransports.webSocket.when(IntegrationPaths.echoUri,
MockTransports.webSocket.when(() => IntegrationPaths.echoUri,
handler: (Uri uri,
{Iterable<String>? protocols,
Map<String, dynamic>? headers}) async =>
mockEchoWebSocketServer);

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

MockTransports.webSocket
.when(IntegrationPaths.fourOhFourUri, reject: true);
.when(() => IntegrationPaths.fourOhFourUri, reject: true);

MockTransports.webSocket.when(IntegrationPaths.closeUri, handler:
MockTransports.webSocket.when(() => IntegrationPaths.closeUri, handler:
(Uri uri,
{Iterable<String>? protocols,
Map<String, dynamic>? headers}) async {
Expand All @@ -145,7 +145,7 @@ void main() {
return webSocket;
});

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

MockTransports.webSocket.when(IntegrationPaths.pingUri, handler: (Uri uri,
MockTransports.webSocket.when(() => IntegrationPaths.pingUri, handler: (Uri uri,
{Iterable<String>? protocols, Map<String, dynamic>? headers}) async {
// ignore: deprecated_member_use_from_same_package
final webSocket = MockWSocket();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/http/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void _runHttpClientSuite(transport.Client getClient()) {
for (final request in createAllRequestTypes(client)) {
final uri = Uri.parse('/test');
final c = Completer<Null>();
MockTransports.http.when(uri, (FinalizedRequest request) async {
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
request.withCredentials
? c.complete()
: c.completeError(Exception('withCredentials should be true'));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/http/form_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void main() {
final uri = Uri.parse('/test');

final c = Completer<String>();
MockTransports.http.when(uri, (FinalizedRequest request) async {
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
transport.HttpBody body = request.body as transport.HttpBody;
c.complete(body.asString());
return MockResponse.ok();
Expand Down
24 changes: 12 additions & 12 deletions test/unit/http/http_static_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void main() {

test('DELETE withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand All @@ -68,7 +68,7 @@ void main() {

test('GET withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand All @@ -87,7 +87,7 @@ void main() {

test('HEAD withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand All @@ -106,7 +106,7 @@ void main() {

test('OPTIONS withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand All @@ -127,7 +127,7 @@ void main() {

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

test('PATCH withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand All @@ -160,7 +160,7 @@ void main() {

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

test('POST withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand All @@ -191,7 +191,7 @@ void main() {

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

test('PUT withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand All @@ -222,7 +222,7 @@ void main() {

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

test('custom method withCredentials', () async {
final c = Completer<Null>();
MockTransports.http.when(requestUri, (FinalizedRequest request) async {
MockTransports.http.when(() => requestUri, (FinalizedRequest request) async {
if (request.withCredentials) {
c.complete();
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/http/json_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void main() {
final uri = Uri.parse('/test');

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

final c = Completer<String>();
MockTransports.http.when(uri, (FinalizedRequest request) async {
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
transport.HttpBody body = request.body as transport.HttpBody;
c.complete(body.asString());
return MockResponse.ok();
Expand Down
4 changes: 2 additions & 2 deletions test/unit/http/plain_text_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void main() {
final uri = Uri.parse('/test');

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

final c = Completer<String>();
MockTransports.http.when(uri, (FinalizedRequest request) async {
MockTransports.http.when(() => uri, (FinalizedRequest request) async {
transport.HttpBody body = request.body as transport.HttpBody;
c.complete(body.asString());
return MockResponse.ok();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/http/request_exception_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@TestOn('vm || browser')
import 'package:mockito/mockito.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
import 'package:w_transport/mock.dart';
import 'package:w_transport/src/http/auto_retry.dart';
Expand Down
Loading

0 comments on commit ba36845

Please sign in to comment.