1 /*
2 * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import org.junit.jupiter.api.Test;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertNotNull;
27 import static org.junit.jupiter.api.Assertions.assertNull;
28 import static org.junit.jupiter.api.Assertions.assertThrows;
29 import static org.junit.jupiter.api.Assertions.assertTrue;
30
31 /*
32 * @test
33 * @summary Basic tests for java.lang.IdentityException
34 * @enablePreview
35 * @run junit ${test.main.class}
36 */
37 class IdentityExceptionBasicTest {
38
39 /*
40 * Verify the no-arg constructor
41 */
42 @Test
43 void testNoArg() throws Exception {
44 // verify that there's no exception message and no cause
45 final IdentityException ex = new IdentityException();
46 assertNull(ex.getMessage(), "unexpected exception message");
47 assertNull(ex.getCause(), "unexpected cause");
48 }
49
50 /*
51 * Verify the constructor which takes the String arg
52 */
53 @Test
54 void testStringArg() throws Exception {
55 // verify that null is allowed
56 final IdentityException ex = new IdentityException((String) null);
57 assertNull(ex.getMessage(), "unexpected exception message");
58 assertNull(ex.getCause(), "unexpected cause");
59
60 // verify custom exception message
61 final IdentityException ex2 = new IdentityException("hello world");
62 assertEquals("hello world", ex2.getMessage(), "unexpected exception message");
63 assertNull(ex2.getCause(), "unexpected cause");
64 }
65 }