26
26
import org .jspecify .annotations .Nullable ;
27
27
import org .junit .jupiter .api .function .Executable ;
28
28
import org .junit .jupiter .api .function .ThrowingSupplier ;
29
+ import org .junit .platform .commons .annotation .Contract ;
29
30
import org .opentest4j .MultipleFailuresError ;
30
31
31
32
/**
@@ -116,6 +117,7 @@ protected Assertions() {
116
117
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
117
118
* generic return type {@code V}.
118
119
*/
120
+ @ Contract (value = " -> fail" )
119
121
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
120
122
public static <V > V fail () {
121
123
AssertionUtils .fail ();
@@ -136,6 +138,7 @@ public static <V> V fail() {
136
138
* Stream.of().map(entry -> fail("should not be called"));
137
139
* }</pre>
138
140
*/
141
+ @ Contract (value = "_ -> fail" )
139
142
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
140
143
public static <V > V fail (@ Nullable String message ) {
141
144
AssertionUtils .fail (message );
@@ -149,6 +152,7 @@ public static <V> V fail(@Nullable String message) {
149
152
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
150
153
* generic return type {@code V}.
151
154
*/
155
+ @ Contract (value = "_, _ -> fail" )
152
156
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
153
157
public static <V > V fail (@ Nullable String message , @ Nullable Throwable cause ) {
154
158
AssertionUtils .fail (message , cause );
@@ -161,6 +165,7 @@ public static <V> V fail(@Nullable String message, @Nullable Throwable cause) {
161
165
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
162
166
* generic return type {@code V}.
163
167
*/
168
+ @ Contract (value = "_ -> fail" )
164
169
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
165
170
public static <V > V fail (@ Nullable Throwable cause ) {
166
171
AssertionUtils .fail (cause );
@@ -174,6 +179,7 @@ public static <V> V fail(@Nullable Throwable cause) {
174
179
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
175
180
* generic return type {@code V}.
176
181
*/
182
+ @ Contract (value = "_ -> fail" )
177
183
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
178
184
public static <V > V fail (Supplier <@ Nullable String > messageSupplier ) {
179
185
AssertionUtils .fail (messageSupplier );
@@ -185,6 +191,7 @@ public static <V> V fail(Supplier<@Nullable String> messageSupplier) {
185
191
/**
186
192
* <em>Assert</em> that the supplied {@code condition} is {@code true}.
187
193
*/
194
+ @ Contract (value = "false -> fail" )
188
195
public static void assertTrue (boolean condition ) {
189
196
AssertTrue .assertTrue (condition );
190
197
}
@@ -193,6 +200,7 @@ public static void assertTrue(boolean condition) {
193
200
* <em>Assert</em> that the supplied {@code condition} is {@code true}.
194
201
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
195
202
*/
203
+ @ Contract (value = "false, _ -> fail" )
196
204
public static void assertTrue (boolean condition , Supplier <@ Nullable String > messageSupplier ) {
197
205
AssertTrue .assertTrue (condition , messageSupplier );
198
206
}
@@ -216,6 +224,7 @@ public static void assertTrue(BooleanSupplier booleanSupplier, @Nullable String
216
224
* <em>Assert</em> that the supplied {@code condition} is {@code true}.
217
225
* <p>Fails with the supplied failure {@code message}.
218
226
*/
227
+ @ Contract (value = "false, _ -> fail" )
219
228
public static void assertTrue (boolean condition , @ Nullable String message ) {
220
229
AssertTrue .assertTrue (condition , message );
221
230
}
@@ -233,6 +242,7 @@ public static void assertTrue(BooleanSupplier booleanSupplier, Supplier<@Nullabl
233
242
/**
234
243
* <em>Assert</em> that the supplied {@code condition} is {@code false}.
235
244
*/
245
+ @ Contract (value = "true -> fail" )
236
246
public static void assertFalse (boolean condition ) {
237
247
AssertFalse .assertFalse (condition );
238
248
}
@@ -241,6 +251,7 @@ public static void assertFalse(boolean condition) {
241
251
* <em>Assert</em> that the supplied {@code condition} is {@code false}.
242
252
* <p>Fails with the supplied failure {@code message}.
243
253
*/
254
+ @ Contract (value = "true, _ -> fail" )
244
255
public static void assertFalse (boolean condition , @ Nullable String message ) {
245
256
AssertFalse .assertFalse (condition , message );
246
257
}
@@ -249,6 +260,7 @@ public static void assertFalse(boolean condition, @Nullable String message) {
249
260
* <em>Assert</em> that the supplied {@code condition} is {@code false}.
250
261
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
251
262
*/
263
+ @ Contract (value = "true, _ -> fail" )
252
264
public static void assertFalse (boolean condition , Supplier <@ Nullable String > messageSupplier ) {
253
265
AssertFalse .assertFalse (condition , messageSupplier );
254
266
}
@@ -281,6 +293,7 @@ public static void assertFalse(BooleanSupplier booleanSupplier, Supplier<@Nullab
281
293
/**
282
294
* <em>Assert</em> that {@code actual} is {@code null}.
283
295
*/
296
+ @ Contract (value = "!null -> fail" )
284
297
public static void assertNull (@ Nullable Object actual ) {
285
298
AssertNull .assertNull (actual );
286
299
}
@@ -289,6 +302,7 @@ public static void assertNull(@Nullable Object actual) {
289
302
* <em>Assert</em> that {@code actual} is {@code null}.
290
303
* <p>Fails with the supplied failure {@code message}.
291
304
*/
305
+ @ Contract (value = "!null, _ -> fail" )
292
306
public static void assertNull (@ Nullable Object actual , @ Nullable String message ) {
293
307
AssertNull .assertNull (actual , message );
294
308
}
@@ -297,6 +311,7 @@ public static void assertNull(@Nullable Object actual, @Nullable String message)
297
311
* <em>Assert</em> that {@code actual} is {@code null}.
298
312
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
299
313
*/
314
+ @ Contract (value = "!null, _ -> fail" )
300
315
public static void assertNull (@ Nullable Object actual , Supplier <@ Nullable String > messageSupplier ) {
301
316
AssertNull .assertNull (actual , messageSupplier );
302
317
}
@@ -306,6 +321,7 @@ public static void assertNull(@Nullable Object actual, Supplier<@Nullable String
306
321
/**
307
322
* <em>Assert</em> that {@code actual} is not {@code null}.
308
323
*/
324
+ @ Contract (value = "null -> fail" )
309
325
public static void assertNotNull (@ Nullable Object actual ) {
310
326
AssertNotNull .assertNotNull (actual );
311
327
}
@@ -314,6 +330,7 @@ public static void assertNotNull(@Nullable Object actual) {
314
330
* <em>Assert</em> that {@code actual} is not {@code null}.
315
331
* <p>Fails with the supplied failure {@code message}.
316
332
*/
333
+ @ Contract (value = "null, _ -> fail" )
317
334
public static void assertNotNull (@ Nullable Object actual , @ Nullable String message ) {
318
335
AssertNotNull .assertNotNull (actual , message );
319
336
}
@@ -322,6 +339,7 @@ public static void assertNotNull(@Nullable Object actual, @Nullable String messa
322
339
* <em>Assert</em> that {@code actual} is not {@code null}.
323
340
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
324
341
*/
342
+ @ Contract (value = "null, _ -> fail" )
325
343
public static void assertNotNull (@ Nullable Object actual , Supplier <@ Nullable String > messageSupplier ) {
326
344
AssertNotNull .assertNotNull (actual , messageSupplier );
327
345
}
@@ -3696,6 +3714,7 @@ public static void assertTimeoutPreemptively(Duration timeout, Executable execut
3696
3714
* @since 5.8
3697
3715
*/
3698
3716
@ API (status = STABLE , since = "5.10" )
3717
+ @ Contract ("_, null -> fail" )
3699
3718
public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ) {
3700
3719
return AssertInstanceOf .assertInstanceOf (expectedType , actualValue );
3701
3720
}
@@ -3712,6 +3731,7 @@ public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object act
3712
3731
* @since 5.8
3713
3732
*/
3714
3733
@ API (status = STABLE , since = "5.10" )
3734
+ @ Contract ("_, null, _ -> fail" )
3715
3735
public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ,
3716
3736
@ Nullable String message ) {
3717
3737
return AssertInstanceOf .assertInstanceOf (expectedType , actualValue , message );
@@ -3729,6 +3749,7 @@ public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object act
3729
3749
*
3730
3750
* @since 5.8
3731
3751
*/
3752
+ @ Contract ("_, null, _ -> fail" )
3732
3753
@ API (status = STABLE , since = "5.10" )
3733
3754
public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ,
3734
3755
Supplier <@ Nullable String > messageSupplier ) {
0 commit comments