I would like to know how can I test to see if my controller is throwing an exception?
Of course, the exception will cause the controller to redirect to another page or will return 500 status code. In my case, it returns 500 Internal Server Error based on what FF says.
I tried saying that I expect this status code but it doesn't work. How can I achieve this?
mockMvc.perform(get("/p/get"))
.andDo(print())
.andExpect(status().is(500));
Edit:
Controller:
@RequestMapping("/get")
public List<A> get(){
return myService.getP(0);
}
MyService - getP():
public List<A> getP(int l){
if(l<=0){
throw new IllegalArgumentException();
}
}
Somehow I want to treat this exception.