diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java index 902df20a2b..a17e7c02b9 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java @@ -18,14 +18,13 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; import java.lang.reflect.Method; -import org.junit.Before; import org.junit.Test; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -43,51 +42,46 @@ import static org.springframework.web.servlet.mvc.method.annotation.MvcUriCompon */ public class HandlerAssertionTests { - private MockMvc mockMvc; + private final MockMvc mockMvc = standaloneSetup(new SimpleController()).alwaysExpect(status().isOk()).build(); + - @Before - public void setup() { - this.mockMvc = standaloneSetup(new SimpleController()).alwaysExpect(status().isOk()).build(); - } @Test - public void testHandlerType() throws Exception { + public void handlerType() throws Exception { this.mockMvc.perform(get("/")).andExpect(handler().handlerType(SimpleController.class)); } @Test - public void testMethodCall() throws Exception { + @Test + public void methodCall() throws Exception { this.mockMvc.perform(get("/")).andExpect(handler().methodCall(on(SimpleController.class).handle())); } @Test - public void testHandlerMethodNameEqualTo() throws Exception { + public void methodName() throws Exception { this.mockMvc.perform(get("/")).andExpect(handler().methodName("handle")); - - // Hamcrest matcher.. - this.mockMvc.perform(get("/")).andExpect(handler().methodName(equalTo("handle"))); } @Test - public void testHandlerMethodNameMatcher() throws Exception { + public void methodNameMatchers() throws Exception { + this.mockMvc.perform(get("/")).andExpect(handler().methodName(equalTo("handle"))); this.mockMvc.perform(get("/")).andExpect(handler().methodName(is(not("save")))); } @Test - public void testHandlerMethod() throws Exception { + public void method() throws Exception { Method method = SimpleController.class.getMethod("handle"); this.mockMvc.perform(get("/")).andExpect(handler().method(method)); } - - @Controller + @RestController static class SimpleController { @RequestMapping("/") - @ResponseBody public ResponseEntity handle() { return ResponseEntity.ok().build(); } } + }