Path: blob/master/test/jdk/java/beans/Introspector/Test6447751.java
41149 views
/*1* Copyright (c) 2010, 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 644775126* @summary Tests automatic search for customizers27* @author Sergey Malenkov28*/2930import java.awt.Component;31import java.beans.Customizer;32import java.beans.Introspector;33import java.beans.IntrospectionException;34import java.beans.SimpleBeanInfo;35import java.beans.BeanDescriptor;36import java.beans.PropertyChangeListener;3738public class Test6447751 {3940public static void main(String[] args) {41test(Manual.class, AutomaticCustomizer.class);42test(Illegal.class, null);43test(Automatic.class, AutomaticCustomizer.class);44}4546private static void test(Class<?> type, Class<?> expected) {47Class<?> actual;48try {49actual = Introspector.getBeanInfo(type).getBeanDescriptor().getCustomizerClass();50}51catch (IntrospectionException exception) {52throw new Error("unexpected error", exception);53}54if (actual != expected) {55StringBuilder sb = new StringBuilder();56sb.append("bean ").append(type).append(": ");57if (expected != null) {58sb.append("expected ").append(expected);59if (actual != null) {60sb.append(", but ");61}62}63if (actual != null) {64sb.append("found ").append(actual);65}66throw new Error(sb.toString());67}68}6970public static class Automatic {71}72public static class AutomaticCustomizer extends Component implements Customizer {73public void setObject(Object bean) {74throw new UnsupportedOperationException();75}76}7778public static class Illegal {79}80public static class IllegalCustomizer implements Customizer {81public void setObject(Object bean) {82throw new UnsupportedOperationException();83}84public void addPropertyChangeListener(PropertyChangeListener listener) {85throw new UnsupportedOperationException();86}87public void removePropertyChangeListener(PropertyChangeListener listener) {88throw new UnsupportedOperationException();89}90}9192public static class Manual {93}94public static class ManualBeanInfo extends SimpleBeanInfo {95public BeanDescriptor getBeanDescriptor() {96return new BeanDescriptor(Manual.class, AutomaticCustomizer.class);97}98}99}100101102