From b7dc861910bd43020ff91c8f9f51fe4c32a66aec Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 14 Jan 2020 20:11:06 +0100 Subject: [PATCH] Verified, that RestController throws NotFound, if remote-data does not exist * This tests may seem to check the value reached into the class by the test itself, because RestController simply returns the fetched Mono at the moment * But it is valuable, because it verifies, that the behavior stays unchanged, when the implementation of RestControler is changed --- .../de/juplo/demo/RestControllerTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/de/juplo/demo/RestControllerTest.java b/src/test/java/de/juplo/demo/RestControllerTest.java index 8b248ce..dae8929 100644 --- a/src/test/java/de/juplo/demo/RestControllerTest.java +++ b/src/test/java/de/juplo/demo/RestControllerTest.java @@ -6,6 +6,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.mockito.Mockito.when; +import org.springframework.web.reactive.function.client.WebClientResponseException; +import org.springframework.web.reactive.function.client.WebClientResponseException.NotFound; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -42,4 +44,24 @@ public class RestControllerTest .expectComplete() .verify(); } + + @Test + @DisplayName("Data not found on remote-server") + void testResponseNotFoud() + { + when(service.getRemoteText("foo")).thenReturn(Mono.error(exception(404))); + + Mono result = controller.fetch("foo"); + + StepVerifier + .create(result) + .expectError(NotFound.class) + .verify(); + } + + + WebClientResponseException exception(int status) + { + return WebClientResponseException.create(status, "", null, null, null); + } } -- 2.20.1