Path: blob/master/test/jdk/java/beans/Introspector/4058433/TestSwingContainer.java
41152 views
/*1* Copyright (c) 2014, 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.Introspector;26import java.util.Objects;27import javax.swing.SwingContainer;2829/**30* @test31* @bug 405843332* @summary Tests the SwingContainer annotation33* @author Sergey Malenkov34*/35public class TestSwingContainer {3637public static void main(String[] args) throws Exception {38test(X.class, null, null);39test(H.class, true, "");40test(G.class, true, "");41test(F.class, true, "method");42test(E.class, false, "");43test(D.class, false, "");44test(C.class, true, "");45test(B.class, false, "method");46test(A.class, true, "method");47}4849private static void test(Class<?> type, Object iC, Object cD) throws Exception {50System.out.println(type);51BeanInfo info = Introspector.getBeanInfo(type);52BeanDescriptor bd = info.getBeanDescriptor();53test(bd, "isContainer", iC);54test(bd, "containerDelegate", cD);55}5657private static void test(BeanDescriptor bd, String name, Object expected) {58Object value = bd.getValue(name);59System.out.println("\t" + name + " = " + value);60if (!Objects.equals(value, expected)) {61throw new Error(name + ": expected = " + expected + "; actual = " + value);62}63}6465public static class X {66}6768@SwingContainer()69public static class H {70}7172@SwingContainer(delegate = "")73public static class G {74}7576@SwingContainer(delegate = "method")77public static class F {78}7980@SwingContainer(false)81public static class E {82}8384@SwingContainer(value = false, delegate = "")85public static class D {86}8788@SwingContainer(value = true, delegate = "")89public static class C {90}9192@SwingContainer(value = false, delegate = "method")93public static class B {94}9596@SwingContainer(value = true, delegate = "method")97public static class A {98}99}100101102