From d22cecf8ab110696f17ba594f44c6726161792f3 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 14 Jan 2020 18:28:22 +0100 Subject: [PATCH] Added more tests for URI's without a parameter * Transformed test into a @ParameterizedTest * Fixed the behavior of the HtmlController accordingly --- src/main/java/de/juplo/demo/HtmlController.java | 2 +- src/test/java/de/juplo/demo/HtmlControllerIT.java | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/juplo/demo/HtmlController.java b/src/main/java/de/juplo/demo/HtmlController.java index 0c5f276..ec5919c 100644 --- a/src/main/java/de/juplo/demo/HtmlController.java +++ b/src/main/java/de/juplo/demo/HtmlController.java @@ -24,7 +24,7 @@ public class HtmlController } - @GetMapping("/") + @GetMapping({ "", "/" }) public String fetch(Model model, @RequestParam(required = false) String path) { model.addAttribute( diff --git a/src/test/java/de/juplo/demo/HtmlControllerIT.java b/src/test/java/de/juplo/demo/HtmlControllerIT.java index b6bd98f..33ee782 100644 --- a/src/test/java/de/juplo/demo/HtmlControllerIT.java +++ b/src/test/java/de/juplo/demo/HtmlControllerIT.java @@ -7,6 +7,8 @@ import org.jsoup.nodes.Document; 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 static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +34,7 @@ public class HtmlControllerIT @Test - @DisplayName("Mapping for HtmlController: /?path=foo") + @DisplayName("Mapping for HtmlController with a parameter: /?path=foo") void testUriWithParameter() { when(service.getRemoteText("foo")).thenReturn(Mono.just("bar")); @@ -51,13 +53,14 @@ public class HtmlControllerIT verify(service).getRemoteText("foo"); } - @Test - @DisplayName("Mapping for HtmlController: /") - void testUriWithoutParameter() + @DisplayName("Mappings for HtmlController without a parameter") + @ParameterizedTest(name = "{arguments} ==> uri={0}") + @ValueSource(strings = { "/", "", "?foo=bar", "/?foo=bar"}) + void testUriWithoutParameter(String uri) { webClient .get() - .uri("/") + .uri(uri) .exchange() .expectStatus().isOk() .expectBody(String.class).value(rendered -> -- 2.20.1