OidEquals.java revision 12256:7fe849a62bea
1/*
2 * Copyright (c) 2015, 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/*
25 * @test
26 * @bug 8022444
27 * @summary Test ObjectIdentifier.equals(Object obj)
28 */
29
30import sun.security.util.ObjectIdentifier;
31
32public class OidEquals {
33    public static void main(String[] args) throws Exception {
34        ObjectIdentifier oid1 = new ObjectIdentifier("1.3.6.1.4.1.42.2.17");
35        ObjectIdentifier oid2 =
36                new ObjectIdentifier(new int[]{1, 3, 6, 1, 4, 1, 42, 2, 17});
37        ObjectIdentifier oid3 = new ObjectIdentifier("1.2.3.4");
38
39        assertEquals(oid1, oid1);
40        assertEquals(oid1, oid2);
41        assertNotEquals(oid1, oid3);
42        assertNotEquals(oid1, "1.3.6.1.4.1.42.2.17");
43
44        System.out.println("Tests passed.");
45    }
46
47    static void assertEquals(ObjectIdentifier oid, Object obj)
48            throws Exception {
49        if (!oid.equals(obj)) {
50            throw new Exception("The ObjectIdentifier " + oid.toString() +
51                    " should be equal to the Object " + obj.toString());
52        }
53    }
54
55    static void assertNotEquals(ObjectIdentifier oid, Object obj)
56            throws Exception {
57        if (oid.equals(obj)) {
58            throw new Exception("The ObjectIdentifier " + oid.toString() +
59                    " should not be equal to the Object " + obj.toString());
60        }
61    }
62}
63