コード例 #1
0
ファイル: Exceptions.java プロジェクト: Groostav/LinqALike
 public static void assertDoesNotThrow(Action runnable) {
   try {
     runnable.run();
   } catch (Exception instigatingException) {
     throw new AssertionError("expected clause not to throw, but it did.", instigatingException);
   }
 }
コード例 #2
0
ファイル: Exceptions.java プロジェクト: Groostav/LinqALike
 @Nonnull
 public static <TException extends Throwable> TException assertThrows(
     Class<TException> expectedException, Action runnable) {
   assert !expectedException.equals(AssertionError.class)
       : "cant assert on assertion errors since thats how we fail a test!";
   try {
     runnable.run();
     fail("expected action to throw " + expectedException.getSimpleName() + " but it did not.");
     return null;
   } catch (Throwable exception) {
     if (!expectedException.isInstance(exception)) {
       throw exception;
     }
     return expectedException.cast(exception);
   }
 }