From 214e9801acdad2b6239e9de9a09b266c34ae7811 Mon Sep 17 00:00:00 2001 From: Ricardo Boss Date: Mon, 12 Feb 2024 20:47:32 +0100 Subject: [PATCH] Replace copyWith method with withUrl fluent API --- lib/src/base_request_builder.dart | 26 +++----------------------- test/request_builder_test.dart | 13 ++++--------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/lib/src/base_request_builder.dart b/lib/src/base_request_builder.dart index 6765773..9bbc60f 100644 --- a/lib/src/base_request_builder.dart +++ b/lib/src/base_request_builder.dart @@ -20,27 +20,7 @@ abstract class BaseRequestBuilder> { /// Clones the current request builder. T clone(); - /// Clones the current request builder using [clone] and applies the provided - /// parameters. - T copyWith({ - RequestAdapter? requestAdapter, - String? urlTemplate, - Map? pathParameters, - }) { - final clone = this.clone(); - - if (requestAdapter != null) { - clone.requestAdapter = requestAdapter; - } - - if (urlTemplate != null) { - clone.urlTemplate = urlTemplate; - } - - if (pathParameters != null) { - clone.pathParameters = pathParameters; - } - - return clone; - } + /// Clones the current request builder using [clone] and sets the given + /// [template] as the url template. + T withUrl(String template) => this.clone()..urlTemplate = template; } diff --git a/test/request_builder_test.dart b/test/request_builder_test.dart index 54bcb6d..636af3c 100644 --- a/test/request_builder_test.dart +++ b/test/request_builder_test.dart @@ -37,20 +37,15 @@ void main() { {'id': '1'}, ); - final anotherRequestAdapter = MockRequestAdapter(); - - final newRequestBuilder = requestBuilder.copyWith( - requestAdapter: anotherRequestAdapter, - urlTemplate: 'https://graph.microsoft.com/v2.0/users/{id}', - pathParameters: {'id': '2'}, - ); + final newRequestBuilder = + requestBuilder.withUrl('https://graph.microsoft.com/v2.0/users/{id}'); expect(newRequestBuilder.id, equals(1)); - expect(newRequestBuilder.requestAdapter, equals(anotherRequestAdapter)); + expect(newRequestBuilder.requestAdapter, equals(mockRequestAdapter)); expect( newRequestBuilder.urlTemplate, equals('https://graph.microsoft.com/v2.0/users/{id}'), ); - expect(newRequestBuilder.pathParameters, equals({'id': '2'})); + expect(newRequestBuilder.pathParameters, equals({'id': '1'})); }); }