Path: blob/master/test/jdk/java/beans/PropertyEditor/6380849/TestPropertyEditor.java
41152 views
/*1* Copyright (c) 2009, 2015, 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* @modules java.desktop/com.sun.beans.editors29* @compile -XDignore.symbol.file TestPropertyEditor.java30* @run main TestPropertyEditor31* @key headful32*/3334import editors.SecondBeanEditor;35import editors.ThirdBeanEditor;3637import java.awt.Color;38import java.awt.Font;39import java.beans.PropertyEditor;40import java.beans.PropertyEditorManager;4142import com.sun.beans.editors.BooleanEditor;43import com.sun.beans.editors.ByteEditor;44import com.sun.beans.editors.ColorEditor;45import com.sun.beans.editors.DoubleEditor;46import com.sun.beans.editors.EnumEditor;47import com.sun.beans.editors.FloatEditor;48import com.sun.beans.editors.FontEditor;49import com.sun.beans.editors.IntegerEditor;50import com.sun.beans.editors.LongEditor;51import com.sun.beans.editors.ShortEditor;52import com.sun.beans.editors.StringEditor;5354public class TestPropertyEditor implements Runnable {5556private enum Enumeration {57FIRST, SECOND, THIRD58}5960private static final String[] SEARCH_PATH = { "editors" }; // NON-NLS: package name6162public static void main(String[] args) throws InterruptedException {63TestPropertyEditor test = new TestPropertyEditor();64test.run();65// the following tests fails on previous build66ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name67Thread thread = new Thread(group, test);68thread.start();69thread.join();70}7172private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {73PropertyEditor actual = PropertyEditorManager.findEditor(type);74if ((actual == null) && (expected != null)) {75throw new Error("expected editor is not found");76}77if ((actual != null) && !actual.getClass().equals(expected)) {78throw new Error("found unexpected editor");79}80}8182public void run() {83PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class);8485test(FirstBean.class, FirstBeanEditor.class);86test(SecondBean.class, null);87test(ThirdBean.class, ThirdBeanEditor.class);88// test editors for default primitive types89test(Byte.TYPE, ByteEditor.class);90test(Short.TYPE, ShortEditor.class);91test(Integer.TYPE, IntegerEditor.class);92test(Long.TYPE, LongEditor.class);93test(Boolean.TYPE, BooleanEditor.class);94test(Float.TYPE, FloatEditor.class);95test(Double.TYPE, DoubleEditor.class);96// test editors for default object types97test(Byte.class, ByteEditor.class);98test(Short.class, ShortEditor.class);99test(Integer.class, IntegerEditor.class);100test(Long.class, LongEditor.class);101test(Boolean.class, BooleanEditor.class);102test(Float.class, FloatEditor.class);103test(Double.class, DoubleEditor.class);104test(String.class, StringEditor.class);105test(Color.class, ColorEditor.class);106test(Font.class, FontEditor.class);107test(Enumeration.class, EnumEditor.class);108109PropertyEditorManager.registerEditor(ThirdBean.class, null);110PropertyEditorManager.setEditorSearchPath(SEARCH_PATH);111112test(FirstBean.class, FirstBeanEditor.class);113test(SecondBean.class, SecondBeanEditor.class);114test(ThirdBean.class, ThirdBeanEditor.class);115// test editors for default primitive types116test(Byte.TYPE, ByteEditor.class);117test(Short.TYPE, ShortEditor.class);118test(Integer.TYPE, IntegerEditor.class);119test(Long.TYPE, LongEditor.class);120test(Boolean.TYPE, BooleanEditor.class);121test(Float.TYPE, FloatEditor.class);122test(Double.TYPE, DoubleEditor.class);123// test editors for default object types124test(Byte.class, null);125test(Short.class, null);126test(Integer.class, null);127test(Long.class, null);128test(Boolean.class, null);129test(Float.class, null);130test(Double.class, null);131test(String.class, null);132test(Color.class, null);133test(Font.class, null);134test(Enumeration.class, EnumEditor.class);135}136}137138139