1414
1515import org .assertj .core .annotation .CanIgnoreReturnValue ;
1616import org .assertj .core .internal .Failures ;
17+ import org .assertj .core .internal .annotation .Contract ;
1718
1819/**
1920 * Common failures.
@@ -42,6 +43,7 @@ public static void setRemoveAssertJRelatedElementsFromStackTrace(boolean removeA
4243 * @throws AssertionError with the given message.
4344 */
4445 @ CanIgnoreReturnValue
46+ @ Contract ("_ -> fail" )
4547 public static <T > T fail (String failureMessage ) {
4648 throw Failures .instance ().failure (failureMessage );
4749 }
@@ -56,6 +58,7 @@ public static <T> T fail(String failureMessage) {
5658 * @since 3.26.0
5759 */
5860 @ CanIgnoreReturnValue
61+ @ Contract (" -> fail" )
5962 public static <T > T fail () {
6063 // pass an empty string because passing null results in a "null" error message.
6164 return fail ("" );
@@ -71,6 +74,7 @@ public static <T> T fail() {
7174 * @throws AssertionError with the given built message.
7275 */
7376 @ CanIgnoreReturnValue
77+ @ Contract ("_, _ -> fail" )
7478 public static <T > T fail (String failureMessage , Object ... args ) {
7579 return fail (String .format (failureMessage , args ));
7680 }
@@ -85,6 +89,7 @@ public static <T> T fail(String failureMessage, Object... args) {
8589 * @throws AssertionError with the given message and with the {@link Throwable} that caused the failure.
8690 */
8791 @ CanIgnoreReturnValue
92+ @ Contract ("_, _ -> fail" )
8893 public static <T > T fail (String failureMessage , Throwable realCause ) {
8994 AssertionError error = Failures .instance ().failure (failureMessage );
9095 error .initCause (realCause );
@@ -100,6 +105,7 @@ public static <T> T fail(String failureMessage, Throwable realCause) {
100105 * @throws AssertionError with the {@link Throwable} that caused the failure.
101106 */
102107 @ CanIgnoreReturnValue
108+ @ Contract ("_ -> fail" )
103109 public static <T > T fail (Throwable realCause ) {
104110 return fail (null , realCause );
105111 }
@@ -114,9 +120,10 @@ public static <T> T fail(Throwable realCause) {
114120 * @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had
115121 * not been.
116122 *
117- * {@link Fail #shouldHaveThrown(Class)} can be used as a replacement.
123+ * @see #shouldHaveThrown(Class)
118124 */
119125 @ CanIgnoreReturnValue
126+ @ Contract ("_ -> fail" )
120127 public static <T > T failBecauseExceptionWasNotThrown (Class <? extends Throwable > throwableClass ) {
121128 return shouldHaveThrown (throwableClass );
122129 }
@@ -132,6 +139,7 @@ public static <T> T failBecauseExceptionWasNotThrown(Class<? extends Throwable>
132139 * not been.
133140 */
134141 @ CanIgnoreReturnValue
142+ @ Contract ("_ -> fail" )
135143 public static <T > T shouldHaveThrown (Class <? extends Throwable > throwableClass ) {
136144 throw Failures .instance ().expectedThrowableNotThrown (throwableClass );
137145 }
0 commit comments