Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/PropertyEditor/6380849/TestPropertyEditor.java
47490 views
/**1* Copyright (c) 2009, 2012, 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 638084926* @summary Tests PropertyEditor finder27* @author Sergey Malenkov28* @compile -XDignore.symbol.file TestPropertyEditor.java29* @run main TestPropertyEditor30* @key headful31*/3233import editors.SecondBeanEditor;34import editors.ThirdBeanEditor;3536import java.awt.Color;37import java.awt.Font;38import java.beans.PropertyEditor;39import java.beans.PropertyEditorManager;4041import com.sun.beans.editors.BooleanEditor;42import com.sun.beans.editors.ByteEditor;43import com.sun.beans.editors.ColorEditor;44import com.sun.beans.editors.DoubleEditor;45import com.sun.beans.editors.EnumEditor;46import com.sun.beans.editors.FloatEditor;47import com.sun.beans.editors.FontEditor;48import com.sun.beans.editors.IntegerEditor;49import com.sun.beans.editors.LongEditor;50import com.sun.beans.editors.ShortEditor;51import com.sun.beans.editors.StringEditor;5253public class TestPropertyEditor implements Runnable {5455private enum Enumeration {56FIRST, SECOND, THIRD57}5859private static final String[] SEARCH_PATH = { "editors" }; // NON-NLS: package name6061public static void main(String[] args) throws InterruptedException {62TestPropertyEditor test = new TestPropertyEditor();63test.run();64// the following tests fails on previous build65ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name66Thread thread = new Thread(group, test);67thread.start();68thread.join();69}7071private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {72PropertyEditor actual = PropertyEditorManager.findEditor(type);73if ((actual == null) && (expected != null)) {74throw new Error("expected editor is not found");75}76if ((actual != null) && !actual.getClass().equals(expected)) {77throw new Error("found unexpected editor");78}79}8081public void run() {82PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class);8384test(FirstBean.class, FirstBeanEditor.class);85test(SecondBean.class, null);86test(ThirdBean.class, ThirdBeanEditor.class);87// test editors for default primitive types88test(Byte.TYPE, ByteEditor.class);89test(Short.TYPE, ShortEditor.class);90test(Integer.TYPE, IntegerEditor.class);91test(Long.TYPE, LongEditor.class);92test(Boolean.TYPE, BooleanEditor.class);93test(Float.TYPE, FloatEditor.class);94test(Double.TYPE, DoubleEditor.class);95// test editors for default object types96test(Byte.class, ByteEditor.class);97test(Short.class, ShortEditor.class);98test(Integer.class, IntegerEditor.class);99test(Long.class, LongEditor.class);100test(Boolean.class, BooleanEditor.class);101test(Float.class, FloatEditor.class);102test(Double.class, DoubleEditor.class);103test(String.class, StringEditor.class);104test(Color.class, ColorEditor.class);105test(Font.class, FontEditor.class);106test(Enumeration.class, EnumEditor.class);107108PropertyEditorManager.registerEditor(ThirdBean.class, null);109PropertyEditorManager.setEditorSearchPath(SEARCH_PATH);110111test(FirstBean.class, FirstBeanEditor.class);112test(SecondBean.class, SecondBeanEditor.class);113test(ThirdBean.class, ThirdBeanEditor.class);114// test editors for default primitive types115test(Byte.TYPE, ByteEditor.class);116test(Short.TYPE, ShortEditor.class);117test(Integer.TYPE, IntegerEditor.class);118test(Long.TYPE, LongEditor.class);119test(Boolean.TYPE, BooleanEditor.class);120test(Float.TYPE, FloatEditor.class);121test(Double.TYPE, DoubleEditor.class);122// test editors for default object types123test(Byte.class, null);124test(Short.class, null);125test(Integer.class, null);126test(Long.class, null);127test(Boolean.class, null);128test(Float.class, null);129test(Double.class, null);130test(String.class, null);131test(Color.class, null);132test(Font.class, null);133test(Enumeration.class, EnumEditor.class);134}135}136137138