In my Spring Boot application I have the following controller with a single method that redirects all HTML5 routes to the root URL**:
@Controller
public class RedirectController {
@RequestMapping(value = "/**/{path:[^\\.]*}")
public String redirect() {
return "forward:/";
}
}
How should I properly test that it works as expected?
Calling the content()
method of the MockMvcResultMatchers
class doesn't work:
@Test
public void givenPathWithoutDotShouldReturnString() throws Exception {
this.mockMvc.perform(get("/somePath"))
.andExpect(content().string("forward:/"));
}
>>> java.lang.AssertionError: Response content
>>> Expected :forward:/
>>> Actual :
** I found out about this solution from following this Spring tutorial.