From 7e4cc8482377b8d21c9efb4232331a4f4777f580 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 14 Jan 2020 19:52:10 +0100 Subject: [PATCH] Added more tests for valid URI's (aka: with parameter) * Switchted @Test to @ParameterizedTest in HtmlControllerTest and RestControllerTest * Fixed the behavior of RestController accordingly --- src/main/java/de/juplo/demo/RestController.java | 2 +- src/test/java/de/juplo/demo/HtmlControllerIT.java | 10 +++++----- src/test/java/de/juplo/demo/RestControllerIT.java | 12 +++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/juplo/demo/RestController.java b/src/main/java/de/juplo/demo/RestController.java index b32f796..288fd9e 100644 --- a/src/main/java/de/juplo/demo/RestController.java +++ b/src/main/java/de/juplo/demo/RestController.java @@ -23,7 +23,7 @@ public class RestController } - @GetMapping(path = "/", produces = MediaType.TEXT_PLAIN_VALUE) + @GetMapping(path = { "", "/" }, produces = MediaType.TEXT_PLAIN_VALUE) public Mono fetch(@RequestParam String path) { return service.getRemoteText(path); diff --git a/src/test/java/de/juplo/demo/HtmlControllerIT.java b/src/test/java/de/juplo/demo/HtmlControllerIT.java index 33ee782..6e33636 100644 --- a/src/test/java/de/juplo/demo/HtmlControllerIT.java +++ b/src/test/java/de/juplo/demo/HtmlControllerIT.java @@ -5,7 +5,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import org.jsoup.Jsoup; 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; @@ -33,14 +32,15 @@ public class HtmlControllerIT RemoteContentService service; - @Test - @DisplayName("Mapping for HtmlController with a parameter: /?path=foo") - void testUriWithParameter() + @DisplayName("Valid mappings for HtmlController with a parameter") + @ParameterizedTest() + @ValueSource(strings = { "/?path=foo", "?path=foo" }) + void testUriWithParameter(String uri) { when(service.getRemoteText("foo")).thenReturn(Mono.just("bar")); webClient .get() - .uri("/?path=foo") + .uri(uri) .exchange() .expectStatus().isOk() .expectBody(String.class).value(rendered -> diff --git a/src/test/java/de/juplo/demo/RestControllerIT.java b/src/test/java/de/juplo/demo/RestControllerIT.java index 68ad229..1e4e0ad 100644 --- a/src/test/java/de/juplo/demo/RestControllerIT.java +++ b/src/test/java/de/juplo/demo/RestControllerIT.java @@ -2,8 +2,9 @@ package de.juplo.demo; 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; @@ -29,14 +30,15 @@ public class RestControllerIT RemoteContentService service; - @Test - @DisplayName("Valid mapping for RestController: /?path=foo") - void testUriWithParameter() + @DisplayName("Valid mappings for RestController with parameter") + @ParameterizedTest() + @ValueSource(strings = { "/?path=foo", "?path=foo" }) + void testUriWithParameter(String uri) { when(service.getRemoteText("foo")).thenReturn(Mono.just("bar")); webClient .get() - .uri("/?path=foo") + .uri(uri) .header("Accept", MediaType.TEXT_PLAIN_VALUE) .exchange() .expectStatus().isOk() -- 2.20.1