2525import org .jspecify .annotations .Nullable ;
2626import org .junit .jupiter .api .function .Executable ;
2727import org .junit .jupiter .api .function .ThrowingSupplier ;
28+ import org .junit .platform .commons .annotation .Contract ;
2829import org .opentest4j .MultipleFailuresError ;
2930
3031/**
@@ -115,6 +116,7 @@ protected Assertions() {
115116 * <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
116117 * generic return type {@code V}.
117118 */
119+ @ Contract (" -> fail" )
118120 @ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
119121 public static <V > V fail () {
120122 AssertionUtils .fail ();
@@ -135,6 +137,7 @@ public static <V> V fail() {
135137 * Stream.of().map(entry -> fail("should not be called"));
136138 * }</pre>
137139 */
140+ @ Contract ("_ -> fail" )
138141 @ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
139142 public static <V > V fail (@ Nullable String message ) {
140143 AssertionUtils .fail (message );
@@ -148,6 +151,7 @@ public static <V> V fail(@Nullable String message) {
148151 * <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
149152 * generic return type {@code V}.
150153 */
154+ @ Contract ("_, _ -> fail" )
151155 @ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
152156 public static <V > V fail (@ Nullable String message , @ Nullable Throwable cause ) {
153157 AssertionUtils .fail (message , cause );
@@ -160,6 +164,7 @@ public static <V> V fail(@Nullable String message, @Nullable Throwable cause) {
160164 * <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
161165 * generic return type {@code V}.
162166 */
167+ @ Contract ("_ -> fail" )
163168 @ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
164169 public static <V > V fail (@ Nullable Throwable cause ) {
165170 AssertionUtils .fail (cause );
@@ -173,6 +178,7 @@ public static <V> V fail(@Nullable Throwable cause) {
173178 * <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
174179 * generic return type {@code V}.
175180 */
181+ @ Contract ("_ -> fail" )
176182 @ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
177183 public static <V > V fail (Supplier <@ Nullable String > messageSupplier ) {
178184 AssertionUtils .fail (messageSupplier );
@@ -184,6 +190,7 @@ public static <V> V fail(Supplier<@Nullable String> messageSupplier) {
184190 /**
185191 * <em>Assert</em> that the supplied {@code condition} is {@code true}.
186192 */
193+ @ Contract ("false -> fail" )
187194 public static void assertTrue (boolean condition ) {
188195 AssertTrue .assertTrue (condition );
189196 }
@@ -192,6 +199,7 @@ public static void assertTrue(boolean condition) {
192199 * <em>Assert</em> that the supplied {@code condition} is {@code true}.
193200 * <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
194201 */
202+ @ Contract ("false, _ -> fail" )
195203 public static void assertTrue (boolean condition , Supplier <@ Nullable String > messageSupplier ) {
196204 AssertTrue .assertTrue (condition , messageSupplier );
197205 }
@@ -215,6 +223,7 @@ public static void assertTrue(BooleanSupplier booleanSupplier, @Nullable String
215223 * <em>Assert</em> that the supplied {@code condition} is {@code true}.
216224 * <p>Fails with the supplied failure {@code message}.
217225 */
226+ @ Contract ("false, _ -> fail" )
218227 public static void assertTrue (boolean condition , @ Nullable String message ) {
219228 AssertTrue .assertTrue (condition , message );
220229 }
@@ -232,6 +241,7 @@ public static void assertTrue(BooleanSupplier booleanSupplier, Supplier<@Nullabl
232241 /**
233242 * <em>Assert</em> that the supplied {@code condition} is {@code false}.
234243 */
244+ @ Contract ("true -> fail" )
235245 public static void assertFalse (boolean condition ) {
236246 AssertFalse .assertFalse (condition );
237247 }
@@ -240,6 +250,7 @@ public static void assertFalse(boolean condition) {
240250 * <em>Assert</em> that the supplied {@code condition} is {@code false}.
241251 * <p>Fails with the supplied failure {@code message}.
242252 */
253+ @ Contract ("true, _ -> fail" )
243254 public static void assertFalse (boolean condition , @ Nullable String message ) {
244255 AssertFalse .assertFalse (condition , message );
245256 }
@@ -248,6 +259,7 @@ public static void assertFalse(boolean condition, @Nullable String message) {
248259 * <em>Assert</em> that the supplied {@code condition} is {@code false}.
249260 * <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
250261 */
262+ @ Contract ("true, _ -> fail" )
251263 public static void assertFalse (boolean condition , Supplier <@ Nullable String > messageSupplier ) {
252264 AssertFalse .assertFalse (condition , messageSupplier );
253265 }
@@ -280,6 +292,7 @@ public static void assertFalse(BooleanSupplier booleanSupplier, Supplier<@Nullab
280292 /**
281293 * <em>Assert</em> that {@code actual} is {@code null}.
282294 */
295+ @ Contract ("!null -> fail" )
283296 public static void assertNull (@ Nullable Object actual ) {
284297 AssertNull .assertNull (actual );
285298 }
@@ -288,6 +301,7 @@ public static void assertNull(@Nullable Object actual) {
288301 * <em>Assert</em> that {@code actual} is {@code null}.
289302 * <p>Fails with the supplied failure {@code message}.
290303 */
304+ @ Contract ("!null, _ -> fail" )
291305 public static void assertNull (@ Nullable Object actual , @ Nullable String message ) {
292306 AssertNull .assertNull (actual , message );
293307 }
@@ -296,6 +310,7 @@ public static void assertNull(@Nullable Object actual, @Nullable String message)
296310 * <em>Assert</em> that {@code actual} is {@code null}.
297311 * <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
298312 */
313+ @ Contract ("!null, _ -> fail" )
299314 public static void assertNull (@ Nullable Object actual , Supplier <@ Nullable String > messageSupplier ) {
300315 AssertNull .assertNull (actual , messageSupplier );
301316 }
@@ -305,6 +320,7 @@ public static void assertNull(@Nullable Object actual, Supplier<@Nullable String
305320 /**
306321 * <em>Assert</em> that {@code actual} is not {@code null}.
307322 */
323+ @ Contract ("null -> fail" )
308324 public static void assertNotNull (@ Nullable Object actual ) {
309325 AssertNotNull .assertNotNull (actual );
310326 }
@@ -313,6 +329,7 @@ public static void assertNotNull(@Nullable Object actual) {
313329 * <em>Assert</em> that {@code actual} is not {@code null}.
314330 * <p>Fails with the supplied failure {@code message}.
315331 */
332+ @ Contract ("null, _ -> fail" )
316333 public static void assertNotNull (@ Nullable Object actual , @ Nullable String message ) {
317334 AssertNotNull .assertNotNull (actual , message );
318335 }
@@ -321,6 +338,7 @@ public static void assertNotNull(@Nullable Object actual, @Nullable String messa
321338 * <em>Assert</em> that {@code actual} is not {@code null}.
322339 * <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
323340 */
341+ @ Contract ("null, _ -> fail" )
324342 public static void assertNotNull (@ Nullable Object actual , Supplier <@ Nullable String > messageSupplier ) {
325343 AssertNotNull .assertNotNull (actual , messageSupplier );
326344 }
@@ -3665,6 +3683,7 @@ public static void assertTimeoutPreemptively(Duration timeout, Executable execut
36653683 * @since 5.8
36663684 */
36673685 @ API (status = STABLE , since = "5.10" )
3686+ @ Contract ("_, null -> fail" )
36683687 public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ) {
36693688 return AssertInstanceOf .assertInstanceOf (expectedType , actualValue );
36703689 }
@@ -3681,6 +3700,7 @@ public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object act
36813700 * @since 5.8
36823701 */
36833702 @ API (status = STABLE , since = "5.10" )
3703+ @ Contract ("_, null, _ -> fail" )
36843704 public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ,
36853705 @ Nullable String message ) {
36863706 return AssertInstanceOf .assertInstanceOf (expectedType , actualValue , message );
@@ -3698,6 +3718,7 @@ public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object act
36983718 *
36993719 * @since 5.8
37003720 */
3721+ @ Contract ("_, null, _ -> fail" )
37013722 @ API (status = STABLE , since = "5.10" )
37023723 public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ,
37033724 Supplier <@ Nullable String > messageSupplier ) {
0 commit comments