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'})); }); }