Path: blob/master/test/jdk/java/beans/Introspector/6380849/TestBeanInfo.java
41153 views
/*1* Copyright (c) 2010, 2012, 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 638084926* @summary Tests BeanInfo finder27* @modules java.desktop/java.beans:open28* @author Sergey Malenkov29*/3031import beans.FirstBean;32import beans.FirstBeanBeanInfo;33import beans.SecondBean;34import beans.ThirdBean;3536import infos.SecondBeanBeanInfo;37import infos.ThirdBeanBeanInfo;3839import java.beans.BeanInfo;40import java.beans.Introspector;41import java.lang.reflect.Method;4243public class TestBeanInfo implements Runnable {4445private static final String[] SEARCH_PATH = { "infos" }; // NON-NLS: package name4647public static void main(String[] args) throws InterruptedException {48TestBeanInfo test = new TestBeanInfo();49test.run();50// the following tests fails on previous build51ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name52Thread thread = new Thread(group, test);53thread.start();54thread.join();55}5657private static void test(Class<?> type, Class<? extends BeanInfo> expected) {58BeanInfo actual;59try {60actual = Introspector.getBeanInfo(type);61type = actual.getClass();62Method method = type.getDeclaredMethod("getTargetBeanInfo"); // NON-NLS: method name63method.setAccessible(true);64actual = (BeanInfo) method.invoke(actual);65}66catch (Exception exception) {67throw new Error("unexpected error", exception);68}69if ((actual == null) && (expected != null)) {70throw new Error("expected info is not found");71}72if ((actual != null) && !actual.getClass().equals(expected)) {73throw new Error("found unexpected info");74}75}7677private boolean passed;7879public void run() {80Introspector.flushCaches();8182test(FirstBean.class, FirstBeanBeanInfo.class);83test(SecondBean.class, null);84test(ThirdBean.class, null);85test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);8687Introspector.setBeanInfoSearchPath(SEARCH_PATH);88Introspector.flushCaches();8990test(FirstBean.class, FirstBeanBeanInfo.class);91test(SecondBean.class, SecondBeanBeanInfo.class);92test(ThirdBean.class, null);93test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);94}95}969798