Path: blob/master/test/jdk/java/beans/Introspector/8132566/OverrideUserDefPropertyInfoTest.java
41153 views
/*1* Copyright (c) 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*/2223import java.beans.BeanDescriptor;24import java.beans.BeanInfo;25import java.beans.BeanProperty;26import java.beans.EventSetDescriptor;27import java.beans.IntrospectionException;28import java.beans.Introspector;29import java.beans.JavaBean;30import java.beans.MethodDescriptor;31import java.beans.PropertyChangeListener;32import java.beans.PropertyDescriptor;33import java.beans.SimpleBeanInfo;3435/**36* @test37* @bug 8132566 8132669 813193938* @summary Check if the derived class overrides39* the parent's user-defined property info.40* @author a.stepanov41*/4243public class OverrideUserDefPropertyInfoTest {4445private static final boolean baseFlag = true;46private static final boolean childFlag = false;4748@JavaBean(description = "CHILD")49public static class C extends Base {5051private int x;5253@BeanProperty(54bound = childFlag,55expert = childFlag,56hidden = childFlag,57preferred = childFlag,58required = childFlag,59visualUpdate = childFlag,60description = "CHILDPROPERTY",61enumerationValues = {"javax.swing.SwingConstants.BOTTOM"}62)63@Override64public void setX(int v) { x = v; }65@Override66public int getX() { return x; }6768@Override69public void addPropertyChangeListener(PropertyChangeListener l) {}70@Override71public void removePropertyChangeListener(PropertyChangeListener l) {}72}7374public static class Base {75private int x;76public void setX(int v) { x = v; }77public int getX() { return x; }78public void addPropertyChangeListener(PropertyChangeListener l) {}79public void removePropertyChangeListener(PropertyChangeListener l) {}80}8182public static class BaseBeanInfo extends SimpleBeanInfo {8384@Override85public BeanDescriptor getBeanDescriptor() {86BeanDescriptor d = new BeanDescriptor(Base.class, null);87d.setShortDescription("BASE");88return d;89}9091@Override92public PropertyDescriptor[] getPropertyDescriptors() {93PropertyDescriptor[] p = new PropertyDescriptor[1];9495try {96p[0] = new PropertyDescriptor ("x", Base.class, "getX", null);97p[0].setShortDescription("BASEPROPERTY");98p[0].setBound (baseFlag);99p[0].setExpert(baseFlag);100p[0].setHidden(baseFlag);101p[0].setPreferred(baseFlag);102p[0].setValue("required", baseFlag);103p[0].setValue("visualUpdate", baseFlag);104p[0].setValue("enumerationValues",105new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});106} catch(IntrospectionException e) { e.printStackTrace(); }107108return p;109}110111@Override112public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; }113@Override114public MethodDescriptor[] getMethodDescriptors() {115MethodDescriptor[] m = new MethodDescriptor[1];116try {117m[0] = new MethodDescriptor(Base.class.getMethod("setX", new Class[] {int.class}));118m[0].setDisplayName("");119}120catch( NoSuchMethodException | SecurityException e) {}121return m;122}123124@Override125public int getDefaultPropertyIndex() { return -1; }126@Override127public int getDefaultEventIndex() { return -1; }128@Override129public java.awt.Image getIcon(int iconKind) { return null; }130}131132public static void main(String[] args) throws Exception {133134BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);135Checker.checkEq("description",136i.getBeanDescriptor().getShortDescription(), "CHILD");137138PropertyDescriptor[] pds = i.getPropertyDescriptors();139Checker.checkEq("number of properties", pds.length, 1);140PropertyDescriptor p = pds[0];141142Checker.checkEq("property description", p.getShortDescription(), "CHILDPROPERTY");143Checker.checkEq("isBound", p.isBound(), childFlag);144Checker.checkEq("isExpert", p.isExpert(), childFlag);145Checker.checkEq("isHidden", p.isHidden(), childFlag);146Checker.checkEq("isPreferred", p.isPreferred(), childFlag);147Checker.checkEq("required", p.getValue("required"), childFlag);148Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), childFlag);149150Checker.checkEnumEq("enumerationValues", p.getValue("enumerationValues"),151new Object[]{"BOTTOM", 3, "javax.swing.SwingConstants.BOTTOM"});152}153}154155156