Stack Exchange
Mock mvc expect exception
I have a controller and some method, which throws CustomException:
@GetMapping
ResponseEntity<Void> getOriginalUrl() {
  ...
  throw new CustomException("my message");
  ...
}

I want to test it.
Test:
 @Rule
 public ExpectedException thrown = ExpectedException.none();

 @Test
 public void testGetOriginalUrl() throws Exception {
 mvc.perform(get(...)
            .contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isNotFound());

    thrown.expect(CustomException.class);
    thrown.expectMessage("my message");
 }

But it does not work. How i can test it?

Even if you any exception server is going to return 500 internal server error, so you should just validated the status code 
 mvc.perform(get(...)
        .contentType(MediaType.APPLICATION_JSON))
        .andExpect(status()isInternalServerError())
        .andExpect(status().reason(containsString("my message")));


Yes, but I want to check the exception type and message.

you can check the message but not exception
