1 /* 2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6380849 27 * @summary Tests PropertyEditor finder 28 * @author Sergey Malenkov 29 * @compile -XDignore.symbol.file TestPropertyEditor.java 30 * @run main TestPropertyEditor 31 * @key headful 32 */ 33 34 import editors.SecondBeanEditor; 35 import editors.ThirdBeanEditor; 36 37 import java.awt.Color; 38 import java.awt.Font; 39 import java.beans.PropertyEditor; 40 import java.beans.PropertyEditorManager; 41 42 import com.sun.beans.editors.BooleanEditor; 43 import com.sun.beans.editors.ByteEditor; 44 import com.sun.beans.editors.ColorEditor; 45 import com.sun.beans.editors.DoubleEditor; 46 import com.sun.beans.editors.EnumEditor; 47 import com.sun.beans.editors.FloatEditor; 48 import com.sun.beans.editors.FontEditor; 49 import com.sun.beans.editors.IntegerEditor; 50 import com.sun.beans.editors.LongEditor; 51 import com.sun.beans.editors.ShortEditor; 52 import com.sun.beans.editors.StringEditor; 53 54 public class TestPropertyEditor implements Runnable { 55 56 private enum Enumeration { 57 FIRST, SECOND, THIRD 58 } 59 60 private static final String[] SEARCH_PATH = { "editors" }; // NON-NLS: package name 61 62 public static void main(String[] args) throws InterruptedException { 63 TestPropertyEditor test = new TestPropertyEditor(); 64 test.run(); 65 // the following tests fails on previous build 66 ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name 67 Thread thread = new Thread(group, test); 68 thread.start(); 69 thread.join(); 70 } 71 72 private static void test(Class<?> type, Class<? extends PropertyEditor> expected) { 73 PropertyEditor actual = PropertyEditorManager.findEditor(type); 74 if ((actual == null) && (expected != null)) { 75 throw new Error("expected editor is not found"); 76 } 77 if ((actual != null) && !actual.getClass().equals(expected)) { 78 throw new Error("found unexpected editor"); 79 } 80 } 81 82 public void run() { 83 PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class); 84 85 test(FirstBean.class, FirstBeanEditor.class); 86 test(SecondBean.class, null); 87 test(ThirdBean.class, ThirdBeanEditor.class); 88 // test editors for default primitive types 89 test(Byte.TYPE, ByteEditor.class); 90 test(Short.TYPE, ShortEditor.class); 91 test(Integer.TYPE, IntegerEditor.class); 92 test(Long.TYPE, LongEditor.class); 93 test(Boolean.TYPE, BooleanEditor.class); 94 test(Float.TYPE, FloatEditor.class); 95 test(Double.TYPE, DoubleEditor.class); 96 // test editors for default object types 97 test(Byte.class, ByteEditor.class); 98 test(Short.class, ShortEditor.class); 99 test(Integer.class, IntegerEditor.class); 100 test(Long.class, LongEditor.class); 101 test(Boolean.class, BooleanEditor.class); 102 test(Float.class, FloatEditor.class); 103 test(Double.class, DoubleEditor.class); 104 test(String.class, StringEditor.class); 105 test(Color.class, ColorEditor.class); 106 test(Font.class, FontEditor.class); 107 test(Enumeration.class, EnumEditor.class); 108 109 PropertyEditorManager.registerEditor(ThirdBean.class, null); 110 PropertyEditorManager.setEditorSearchPath(SEARCH_PATH); 111 112 test(FirstBean.class, FirstBeanEditor.class); 113 test(SecondBean.class, SecondBeanEditor.class); 114 test(ThirdBean.class, ThirdBeanEditor.class); 115 // test editors for default primitive types 116 test(Byte.TYPE, ByteEditor.class); 117 test(Short.TYPE, ShortEditor.class); 118 test(Integer.TYPE, IntegerEditor.class); 119 test(Long.TYPE, LongEditor.class); 120 test(Boolean.TYPE, BooleanEditor.class); 121 test(Float.TYPE, FloatEditor.class); 122 test(Double.TYPE, DoubleEditor.class); 123 // test editors for default object types 124 test(Byte.class, null); 125 test(Short.class, null); 126 test(Integer.class, null); 127 test(Long.class, null); 128 test(Boolean.class, null); 129 test(Float.class, null); 130 test(Double.class, null); 131 test(String.class, null); 132 test(Color.class, null); 133 test(Font.class, null); 134 test(Enumeration.class, EnumEditor.class); 135 } 136 }