25
25
import org .jspecify .annotations .Nullable ;
26
26
import org .junit .jupiter .api .function .Executable ;
27
27
import org .junit .jupiter .api .function .ThrowingSupplier ;
28
+ import org .junit .platform .commons .annotation .Contract ;
28
29
import org .opentest4j .MultipleFailuresError ;
29
30
30
31
/**
@@ -115,6 +116,7 @@ protected Assertions() {
115
116
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
116
117
* generic return type {@code V}.
117
118
*/
119
+ @ Contract (" -> fail" )
118
120
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
119
121
public static <V > V fail () {
120
122
AssertionUtils .fail ();
@@ -135,6 +137,7 @@ public static <V> V fail() {
135
137
* Stream.of().map(entry -> fail("should not be called"));
136
138
* }</pre>
137
139
*/
140
+ @ Contract ("_ -> fail" )
138
141
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
139
142
public static <V > V fail (@ Nullable String message ) {
140
143
AssertionUtils .fail (message );
@@ -148,6 +151,7 @@ public static <V> V fail(@Nullable String message) {
148
151
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
149
152
* generic return type {@code V}.
150
153
*/
154
+ @ Contract ("_, _ -> fail" )
151
155
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
152
156
public static <V > V fail (@ Nullable String message , @ Nullable Throwable cause ) {
153
157
AssertionUtils .fail (message , cause );
@@ -160,6 +164,7 @@ public static <V> V fail(@Nullable String message, @Nullable Throwable cause) {
160
164
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
161
165
* generic return type {@code V}.
162
166
*/
167
+ @ Contract ("_ -> fail" )
163
168
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
164
169
public static <V > V fail (@ Nullable Throwable cause ) {
165
170
AssertionUtils .fail (cause );
@@ -173,6 +178,7 @@ public static <V> V fail(@Nullable Throwable cause) {
173
178
* <p>See Javadoc for {@link #fail(String)} for an explanation of this method's
174
179
* generic return type {@code V}.
175
180
*/
181
+ @ Contract ("_ -> fail" )
176
182
@ SuppressWarnings ({ "NullAway" , "TypeParameterUnusedInFormals" })
177
183
public static <V > V fail (Supplier <@ Nullable String > messageSupplier ) {
178
184
AssertionUtils .fail (messageSupplier );
@@ -184,6 +190,7 @@ public static <V> V fail(Supplier<@Nullable String> messageSupplier) {
184
190
/**
185
191
* <em>Assert</em> that the supplied {@code condition} is {@code true}.
186
192
*/
193
+ @ Contract ("false -> fail" )
187
194
public static void assertTrue (boolean condition ) {
188
195
AssertTrue .assertTrue (condition );
189
196
}
@@ -192,6 +199,7 @@ public static void assertTrue(boolean condition) {
192
199
* <em>Assert</em> that the supplied {@code condition} is {@code true}.
193
200
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
194
201
*/
202
+ @ Contract ("false, _ -> fail" )
195
203
public static void assertTrue (boolean condition , Supplier <@ Nullable String > messageSupplier ) {
196
204
AssertTrue .assertTrue (condition , messageSupplier );
197
205
}
@@ -215,6 +223,7 @@ public static void assertTrue(BooleanSupplier booleanSupplier, @Nullable String
215
223
* <em>Assert</em> that the supplied {@code condition} is {@code true}.
216
224
* <p>Fails with the supplied failure {@code message}.
217
225
*/
226
+ @ Contract ("false, _ -> fail" )
218
227
public static void assertTrue (boolean condition , @ Nullable String message ) {
219
228
AssertTrue .assertTrue (condition , message );
220
229
}
@@ -232,6 +241,7 @@ public static void assertTrue(BooleanSupplier booleanSupplier, Supplier<@Nullabl
232
241
/**
233
242
* <em>Assert</em> that the supplied {@code condition} is {@code false}.
234
243
*/
244
+ @ Contract ("true -> fail" )
235
245
public static void assertFalse (boolean condition ) {
236
246
AssertFalse .assertFalse (condition );
237
247
}
@@ -240,6 +250,7 @@ public static void assertFalse(boolean condition) {
240
250
* <em>Assert</em> that the supplied {@code condition} is {@code false}.
241
251
* <p>Fails with the supplied failure {@code message}.
242
252
*/
253
+ @ Contract ("true, _ -> fail" )
243
254
public static void assertFalse (boolean condition , @ Nullable String message ) {
244
255
AssertFalse .assertFalse (condition , message );
245
256
}
@@ -248,6 +259,7 @@ public static void assertFalse(boolean condition, @Nullable String message) {
248
259
* <em>Assert</em> that the supplied {@code condition} is {@code false}.
249
260
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
250
261
*/
262
+ @ Contract ("true, _ -> fail" )
251
263
public static void assertFalse (boolean condition , Supplier <@ Nullable String > messageSupplier ) {
252
264
AssertFalse .assertFalse (condition , messageSupplier );
253
265
}
@@ -280,6 +292,7 @@ public static void assertFalse(BooleanSupplier booleanSupplier, Supplier<@Nullab
280
292
/**
281
293
* <em>Assert</em> that {@code actual} is {@code null}.
282
294
*/
295
+ @ Contract ("!null -> fail" )
283
296
public static void assertNull (@ Nullable Object actual ) {
284
297
AssertNull .assertNull (actual );
285
298
}
@@ -288,6 +301,7 @@ public static void assertNull(@Nullable Object actual) {
288
301
* <em>Assert</em> that {@code actual} is {@code null}.
289
302
* <p>Fails with the supplied failure {@code message}.
290
303
*/
304
+ @ Contract ("!null, _ -> fail" )
291
305
public static void assertNull (@ Nullable Object actual , @ Nullable String message ) {
292
306
AssertNull .assertNull (actual , message );
293
307
}
@@ -296,6 +310,7 @@ public static void assertNull(@Nullable Object actual, @Nullable String message)
296
310
* <em>Assert</em> that {@code actual} is {@code null}.
297
311
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
298
312
*/
313
+ @ Contract ("!null, _ -> fail" )
299
314
public static void assertNull (@ Nullable Object actual , Supplier <@ Nullable String > messageSupplier ) {
300
315
AssertNull .assertNull (actual , messageSupplier );
301
316
}
@@ -305,6 +320,7 @@ public static void assertNull(@Nullable Object actual, Supplier<@Nullable String
305
320
/**
306
321
* <em>Assert</em> that {@code actual} is not {@code null}.
307
322
*/
323
+ @ Contract ("null -> fail" )
308
324
public static void assertNotNull (@ Nullable Object actual ) {
309
325
AssertNotNull .assertNotNull (actual );
310
326
}
@@ -313,6 +329,7 @@ public static void assertNotNull(@Nullable Object actual) {
313
329
* <em>Assert</em> that {@code actual} is not {@code null}.
314
330
* <p>Fails with the supplied failure {@code message}.
315
331
*/
332
+ @ Contract ("null, _ -> fail" )
316
333
public static void assertNotNull (@ Nullable Object actual , @ Nullable String message ) {
317
334
AssertNotNull .assertNotNull (actual , message );
318
335
}
@@ -321,6 +338,7 @@ public static void assertNotNull(@Nullable Object actual, @Nullable String messa
321
338
* <em>Assert</em> that {@code actual} is not {@code null}.
322
339
* <p>If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
323
340
*/
341
+ @ Contract ("null, _ -> fail" )
324
342
public static void assertNotNull (@ Nullable Object actual , Supplier <@ Nullable String > messageSupplier ) {
325
343
AssertNotNull .assertNotNull (actual , messageSupplier );
326
344
}
@@ -3665,6 +3683,7 @@ public static void assertTimeoutPreemptively(Duration timeout, Executable execut
3665
3683
* @since 5.8
3666
3684
*/
3667
3685
@ API (status = STABLE , since = "5.10" )
3686
+ @ Contract ("_, null -> fail" )
3668
3687
public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ) {
3669
3688
return AssertInstanceOf .assertInstanceOf (expectedType , actualValue );
3670
3689
}
@@ -3681,6 +3700,7 @@ public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object act
3681
3700
* @since 5.8
3682
3701
*/
3683
3702
@ API (status = STABLE , since = "5.10" )
3703
+ @ Contract ("_, null, _ -> fail" )
3684
3704
public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ,
3685
3705
@ Nullable String message ) {
3686
3706
return AssertInstanceOf .assertInstanceOf (expectedType , actualValue , message );
@@ -3698,6 +3718,7 @@ public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object act
3698
3718
*
3699
3719
* @since 5.8
3700
3720
*/
3721
+ @ Contract ("_, null, _ -> fail" )
3701
3722
@ API (status = STABLE , since = "5.10" )
3702
3723
public static <T > T assertInstanceOf (Class <T > expectedType , @ Nullable Object actualValue ,
3703
3724
Supplier <@ Nullable String > messageSupplier ) {
0 commit comments