Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertNull.java

raw symbols SCIP
1 /*
2 * Copyright 2015-2024 the original author or authors.
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v2.0 which
6 * accompanies this distribution and is available at
7 *
8 * https://www.eclipse.org/legal/epl-v20.html
9 */
10
11 package org.junit.jupiter.api;
12
13 import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;
14
15 import java.util.function.Supplier;
16
17 /**
18 * {@code AssertNull} is a collection of utility methods that support asserting
19 * there is no object.
20 *
21 * @since 5.0
22 */
23 class AssertNull {
24
25 private AssertNull() {
26 /* no-op */
27 }
28
29 static void assertNull(Object actual) {
30 assertNull(actual, (String) null);
31 }
32
33 static void assertNull(Object actual, String message) {
34 if (actual != null) {
35 failNotNull(actual, message);
36 }
37 }
38
39 static void assertNull(Object actual, Supplier<String> messageSupplier) {
40 if (actual != null) {
41 failNotNull(actual, messageSupplier);
42 }
43 }
44
45 private static void failNotNull(Object actual, Object messageOrSupplier) {
46 assertionFailure() //
47 .message(messageOrSupplier) //
48 .expected(null) //
49 .actual(actual) //
50 .buildAndThrow();
51 }
52
53 }