99import org .springframework .context .annotation .Configuration ;
1010import org .springframework .test .context .ContextConfiguration ;
1111import org .springframework .test .web .servlet .MockMvc ;
12- import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
1312import org .springframework .test .web .servlet .result .MockMvcResultMatchers ;
1413import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
1514import org .springframework .web .servlet .config .annotation .ViewResolverRegistry ;
1817import java .lang .reflect .Method ;
1918
2019import static org .junit .jupiter .api .Assertions .*;
21- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .* ;
20+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
2221import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
22+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .view ;
2323
2424@ WebMvcTest
2525@ ContextConfiguration (classes = {ResolverConfig .class })
2626@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
2727public class ViewResolverTest {
28+
2829 @ Autowired
2930 private MockMvc mockMvc ;
3031
@@ -38,15 +39,15 @@ void classIsMarkedAsConfiguration() {
3839
3940 @ Test
4041 @ Order (2 )
41- @ DisplayName ("Configuration Class marked as @EnableWebMvc" )
42+ @ DisplayName ("Configuration Class has annotation @EnableWebMvc" )
4243 void classAnnotatedWithEnableWebMvc () {
4344 EnableWebMvc enableWebMvc = ResolverConfig .class .getAnnotation (EnableWebMvc .class );
4445 assertNotNull (enableWebMvc );
4546 }
4647
4748 @ Test
4849 @ Order (3 )
49- @ DisplayName ("Configuration Class marked as @ComponentScan" )
50+ @ DisplayName ("Configuration Class has annotation @ComponentScan" )
5051 void classAnnotatedWithComponentScan () {
5152 ComponentScan componentScan = ResolverConfig .class .getAnnotation (ComponentScan .class );
5253 assertNotNull (componentScan );
@@ -62,15 +63,15 @@ void ComponentScanHasIndicatedPackages() {
6263
6364 @ Test
6465 @ Order (5 )
65- @ DisplayName ("Is config class implements WebMvcConfigurer interface" )
66+ @ DisplayName ("Config class implements WebMvcConfigurer interface" )
6667 void isConfigClassImplementsWebMvcConfigurerInterface () {
6768 assertTrue (WebMvcConfigurer .class .isAssignableFrom (ResolverConfig .class ));
6869 }
6970
7071 @ SneakyThrows
7172 @ Test
7273 @ Order (6 )
73- @ DisplayName ("Is config class overrides configureViewResolvers method" )
74+ @ DisplayName ("Config class overrides configureViewResolvers method" )
7475 void isConfigurationClassContainsViewResolverMethod () {
7576 Method configureViewResolvers = ResolverConfig .class .getMethod ("configureViewResolvers" , ViewResolverRegistry .class );
7677 assertNotNull (configureViewResolvers );
@@ -79,8 +80,11 @@ void isConfigurationClassContainsViewResolverMethod() {
7980 @ Test
8081 @ Order (7 )
8182 @ SneakyThrows
82- void getRequestReturnOkStatus () {
83+ @ DisplayName ("Get request returns correct view name and URL" )
84+ void getRequestReturnCorrectUrlAndViewName () {
8385 mockMvc .perform (get ("/" ))
84- .andExpect (status ().isOk ());
86+ .andExpect (status ().isOk ())
87+ .andExpect (view ().name ("index" ))
88+ .andExpect (MockMvcResultMatchers .forwardedUrl ("/WEB-INF/views/index.jsp" ));
8589 }
8690}
0 commit comments