Path: blob/master/test/jdk/java/security/Provider/Equals.java
41149 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4918769 813018126* @summary make sure Provider.equals() behaves as expected with the id attributes27* @author Andreas Sterbenz28*/2930import java.security.*;3132public class Equals {3334public static void main(String[] args) throws Exception {35Provider p1 = new P1("foo", "1.0", "foo");36Provider p1b = new P1("foo", "1.0", "foo");37Provider p2 = new P2("foo", "1.0", "foo");38System.out.println(p1.entrySet());39if (p1.equals(p2)) {40throw new Exception("Objects are equal");41}42if (p1.equals(p1b) == false) {43throw new Exception("Objects not equal");44}45p1.clear();46if (p1.equals(p1b) == false) {47throw new Exception("Objects not equal");48}49p1.put("Provider.id name", "bar");50p1.remove("Provider.id version");51if (p1.equals(p1b) == false) {52throw new Exception("Objects not equal");53}54}5556private static class P1 extends Provider {57P1(String name, String version, String info) {58super(name, version, info);59}60}6162private static class P2 extends Provider {63P2(String name, String version, String info) {64super(name, version, info);65}66}6768}697071