Path: blob/master/test/jdk/java/beans/Introspector/Test4498236.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 449823626* @summary Tests toString methods27* @author Sergey Malenkov28*/2930import java.awt.event.KeyEvent;31import java.awt.event.KeyListener;32import java.beans.BeanDescriptor;33import java.beans.EventSetDescriptor;34import java.beans.FeatureDescriptor;35import java.beans.IndexedPropertyChangeEvent;36import java.beans.IndexedPropertyDescriptor;37import java.beans.MethodDescriptor;38import java.beans.ParameterDescriptor;39import java.beans.PropertyChangeEvent;40import java.beans.PropertyDescriptor;41import java.lang.reflect.Method;4243public class Test4498236 {4445public static void main(String[] args) throws Exception {46PropertyChangeEvent event = new PropertyChangeEvent("source", null, null, null);47event.setPropagationId("id");48test("[propertyName=null; oldValue=null; newValue=null; propagationId=id; source=source]", event);49test("[propertyName=name; oldValue=old; newValue=new; propagationId=null; source=source]",50new PropertyChangeEvent("source", "name", "old", "new")51);52test("[propertyName=array; index=5; oldValue=old; newValue=new; propagationId=null; source=source]",53new IndexedPropertyChangeEvent("source", "array", "old", "new", 5)54);55FeatureDescriptor fd = new FeatureDescriptor();56fd.setName("n");57fd.setDisplayName("dn");58fd.setShortDescription("sd");59fd.setPreferred(true);60fd.setHidden(true);61fd.setExpert(true);62fd.setValue("first", "value");63test("[name=n; displayName=dn; shortDescription=sd; preferred; hidden; expert; values={first=value}]", fd);64test("[name=String; beanClass=class java.lang.String]",65new BeanDescriptor(String.class)66);67test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]",68new BeanDescriptor(Object.class, String.class)69);70test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]",71new BeanDescriptor(Object.class, String.class)72);73test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object)]",74new MethodDescriptor(Object.class.getMethod("equals", Object.class))75);76test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object); parameterDescriptors={java.beans.ParameterDescriptor[name=null]}]",77new MethodDescriptor(Object.class.getMethod("equals", Object.class), new ParameterDescriptor[] {78new ParameterDescriptor()79})80);81Class type = KeyListener.class;82String[] names = { "keyTyped", "keyPressed", "keyReleased" };83Method[] methods = new Method[names.length];84for (int i = 0; i < names.length; i++) {85methods[i] = type.getMethod(names[i], KeyEvent.class);86}87test("[name=key; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.getKeyListeners(); addListenerMethod=public void Test4498236.addKeyListener(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.removeKeyListener(java.awt.event.KeyListener)]",88new EventSetDescriptor(Test4498236.class, "key", type, names[0])89);90test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",91new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove")92);93test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",94new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove", "get")95);96test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",97new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type))98);99test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]",100new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type), Test4498236.class.getMethod("get"))101);102test("[name=value; propertyType=boolean; readMethod=public boolean Test4498236.isValue(); writeMethod=public void Test4498236.setValue(boolean)]",103new PropertyDescriptor("value", Test4498236.class)104);105test("[name=$$$]",106new PropertyDescriptor("$$$", Test4498236.class, null, null)107);108test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]",109new PropertyDescriptor("$$$", Test4498236.class, "getValue", null)110);111test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]",112new PropertyDescriptor("$$$", Test4498236.class, "getValue", "setValue")113);114test("[name=$$$]",115new PropertyDescriptor("$$$", null, null)116);117test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]",118new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), null)119);120test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]",121new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), Test4498236.class.getMethod("setValue", boolean.class))122);123test("[name=index; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",124new IndexedPropertyDescriptor("index", Test4498236.class)125);126test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",127new IndexedPropertyDescriptor("$$$", Test4498236.class, "getIndex", "setIndex", "getIndex", "setIndex")128);129test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]",130new IndexedPropertyDescriptor("$$$", Test4498236.class.getMethod("getIndex"), Test4498236.class.getMethod("setIndex", new int[0].getClass()), Test4498236.class.getMethod("getIndex", int.class), Test4498236.class.getMethod("setIndex", int.class, int.class) )131);132}133134public void addKeyListener(KeyListener listener) {135add(listener);136}137138public void removeKeyListener(KeyListener listener) {139remove(listener);140}141142public KeyListener getKeyListeners() {143return null;144}145146public void add(KeyListener listener) {147}148149public void remove(KeyListener listener) {150}151152public KeyListener get() {153return null;154}155156public boolean isValue() {157return true;158}159160public boolean getValue() {161return true;162}163164public void setValue(boolean value) {165}166167public int[] getIndex() {168return null;169}170171public int getIndex(int index) {172return 0;173}174175public void setIndex(int index, int value) {176}177178public void setIndex(int[] value) {179}180181private static void test(String expected, Object object) {182String actual = object.toString();183if (!actual.equals(object.getClass().getName() + expected)) {184throw new Error(actual);185}186}187}188189190