Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/MultiUIDefaults/Test6860438.java
38840 views
/*1* Copyright (c) 2009, 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/* @test24@bug 686043825@summary Tests various MultiUIDefaults methods26@author Peter Zhelezniakov27@run main Test686043828*/2930import java.util.Enumeration;31import java.util.Map.Entry;32import java.util.Set;33import javax.swing.UIManager;3435public class Test686043836{37static final String KEY = "Test6860438.key";38static final String VALUE = "Test6860438.value";3940void check(Object key, Object value, boolean present, int size) {41check(UIManager.get(key) == value, "UIManager.get()");42check(UIManager.getDefaults().size() == size, "MultiUIDefaults.size()");4344checkEnumeration(UIManager.getDefaults().keys(),45key, present, "MultiUIDefaults.keys()");46checkEnumeration(UIManager.getDefaults().elements(),47value, present, "MultiUIDefaults.elements()");4849// check MultiUIDefaults.entrySet()50boolean found = false;51Set<Entry<Object, Object>> entries = UIManager.getDefaults().entrySet();52for (Entry<Object, Object> e: entries) {53if (e.getKey() == key) {54check(e.getValue() == value, "MultiUIDefaults.entrySet()");55found = true;56}57}58check(found == present, "MultiUIDefaults.entrySet()");59}6061void checkEnumeration(Enumeration<Object> e, Object elem,62boolean present, String error) {63boolean found = false;64while (e.hasMoreElements()) {65if (e.nextElement() == elem) {66found = true;67}68}69check(found == present, error);70}7172void check(boolean condition, String methodName) {73if (! condition) {74throw new RuntimeException(methodName + " failed");75}76}7778void test() {79int size = UIManager.getDefaults().size();8081// create a new value, size increases82UIManager.getLookAndFeelDefaults().put(KEY, VALUE);83check(KEY, VALUE, true, size + 1);8485// override the value, size remains the same86UIManager.put(KEY, VALUE);87check(KEY, VALUE, true, size + 1);8889// remove the value, size decreases90UIManager.getDefaults().remove(KEY);91check(KEY, null, false, size);92}9394public static void main(String[] args) {95new Test6860438().test();96}97}9899100