Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertTrue.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.BooleanSupplier;
16 import java.util.function.Supplier;
17
18 /**
19 * {@code AssertTrue} is a collection of utility methods that support asserting
20 * {@code true} in tests.
21 *
22 * @since 5.0
23 */
24 class AssertTrue {
25
26 private AssertTrue() {
27 /* no-op */
28 }
29
30 static void assertTrue(boolean condition) {
31 assertTrue(condition, (String) null);
32 }
33
34 static void assertTrue(boolean condition, String message) {
35 if (!condition) {
36 failNotTrue(message);
37 }
38 }
39
40 static void assertTrue(boolean condition, Supplier<String> messageSupplier) {
41 if (!condition) {
42 failNotTrue(messageSupplier);
43 }
44 }
45
46 static void assertTrue(BooleanSupplier booleanSupplier) {
47 assertTrue(booleanSupplier.getAsBoolean(), (String) null);
48 }
49
50 static void assertTrue(BooleanSupplier booleanSupplier, String message) {
51 assertTrue(booleanSupplier.getAsBoolean(), message);
52 }
53
54 static void assertTrue(BooleanSupplier booleanSupplier, Supplier<String> messageSupplier) {
55 assertTrue(booleanSupplier.getAsBoolean(), messageSupplier);
56 }
57
58 private static void failNotTrue(Object messageOrSupplier) {
59 assertionFailure() //
60 .message(messageOrSupplier) //
61 .expected(true) //
62 .actual(false) //
63 .buildAndThrow();
64 }
65
66 }