After doing some digging, I've discovered that the HTTPRequestAdapter.parseRequest()
method has an issue with the way that MockMVC sends requests. Specifically, the request sent by MockMVC doesn't include a header in the request with the name host
.
HTTPRequestAdapter
requires that header and does not account for the fact that it can be null, so it generates the NullPointerException
.
I fixed the issue with this code:
mockMvc.perform(get("/validation-success")
.header("host", "localhost:80"))
.andExpect(status().isOk());
The host
header won't be null and your tests should pass.