diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java index 92b5cf21fd2..7a7b4d7ed44 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -16,17 +16,14 @@ package org.springframework.test.web.servlet; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -47,29 +44,25 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC * @author Rob Winch * @since 4.2 */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration -@WebAppConfiguration -public class MockMvcReuseTests { +@SpringJUnitWebConfig +@TestInstance(Lifecycle.PER_CLASS) +class MockMvcReuseTests { private static final String HELLO = "hello"; private static final String ENIGMA = "enigma"; private static final String FOO = "foo"; private static final String BAR = "bar"; - @Autowired - private WebApplicationContext wac; - - private MockMvc mvc; + private final MockMvc mvc; - @BeforeEach - public void setUp() { - this.mvc = webAppContextSetup(this.wac).build(); + MockMvcReuseTests(WebApplicationContext wac) { + this.mvc = webAppContextSetup(wac).build(); } + @Test - public void sessionAttributesAreClearedBetweenInvocations() throws Exception { + void sessionAttributesAreClearedBetweenInvocations() throws Exception { this.mvc.perform(get("/")) .andExpect(content().string(HELLO)) @@ -85,7 +78,7 @@ public class MockMvcReuseTests { } @Test - public void requestParametersAreClearedBetweenInvocations() throws Exception { + void requestParametersAreClearedBetweenInvocations() throws Exception { this.mvc.perform(get("/")) .andExpect(content().string(HELLO)); @@ -102,7 +95,7 @@ public class MockMvcReuseTests { static class Config { @Bean - public MyController myController() { + MyController myController() { return new MyController(); } } @@ -110,13 +103,13 @@ public class MockMvcReuseTests { @RestController static class MyController { - @RequestMapping("/") - public String hello() { + @GetMapping("/") + String hello() { return HELLO; } - @RequestMapping(path = "/", params = ENIGMA) - public String enigma() { + @GetMapping(path = "/", params = ENIGMA) + String enigma() { return ENIGMA; } }