'MocMVC test for RequestRejectedException giving "Expecting actual not to be null" error
I am trying to add Moc test for below method,
code method:
@Bean
public RequestRejectedHandler requestRejectedHandler() {
return new HttpStatusRequestRejectedHandler();
}
Moc test code
@Test
public void bad_request() throws Exception {
mockMvc
.perform(get("//.%252e/.%252e/.%252e/"))
.andExpect(status().is4xxClientError())
.andExpect(result -> assertTrue(result.getResolvedException() instanceof RequestRejectedException))
.andExpect(result -> assertEquals("Bad Request", result.getResolvedException().getMessage()));;
}
It is giving below error
Expecting actual not to be null
java.lang.AssertionError:
Expecting actual not to be null
at co.application.controller.ErrorControllerTest$requestError.lambda$bad_request$0(ErrorControllerTest.java:45)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:212)
at co.application.controller.ErrorControllerTest$requestError.bad_request(ErrorControllerTest.java:44)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
