0N/A/**
1668N/A * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A */
0N/A
0N/A/*
1879N/A * @test
1879N/A * @bug 6380849
1879N/A * @summary Tests PropertyEditor finder
1879N/A * @author Sergey Malenkov
0N/A * @compile -XDignore.symbol.file TestPropertyEditor.java
0N/A * @run main TestPropertyEditor
0N/A */
0N/A
0N/Aimport editors.SecondBeanEditor;
0N/Aimport editors.ThirdBeanEditor;
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Font;
0N/Aimport java.beans.PropertyEditor;
0N/Aimport java.beans.PropertyEditorManager;
0N/A
0N/Aimport com.sun.beans.editors.BooleanEditor;
0N/Aimport com.sun.beans.editors.ByteEditor;
0N/Aimport com.sun.beans.editors.ColorEditor;
0N/Aimport com.sun.beans.editors.DoubleEditor;
0N/Aimport com.sun.beans.editors.EnumEditor;
0N/Aimport com.sun.beans.editors.FloatEditor;
0N/Aimport com.sun.beans.editors.FontEditor;
0N/Aimport com.sun.beans.editors.IntegerEditor;
0N/Aimport com.sun.beans.editors.LongEditor;
0N/Aimport com.sun.beans.editors.ShortEditor;
0N/Aimport com.sun.beans.editors.StringEditor;
0N/A
0N/Apublic class TestPropertyEditor implements Runnable {
0N/A
0N/A private enum Enumeration {
0N/A FIRST, SECOND, THIRD
0N/A }
0N/A
0N/A private static final String[] SEARCH_PATH = { "editors" }; // NON-NLS: package name
0N/A
0N/A public static void main(String[] args) throws InterruptedException {
0N/A TestPropertyEditor test = new TestPropertyEditor();
0N/A test.run();
0N/A // the following tests fails on previous build
0N/A ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name
0N/A Thread thread = new Thread(group, test);
0N/A thread.start();
0N/A thread.join();
0N/A }
0N/A
0N/A private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {
0N/A PropertyEditor actual = PropertyEditorManager.findEditor(type);
0N/A if ((actual == null) && (expected != null)) {
0N/A throw new Error("expected editor is not found");
0N/A }
0N/A if ((actual != null) && !actual.getClass().equals(expected)) {
0N/A throw new Error("found unexpected editor");
0N/A }
0N/A }
0N/A
0N/A public void run() {
0N/A PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class);
0N/A
0N/A test(FirstBean.class, FirstBeanEditor.class);
0N/A test(SecondBean.class, null);
0N/A test(ThirdBean.class, ThirdBeanEditor.class);
0N/A // test editors for default primitive types
0N/A test(Byte.TYPE, ByteEditor.class);
0N/A test(Short.TYPE, ShortEditor.class);
0N/A test(Integer.TYPE, IntegerEditor.class);
0N/A test(Long.TYPE, LongEditor.class);
0N/A test(Boolean.TYPE, BooleanEditor.class);
0N/A test(Float.TYPE, FloatEditor.class);
0N/A test(Double.TYPE, DoubleEditor.class);
0N/A // test editors for default object types
0N/A test(Byte.class, ByteEditor.class);
0N/A test(Short.class, ShortEditor.class);
0N/A test(Integer.class, IntegerEditor.class);
0N/A test(Long.class, LongEditor.class);
0N/A test(Boolean.class, BooleanEditor.class);
0N/A test(Float.class, FloatEditor.class);
0N/A test(Double.class, DoubleEditor.class);
0N/A test(String.class, StringEditor.class);
0N/A test(Color.class, ColorEditor.class);
0N/A test(Font.class, FontEditor.class);
0N/A test(Enumeration.class, EnumEditor.class);
0N/A
0N/A PropertyEditorManager.registerEditor(ThirdBean.class, null);
0N/A PropertyEditorManager.setEditorSearchPath(SEARCH_PATH);
0N/A
0N/A test(FirstBean.class, FirstBeanEditor.class);
0N/A test(SecondBean.class, SecondBeanEditor.class);
0N/A test(ThirdBean.class, ThirdBeanEditor.class);
0N/A // test editors for default primitive types
0N/A test(Byte.TYPE, ByteEditor.class);
0N/A test(Short.TYPE, ShortEditor.class);
0N/A test(Integer.TYPE, IntegerEditor.class);
0N/A test(Long.TYPE, LongEditor.class);
0N/A test(Boolean.TYPE, BooleanEditor.class);
0N/A test(Float.TYPE, FloatEditor.class);
0N/A test(Double.TYPE, DoubleEditor.class);
0N/A // test editors for default object types
0N/A test(Byte.class, null);
0N/A test(Short.class, null);
0N/A test(Integer.class, null);
0N/A test(Long.class, null);
0N/A test(Boolean.class, null);
0N/A test(Float.class, null);
0N/A test(Double.class, null);
0N/A test(String.class, null);
0N/A test(Color.class, null);
0N/A test(Font.class, null);
0N/A test(Enumeration.class, EnumEditor.class);
0N/A }
0N/A}
0N/A