Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/6380849/TestBeanInfo.java
47964 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* @author Sergey Malenkov28*/2930import beans.FirstBean;31import beans.FirstBeanBeanInfo;32import beans.SecondBean;33import beans.ThirdBean;3435import infos.SecondBeanBeanInfo;36import infos.ThirdBeanBeanInfo;3738import java.beans.BeanInfo;39import java.beans.Introspector;40import java.lang.reflect.Method;4142public class TestBeanInfo implements Runnable {4344private static final String[] SEARCH_PATH = { "infos" }; // NON-NLS: package name4546public static void main(String[] args) throws InterruptedException {47TestBeanInfo test = new TestBeanInfo();48test.run();49// the following tests fails on previous build50ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name51Thread thread = new Thread(group, test);52thread.start();53thread.join();54}5556private static void test(Class<?> type, Class<? extends BeanInfo> expected) {57BeanInfo actual;58try {59actual = Introspector.getBeanInfo(type);60type = actual.getClass();61Method method = type.getDeclaredMethod("getTargetBeanInfo"); // NON-NLS: method name62method.setAccessible(true);63actual = (BeanInfo) method.invoke(actual);64}65catch (Exception exception) {66throw new Error("unexpected error", exception);67}68if ((actual == null) && (expected != null)) {69throw new Error("expected info is not found");70}71if ((actual != null) && !actual.getClass().equals(expected)) {72throw new Error("found unexpected info");73}74}7576private boolean passed;7778public void run() {79Introspector.flushCaches();8081test(FirstBean.class, FirstBeanBeanInfo.class);82test(SecondBean.class, null);83test(ThirdBean.class, null);84test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);8586Introspector.setBeanInfoSearchPath(SEARCH_PATH);87Introspector.flushCaches();8889test(FirstBean.class, FirstBeanBeanInfo.class);90test(SecondBean.class, SecondBeanBeanInfo.class);91test(ThirdBean.class, null);92test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);93}94}959697