Path: blob/master/test/jdk/java/beans/Introspector/7084904/Test7084904.java
41152 views
/*1* Copyright (c) 2014, 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*/22import bean.Derived;23import java.lang.reflect.Method;24/*25* @test26* @bug 708490427* @summary Compares reflection and bean introspection28* @library ..29* @run main/othervm -Djava.security.manager=allow Test708490430* @author Sergey Malenkov31*/32public class Test7084904 {33public static void main(String[] args) throws Exception {34System.setSecurityManager(new SecurityManager());35Derived bean = new Derived();36Class<?> type = bean.getClass();37Method method1 = test("reflection", bean, type.getMethod("isAllowed"));38Method method2 = test("bean introspection", bean, BeanUtils.getPropertyDescriptor(type, "allowed").getReadMethod());39if (!method1.equals(method2)) {40throw new Error("first method is not equal to the second one");41}42}4344private static Method test(String name, Object bean, Method method) throws Exception {45System.out.println("\n === use " + name + " ===");46System.out.println(method);47System.out.println("declaring " + method.getDeclaringClass());48System.out.println("invocation result: " + method.invoke(bean));49return method;50}51}525354