I want to perform a test on a controller method which throws an exception. The method is something like this:
@RequestMapping("/do")
public ResponseEntity doIt(@RequestBody Request request) throws Exception {
throw new NullPointerException();
}
When I try to test this method with following code part,
mockMvc.perform(post("/do")
.contentType(MediaType.APPLICATION_JSON)
.content(JSON.toJson(request)))
NestedServletException
is thrown from Spring libraries. How can I test that NullPointerException
is thrown instead of NestedServletException
?
Aucun commentaire:
Enregistrer un commentaire