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