code: public static <T extends Throwable> T exceptionThrownBy(
          Statement statement, Class<T> type) {
          try {
              statement.evaluate();
          } catch (Throwable e) {
              if (type.isAssignableFrom(e.getClass()))
                  return (T) e;
              else
                  throw new ExceptionWithWrongTypeThrownFailure(type, e);
          }
          throw new ExceptionNotThrownFailure();
      }
docs: Executes the provided statement and returns the exception that
  has been thrown by the statement if it has the specified type.
  This is useful for writing tests for exceptions according to the
  AAA (Arrange-Act-Assert) pattern in case that you need to check
  properties of the exception.
  <p>Example:
  <pre>
  FooException exception = exceptionThrownBy(
  () -&gt; { throw new FooException(3); }, FooException.class);
  assertEquals(3, exception.getValue())
  </pre>
  
  @param statement an arbitrary piece of code.
  @param type the type of the exception that should be exposed.
  @param <T> the type of the exception that should be exposed.
  @return The exception thrown by the statement.
  @throws ExceptionNotThrownFailure if the statement didn't throw
  an exception.
  @throws ExceptionWithWrongTypeThrownFailure if the statement
  threw an exception of a different type.
  @see #exceptionThrownBy(Statement)