Debian Codegraph @

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