diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java index 9f97cb0bc8..03f1d8dec3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java @@ -20,7 +20,6 @@ import java.net.URI; import org.junit.Test; import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -29,6 +28,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** @@ -44,7 +44,7 @@ public class JsonContentTests { @Test - public void jsonContent() throws Exception { + public void jsonContent() { this.client.get().uri("/persons") .accept(MediaType.APPLICATION_JSON_UTF8) .exchange() @@ -53,7 +53,7 @@ public class JsonContentTests { } @Test - public void jsonPathIsEqualTo() throws Exception { + public void jsonPathIsEqualTo() { this.client.get().uri("/persons") .accept(MediaType.APPLICATION_JSON_UTF8) .exchange() @@ -64,9 +64,8 @@ public class JsonContentTests { .jsonPath("$[2].name").isEqualTo("John"); } - @Test - // See https://stackoverflow.com/questions/49149376/webtestclient-check-that-jsonpath-contains-sub-string - public void jsonPathContainsSubstringViaRegularExpression() throws Exception { + @Test // https://stackoverflow.com/questions/49149376/webtestclient-check-that-jsonpath-contains-sub-string + public void jsonPathContainsSubstringViaRegex() { this.client.get().uri("/persons/John") .accept(MediaType.APPLICATION_JSON_UTF8) .exchange() @@ -78,7 +77,7 @@ public class JsonContentTests { } @Test - public void postJsonContent() throws Exception { + public void postJsonContent() { this.client.post().uri("/persons") .contentType(MediaType.APPLICATION_JSON_UTF8) .syncBody("{\"name\":\"John\"}") @@ -89,14 +88,15 @@ public class JsonContentTests { @RestController + @RequestMapping("/persons") static class PersonController { - @GetMapping("/persons") + @GetMapping Flux getPersons() { return Flux.just(new Person("Jane"), new Person("Jason"), new Person("John")); } - @GetMapping("/persons/{name}") + @GetMapping("/{name}") Person getPerson(@PathVariable String name) { return new Person(name); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java index 40c6fed83b..e4a91c3ce6 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java @@ -21,9 +21,8 @@ import org.junit.Test; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -64,7 +63,7 @@ public class ExceptionHandlerTests { @Controller private static class PersonController { - @RequestMapping(value="/person/{name}", method=RequestMethod.GET) + @GetMapping("/person/{name}") public String show(@PathVariable String name) { if (name.equals("Clyde")) { throw new IllegalArgumentException("simulated exception"); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java index 645bd5b81d..e00e47dd46 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,9 @@ import org.springframework.test.web.Person; import org.springframework.test.web.servlet.MockMvc; import org.springframework.ui.Model; import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -109,13 +109,13 @@ public class RedirectTests { @Controller private static class PersonController { - @RequestMapping(value="/persons/{name}", method=RequestMethod.GET) + @GetMapping("/persons/{name}") public String getPerson(@PathVariable String name, Model model) { model.addAttribute(new Person(name)); return "persons/index"; } - @RequestMapping(value="/persons", method=RequestMethod.POST) + @PostMapping public String save(@Valid Person person, Errors errors, RedirectAttributes redirectAttrs) { if (errors.hasErrors()) { return "persons/add"; @@ -125,7 +125,7 @@ public class RedirectTests { return "redirect:/persons/{name}"; } - @RequestMapping(value="/people", method=RequestMethod.POST) + @PostMapping("/people") public Object saveSpecial(@Valid Person person, Errors errors, RedirectAttributes redirectAttrs) { if (errors.hasErrors()) { return "persons/add"; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java index 001a2c69ce..83113cea9c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java @@ -30,9 +30,8 @@ import org.springframework.ui.Model; import org.springframework.web.accept.ContentNegotiationManager; import org.springframework.web.accept.FixedContentNegotiationStrategy; import org.springframework.web.accept.HeaderContentNegotiationStrategy; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; import org.springframework.web.servlet.view.InternalResourceViewResolver; @@ -136,7 +135,7 @@ public class ViewResolutionTests { @Controller private static class PersonController { - @RequestMapping(value="/person/{name}", method=RequestMethod.GET) + @GetMapping("/person/{name}") public String show(@PathVariable String name, Model model) { Person person = new Person(name); model.addAttribute(person); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java index e4c3998ed4..d561d7d051 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java @@ -28,6 +28,7 @@ import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -112,7 +113,7 @@ public class ModelAssertionTests { return "view"; } - @RequestMapping(value="/persons", method=RequestMethod.POST) + @PostMapping("/persons") public String create(@Valid Person person, BindingResult result, Model model) { return "view"; }