From 1d174861f0b64f97ab0722bb324a760bfb02f567 Mon Sep 17 00:00:00 2001 From: Stefan Birkner Date: Wed, 1 Jan 2020 18:05:50 +0100 Subject: [PATCH] Add a link to assertThrows in exception testing Provide information about alternatives to the expected parameter which can be used to overcome the limitations of expected. This is an improvement for JUnit 4.13 to the fix for #806 (84dcb64cf07eba08fd7ef4de3a6aaf21f4944157). --- src/main/java/org/junit/Test.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/junit/Test.java b/src/main/java/org/junit/Test.java index 0a9b7aa3e299..1db6fc7ab073 100644 --- a/src/main/java/org/junit/Test.java +++ b/src/main/java/org/junit/Test.java @@ -1,5 +1,7 @@ package org.junit; +import org.junit.function.ThrowingRunnable; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -37,8 +39,16 @@ * new ArrayList<Object>().get(1); * } * - * If the exception's message or one of its properties should be verified, the - * {@link org.junit.rules.ExpectedException ExpectedException} rule can be used. Further + * + * Using the parameter expected for exception testing comes with + * some limitations: only the exception's type can be checked and it is not + * possible to precisely specify the code that throws the exception. Therefore + * JUnit 4 has improved its support for exception testing with + * {@link Assert#assertThrows(Class, ThrowingRunnable)} and the + * {@link org.junit.rules.ExpectedException ExpectedException} rule. + * With assertThrows the code that throws the exception can be + * precisely specified. If the exception's message or one of its properties + * should be verified, the ExpectedException rule can be used. Further * information about exception testing can be found at the * JUnit Wiki. *