SOLR-12555: Add add'l expectThrows() test helper

This commit is contained in:
Jason Gerlowski 2018-07-23 20:37:04 -04:00
parent de16baaa2f
commit 6ed9607f74
1 changed files with 6 additions and 1 deletions

View File

@ -2665,6 +2665,11 @@ public abstract class LuceneTestCase extends Assert {
/** Checks a specific exception class is thrown by the given runnable, and returns it. */ /** Checks a specific exception class is thrown by the given runnable, and returns it. */
public static <T extends Throwable> T expectThrows(Class<T> expectedType, ThrowingRunnable runnable) { public static <T extends Throwable> T expectThrows(Class<T> expectedType, ThrowingRunnable runnable) {
return expectThrows(expectedType, "Expected exception "+ expectedType.getSimpleName() + " but no exception was thrown", runnable);
}
/** Checks a specific exception class is thrown by the given runnable, and returns it. */
public static <T extends Throwable> T expectThrows(Class<T> expectedType, String noExceptionMessage, ThrowingRunnable runnable) {
try { try {
runnable.run(); runnable.run();
} catch (Throwable e) { } catch (Throwable e) {
@ -2675,7 +2680,7 @@ public abstract class LuceneTestCase extends Assert {
assertion.initCause(e); assertion.initCause(e);
throw assertion; throw assertion;
} }
throw new AssertionFailedError("Expected exception " + expectedType.getSimpleName() + " but no exception was thrown"); throw new AssertionFailedError(noExceptionMessage);
} }
/** /**