Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertSame.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 AssertSame} is a collection of utility methods that support asserting
19 * two objects are the same.
20 *
21 * @since 5.0
22 */
23 class AssertSame {
24
25 private AssertSame() {
26 /* no-op */
27 }
28
29 static void assertSame(Object expected, Object actual) {
30 assertSame(expected, actual, (String) null);
31 }
32
33 static void assertSame(Object expected, Object actual, String message) {
34 if (expected != actual) {
35 failNotSame(expected, actual, message);
36 }
37 }
38
39 static void assertSame(Object expected, Object actual, Supplier<String> messageSupplier) {
40 if (expected != actual) {
41 failNotSame(expected, actual, messageSupplier);
42 }
43 }
44
45 private static void failNotSame(Object expected, Object actual, Object messageOrSupplier) {
46 assertionFailure() //
47 .message(messageOrSupplier) //
48 .expected(expected) //
49 .actual(actual) //
50 .buildAndThrow();
51 }
52
53 }