title: Should I always use Lambda Expressions for Exception Tests?
body: <p>I always tested my exceptions with annotations.</p>
  
  <pre><code>@Test (expected = Exception.class)
  public void test1() {
    methodToTest() // throws an exception
  }
  </code></pre>
  
  <p>I finally switched to Java 8, and I came across lambda Expressions. Now there is another option to get the desired result.</p>
  
  <pre><code>@Test
  public void test2() {
    assertThrows(Exception.class, () -&gt; methodToTest());
  }
  
  public static &lt;X extends Throwable&gt; Throwable assertThrows(
    final Class&lt;X&gt; exceptionClass, final Runnable block) {
      try {
        block.run();
      } catch(Throwable ex) {
        if (exceptionClass.isInstance(ex))
          return ex;
      }
      fail("Failed to throw expected exception");
      return null;
    }
  </code></pre>
  
  <p>I understand that with the second version you can check for single methods more precisely, and you don't have to worry about other methods within a single test that could throw the expected exception as well. Furthermore, with an "assertThrows" method, all tests can have the same structure, because it all comes down to a call for an assertion.</p>
  
  <p>Besides those two points, <strong>are there any pro arguments for the new way?</strong> For me, it feels like its still superior to go with the annotations, as long as I am only testing a single method within a single test.</p>