diff --git a/lib/src/adapters/dio_adapter.dart b/lib/src/adapters/dio_adapter.dart index 2b40004..5993717 100644 --- a/lib/src/adapters/dio_adapter.dart +++ b/lib/src/adapters/dio_adapter.dart @@ -7,7 +7,7 @@ import 'package:http_mock_adapter/src/mixins/mixins.dart'; import 'package:http_mock_adapter/src/response.dart'; /// [HttpClientAdapter] extension with data mocking and recording functionality. -class DioAdapter extends HttpClientAdapter with Recording, RequestHandling { +class DioAdapter with Recording, RequestHandling implements HttpClientAdapter { /// State of [DioAdapter] that can be closed to prohibit functionality. bool _isClosed = false; diff --git a/lib/src/exceptions.dart b/lib/src/exceptions.dart index c179b64..c7275f7 100644 --- a/lib/src/exceptions.dart +++ b/lib/src/exceptions.dart @@ -11,7 +11,7 @@ class MockDioError extends DioError implements MockResponse { MockDioError({ required RequestOptions requestOptions, Response? response, - DioErrorType type = DioErrorType.other, + DioErrorType type = DioErrorType.unknown, dynamic error, this.delay, }) : super( diff --git a/lib/src/matchers/list_param.dart b/lib/src/matchers/list_param.dart index 3a766df..dc45761 100644 --- a/lib/src/matchers/list_param.dart +++ b/lib/src/matchers/list_param.dart @@ -1,7 +1,5 @@ import 'package:collection/collection.dart'; import 'package:dio/dio.dart'; -// ignore: implementation_imports -import 'package:dio/src/parameter.dart' show ListParam; import 'package:http_mock_adapter/src/matchers/matcher.dart'; /// Matches [ListParam] instance by comparing diff --git a/lib/src/matchers/matchers.dart b/lib/src/matchers/matchers.dart index 1ab00d7..92c99a3 100644 --- a/lib/src/matchers/matchers.dart +++ b/lib/src/matchers/matchers.dart @@ -1,6 +1,4 @@ import 'package:dio/dio.dart'; -// ignore: implementation_imports -import 'package:dio/src/parameter.dart' show ListParam; import 'package:http_mock_adapter/src/matchers/any.dart'; import 'package:http_mock_adapter/src/matchers/boolean.dart'; import 'package:http_mock_adapter/src/matchers/decimal.dart'; diff --git a/lib/src/mixins/request_handling.dart b/lib/src/mixins/request_handling.dart index 938209f..f33076b 100644 --- a/lib/src/mixins/request_handling.dart +++ b/lib/src/mixins/request_handling.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:http_mock_adapter/http_mock_adapter.dart'; -import 'package:http_mock_adapter/src/exceptions.dart'; import 'package:http_mock_adapter/src/handlers/request_handler.dart'; import 'package:http_mock_adapter/src/mixins/mixins.dart'; import 'package:http_mock_adapter/src/request.dart'; @@ -27,12 +26,12 @@ mixin RequestHandling on Recording { 'multipart/form-data; boundary=${data.boundary}'; options.headers[Headers.contentLengthHeader] = data.length.toString(); } else { - final _data = await dio.transformer.transformRequest(options); + final data = await dio.transformer.transformRequest(options); List bytes; if (options.requestEncoder != null) { - bytes = options.requestEncoder!(_data, options); + bytes = options.requestEncoder!(data, options); } else { - bytes = utf8.encode(_data); + bytes = utf8.encode(data); } options.headers[Headers.contentLengthHeader] = bytes.length.toString(); } diff --git a/pubspec.yaml b/pubspec.yaml index 59c5ae7..73a2a72 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,14 +6,14 @@ repository: https://github.com/lomsa-dev/http-mock-adapter issue_tracker: https://github.com/lomsa-dev/http-mock-adapter/issues environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.15.0 <3.0.0" dependencies: collection: ^1.15.0 - dio: ^4.0.0 - http_parser: ^4.0.0 + dio: ^5.0.0 + http_parser: ^4.0.2 dev_dependencies: - lints: ^1.0.1 - test: ^1.16.8 - fake_async: ^1.2.0 + lints: ^2.0.1 + test: ^1.23.1 + fake_async: ^1.3.1 diff --git a/test/adapters/dio_adapter_test.dart b/test/adapters/dio_adapter_test.dart index e541732..53e5164 100644 --- a/test/adapters/dio_adapter_test.dart +++ b/test/adapters/dio_adapter_test.dart @@ -1,5 +1,6 @@ import 'package:dio/dio.dart'; import 'package:http_mock_adapter/http_mock_adapter.dart'; +import 'package:http_mock_adapter/src/exceptions.dart'; import 'package:test/test.dart'; import '../utils.dart'; @@ -24,13 +25,8 @@ void main() { expect( () async => await dio.get('/route'), - throwsA( - predicate( - (DioError dioError) => dioError.message.startsWith( - 'ClosedException', - ), - ), - ), + throwsA(predicate( + (DioError dioError) => dioError.error is ClosedException)), ); }); @@ -52,7 +48,7 @@ void main() { test('delays error', () async { const delay = 5000; final dioError = DioError( - type: DioErrorType.response, + type: DioErrorType.badResponse, requestOptions: RequestOptions(path: 'path'), ); diff --git a/test/extensions/matches_request_test.dart b/test/extensions/matches_request_test.dart index 695a4a6..46a023b 100644 --- a/test/extensions/matches_request_test.dart +++ b/test/extensions/matches_request_test.dart @@ -168,7 +168,7 @@ void main() { late DioAdapter dioAdapter; setUpAll(() { - dio = Dio(); + dio = Dio(BaseOptions(contentType: Headers.jsonContentType)); dioAdapter = DioAdapter(dio: dio); }); @@ -247,7 +247,7 @@ void main() { () => dio.get(path), throwsA(predicate((e) => e is DioError && - e.type == DioErrorType.other && + e.type == DioErrorType.unknown && e.error is AssertionError))); }); }); diff --git a/test/handlers/request_handler_test.dart b/test/handlers/request_handler_test.dart index f053879..c562bc3 100644 --- a/test/handlers/request_handler_test.dart +++ b/test/handlers/request_handler_test.dart @@ -30,7 +30,7 @@ void main() { final mockResponseBody = statusHandler(RequestOptions(path: '')) as MockResponseBody; - final resolvedData = await DefaultTransformer().transformResponse( + final resolvedData = await BackgroundTransformer().transformResponse( RequestOptions(path: ''), mockResponseBody, ); @@ -61,7 +61,7 @@ void main() { final mockResponseBody = statusHandler(RequestOptions(path: '')) as MockResponseBody; - final resolvedData = await DefaultTransformer() + final resolvedData = await BackgroundTransformer() .transformResponse(RequestOptions(path: ''), mockResponseBody); expect(resolvedData, data); @@ -91,7 +91,7 @@ void main() { final mockResponseBody = statusHandler(RequestOptions(path: '')) as MockResponseBody; - final resolvedData = await DefaultTransformer().transformResponse( + final resolvedData = await BackgroundTransformer().transformResponse( RequestOptions(path: ''), mockResponseBody, ); @@ -106,7 +106,7 @@ void main() { requestOptions: RequestOptions( path: 'path', ), - type: DioErrorType.response, + type: DioErrorType.badResponse, ); requestHandler.throws( diff --git a/test/matchers/http_matcher_test.dart b/test/matchers/http_matcher_test.dart index 29d3426..e480ef4 100644 --- a/test/matchers/http_matcher_test.dart +++ b/test/matchers/http_matcher_test.dart @@ -63,7 +63,7 @@ void main() { queryParameters: {}, ): true, Request( - route: path + '/url/request/matcher', + route: '$path/url/request/matcher', method: RequestMethods.post, queryParameters: {}, ): false, diff --git a/test/matchers/list_param_test.dart b/test/matchers/list_param_test.dart index 91e7533..9600f37 100644 --- a/test/matchers/list_param_test.dart +++ b/test/matchers/list_param_test.dart @@ -1,5 +1,4 @@ import 'package:dio/dio.dart'; -import 'package:dio/src/parameter.dart'; import 'package:http_mock_adapter/http_mock_adapter.dart'; import 'package:test/test.dart'; diff --git a/test/mixins/recording_test.dart b/test/mixins/recording_test.dart index a8c30a2..30c1d09 100644 --- a/test/mixins/recording_test.dart +++ b/test/mixins/recording_test.dart @@ -65,11 +65,7 @@ void main() { expect( () async => await dio.get('/undefined'), throwsA( - predicate( - (DioError dioError) => dioError.message.startsWith( - 'Assertion failed', - ), - ), + predicate((DioError dioError) => dioError.error is AssertionError), ), ); }); diff --git a/test/mixins/request_handling_test.dart b/test/mixins/request_handling_test.dart index 1b632b5..5c74479 100644 --- a/test/mixins/request_handling_test.dart +++ b/test/mixins/request_handling_test.dart @@ -106,7 +106,6 @@ void main() { 'foo': 'bar', }, headers: { - Headers.contentTypeHeader: Headers.jsonContentType, Headers.contentLengthHeader: Matchers.integer, }, ); @@ -130,7 +129,7 @@ void main() { statusCode: 500, requestOptions: RequestOptions(path: path), ), - type: DioErrorType.response, + type: DioErrorType.badResponse, ); tester.onGet( @@ -143,12 +142,7 @@ void main() { expect( () async => await dio.get(path), throwsA( - predicate( - (DioError error) => - error is DioError && - error is MockDioError && - error.message == dioError.error.toString(), - ), + predicate((DioError error) => error is MockDioError), ), ); });