mirror of https://github.com/apache/lucene.git
SOLR-12555: Add add'l expectThrows() test helper
This commit is contained in:
parent
de16baaa2f
commit
6ed9607f74
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue