diff --git a/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java b/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java index 11409ce986..a12d54960a 100644 --- a/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java +++ b/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java @@ -34,11 +34,11 @@ public class ReactiveUploadService { .contentType(MediaType.APPLICATION_PDF) .body(BodyInserters.fromResource(resource)) .exchangeToMono(response -> { - if (response.statusCode().equals(HttpStatus.OK)) { - return response.bodyToMono(HttpStatus.class).thenReturn(response.statusCode()); - } else { - throw new ServiceException("Error uploading file"); - } + if (response.statusCode().equals(HttpStatus.OK)) { + return response.bodyToMono(HttpStatus.class).thenReturn(response.statusCode()); + } else { + throw new ServiceException("Error uploading file"); + } }); return httpStatusMono; } @@ -55,11 +55,11 @@ public class ReactiveUploadService { .contentType(MediaType.MULTIPART_FORM_DATA) .body(BodyInserters.fromMultipartData(builder.build())) .exchangeToMono(response -> { - if (response.statusCode().equals(HttpStatus.OK)) { - return response.bodyToMono(HttpStatus.class).thenReturn(response.statusCode()); - } else { - throw new ServiceException("Error uploading file"); - } + if (response.statusCode().equals(HttpStatus.OK)) { + return response.bodyToMono(HttpStatus.class).thenReturn(response.statusCode()); + } else { + throw new ServiceException("Error uploading file"); + } }); return httpStatusMono; } diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java index 0ca59848d7..40c1e40d92 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java @@ -18,8 +18,8 @@ class ReactiveUploadServiceUnitTest { final WebClient webClientMock = WebClient.builder().baseUrl(BASE_URL) .exchangeFunction(clientRequest -> Mono.just(ClientResponse.create(HttpStatus.OK) - .header("content-type", "application/json") - .build())) + .header("content-type", "application/json") + .build())) .build(); private final ReactiveUploadService tested = new ReactiveUploadService(webClientMock); @@ -27,8 +27,10 @@ class ReactiveUploadServiceUnitTest { @Test void givenAPdf_whenUploadingWithWebClient_thenOK() { final Resource file = mock(Resource.class); + final Mono result = tested.uploadPdf(file); final HttpStatus status = result.block(); + assertThat(status).isEqualTo(HttpStatus.OK); } @@ -37,8 +39,10 @@ class ReactiveUploadServiceUnitTest { final Resource file = mock(Resource.class); final MultipartFile multipartFile = mock(MultipartFile.class); when(multipartFile.getResource()).thenReturn(file); + final Mono result = tested.uploadMultipart(multipartFile); final HttpStatus status = result.block(); + assertThat(status).isEqualTo(HttpStatus.OK); } } \ No newline at end of file