[testng] 105/160: Add assertThrows(Class, ThrowingRunnable)
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:22:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag testng-6.9.5
in repository testng.
commit 367e4ad6481e0b9eb81c455e893c25add5004628
Author: Ryan Schmitt <rschmitt at pobox.com>
Date: Thu Jun 11 13:40:41 2015 -0700
Add assertThrows(Class, ThrowingRunnable)
This adds a convenience method that simply delegates to expectThrows and
discards its result. There are three reasons for this:
(1) It prevents warnings: discarding a Throwable return value can raise
red flags
(2) It facilitates convention: "assert" is called solely for its side
effect, whereas "expect" returns something but first asserts
something about its return value
(3) It enhances discoverability: most people will look for methods
prefixed with "assert", and indeed, the return value of expectThrows
is often unneeded
---
src/main/java/org/testng/Assert.java | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/testng/Assert.java b/src/main/java/org/testng/Assert.java
index e56ba3f..902815a 100644
--- a/src/main/java/org/testng/Assert.java
+++ b/src/main/java/org/testng/Assert.java
@@ -971,12 +971,27 @@ public class Assert {
* @param runnable A function that is expected to throw an exception when invoked
*/
public static void assertThrows(ThrowingRunnable runnable) {
- expectThrows(Throwable.class, runnable);
+ assertThrows(Throwable.class, runnable);
}
/**
* Asserts that {@code runnable} throws an exception of type {@code throwableClass} when
- * executed. If it does, the exception object is returned. If it does not throw an exception, an
+ * executed. If it does not throw an exception, an {@link AssertionError} is thrown. If it
+ * throws the wrong type of exception, an {@code AssertionError} is thrown describing the
+ * mismatch; the exception that was actually thrown can be obtained by calling {@link
+ * AssertionError#getCause}.
+ *
+ * @param throwableClass the expected type of the exception
+ * @param runnable A function that is expected to throw an exception when invoked
+ */
+ @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+ public static <T extends Throwable> void assertThrows(Class<T> throwableClass, ThrowingRunnable runnable) {
+ expectThrows(throwableClass, runnable);
+ }
+
+ /**
+ * Asserts that {@code runnable} throws an exception of type {@code throwableClass} when
+ * executed and returns the exception. If {@code runnable} does not throw an exception, an
* {@link AssertionError} is thrown. If it throws the wrong type of exception, an {@code
* AssertionError} is thrown describing the mismatch; the exception that was actually thrown can
* be obtained by calling {@link AssertionError#getCause}.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list