From 6ed9607f74398d054e1cda7d1c02da80c2d93180 Mon Sep 17 00:00:00 2001 From: Jason Gerlowski Date: Mon, 23 Jul 2018 20:37:04 -0400 Subject: [PATCH] SOLR-12555: Add add'l expectThrows() test helper --- .../src/java/org/apache/lucene/util/LuceneTestCase.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 expectThrows(Class 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 expectThrows(Class 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); } /**