Skip to content

Apache Lucene open-source search software

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

Jason Gerlowski6ed9607f7439
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
index 6be8d037fd6..baf72c1ddd1 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
@@ -2665,6 +2665,11 @@ public abstract class LuceneTestCase extends Assert {
/** 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) {
+ 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 {
runnable.run();
} catch (Throwable e) {
@@ -2675,7 +2680,7 @@ public abstract class LuceneTestCase extends Assert {
assertion.initCause(e);
throw assertion;
}
- throw new AssertionFailedError("Expected exception " + expectedType.getSimpleName() + " but no exception was thrown");
+ throw new AssertionFailedError(noExceptionMessage);
}
/**