From c35cf11506a3b1c3813d1c7ea76c1d2ed57b6319 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 14 Jan 2020 17:48:04 +0100 Subject: [PATCH] Switched parameterized test in HtmlControllerTest to @EnumSource --- .../de/juplo/demo/HtmlControllerTest.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test/java/de/juplo/demo/HtmlControllerTest.java b/src/test/java/de/juplo/demo/HtmlControllerTest.java index 1584ef6..0aa7f13 100644 --- a/src/test/java/de/juplo/demo/HtmlControllerTest.java +++ b/src/test/java/de/juplo/demo/HtmlControllerTest.java @@ -7,12 +7,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.provider.EnumSource; import org.mockito.ArgumentCaptor; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpStatus; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.ui.Model; import org.springframework.web.reactive.function.client.WebClientResponseException; @@ -86,10 +87,26 @@ public class HtmlControllerTest */ @DisplayName("Other error while fetching data from remote-server") @ParameterizedTest(name = "{arguments} ==> HTTP-status={0}") - @ValueSource(ints = { 400, 401, 403, 405, 406, 409, 410, 415, 422, 429, 500, 501, 502, 503, 504 }) - void testOtherError(int status) + @EnumSource(value = HttpStatus.class, names = { + "BAD_REQUEST", + "UNAUTHORIZED", + "FORBIDDEN", + "METHOD_NOT_ALLOWED", + "NOT_ACCEPTABLE", + "CONFLICT", + "GONE", + "UNSUPPORTED_MEDIA_TYPE", + "TOO_MANY_REQUESTS", + "UNPROCESSABLE_ENTITY", + "INTERNAL_SERVER_ERROR", + "NOT_IMPLEMENTED", + "BAD_GATEWAY", + "SERVICE_UNAVAILABLE", + "GATEWAY_TIMEOUT" + }) + void testOtherError(HttpStatus status) { - Mono mono = Mono.error(WebClientResponseException.create(status, "", null, null, null)); + Mono mono = Mono.error(WebClientResponseException.create(status.value(), "", null, null, null)); when(service.getRemoteText("foo")).thenReturn(mono); String result = controller.fetch(model, "foo"); @@ -99,7 +116,7 @@ public class HtmlControllerTest verify(model).addAttribute(eq("text"), captor.capture()); StepVerifier .create(captor.getValue()) - .expectNextMatches(message -> message.startsWith(Integer.toString(status))) + .expectNextMatches(message -> message.startsWith(Integer.toString(status.value()))) .expectComplete() .verify(); } -- 2.20.1