jdk/test/java/beans/Introspector/4058433/TestSwingContainer.java
changeset 31166 6448eff013a8
parent 25566 ba387c302edd
equal deleted inserted replaced
31165:42e11a4250b7 31166:6448eff013a8
     1 /*
     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    18  *
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
       
    23 
    23 import java.beans.BeanDescriptor;
    24 import java.beans.BeanDescriptor;
    24 import java.beans.BeanInfo;
    25 import java.beans.BeanInfo;
    25 import java.beans.Introspector;
    26 import java.beans.Introspector;
    26 import java.util.Objects;
    27 import java.util.Objects;
    27 import javax.swing.SwingContainer;
    28 import javax.swing.SwingContainer;
    28 /*
    29 
       
    30 /**
    29  * @test
    31  * @test
    30  * @bug 4058433
    32  * @bug 4058433
    31  * @summary Tests the SwingContainer annotation
    33  * @summary Tests the SwingContainer annotation
    32  * @author Sergey Malenkov
    34  * @author Sergey Malenkov
    33  */
    35  */
    34 public class TestSwingContainer {
    36 public class TestSwingContainer {
       
    37 
    35     public static void main(String[] args) throws Exception {
    38     public static void main(String[] args) throws Exception {
    36         test(X.class, null, null);
    39         test(X.class, null, null);
    37         test(T.class, true, null);
    40         test(H.class, true, "");
    38         test(D.class, true, "method");
    41         test(G.class, true, "");
    39         test(F.class, false, null);
    42         test(F.class, true, "method");
    40         test(A.class, false, "method");
    43         test(E.class, false, "");
       
    44         test(D.class, false, "");
       
    45         test(C.class, true, "");
       
    46         test(B.class, false, "method");
       
    47         test(A.class, true, "method");
    41     }
    48     }
    42 
    49 
    43     private static void test(Class<?> type, Object iC, Object cD) throws Exception {
    50     private static void test(Class<?> type, Object iC, Object cD) throws Exception {
    44         System.out.println(type);
    51         System.out.println(type);
    45         BeanInfo info = Introspector.getBeanInfo(type);
    52         BeanInfo info = Introspector.getBeanInfo(type);
    48         test(bd, "containerDelegate", cD);
    55         test(bd, "containerDelegate", cD);
    49     }
    56     }
    50 
    57 
    51     private static void test(BeanDescriptor bd, String name, Object expected) {
    58     private static void test(BeanDescriptor bd, String name, Object expected) {
    52         Object value = bd.getValue(name);
    59         Object value = bd.getValue(name);
    53         System.out.println(name + " = " + value);
    60         System.out.println("\t" + name + " = " + value);
    54         if (!Objects.equals(value, expected)) {
    61         if (!Objects.equals(value, expected)) {
    55             throw new Error(name + ": expected = " + expected + "; actual = " + value);
    62             throw new Error(name + ": expected = " + expected + "; actual = " + value);
    56         }
    63         }
    57     }
    64     }
    58 
    65 
    59     public static class X {
    66     public static class X {
    60     }
    67     }
    61 
    68 
    62     @SwingContainer()
    69     @SwingContainer()
    63     public static class T {
    70     public static class H {
       
    71     }
       
    72 
       
    73     @SwingContainer(delegate = "")
       
    74     public static class G {
    64     }
    75     }
    65 
    76 
    66     @SwingContainer(delegate = "method")
    77     @SwingContainer(delegate = "method")
       
    78     public static class F {
       
    79     }
       
    80 
       
    81     @SwingContainer(false)
       
    82     public static class E {
       
    83     }
       
    84 
       
    85     @SwingContainer(value = false, delegate = "")
    67     public static class D {
    86     public static class D {
    68     }
    87     }
    69 
    88 
    70     @SwingContainer(false)
    89     @SwingContainer(value = true, delegate = "")
    71     public static class F {
    90     public static class C {
    72     }
    91     }
    73 
    92 
    74     @SwingContainer(value = false, delegate = "method")
    93     @SwingContainer(value = false, delegate = "method")
       
    94     public static class B {
       
    95     }
       
    96 
       
    97     @SwingContainer(value = true, delegate = "method")
    75     public static class A {
    98     public static class A {
    76     }
    99     }
    77 }
   100 }