jdk/test/java/beans/Introspector/4058433/TestSwingContainer.java
author serb
Wed, 03 Jun 2015 23:17:52 +0300
changeset 31166 6448eff013a8
parent 25566 ba387c302edd
permissions -rw-r--r--
8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec Reviewed-by: alexsch, malenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     1
/*
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     4
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     8
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    13
 * accompanied this code).
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    14
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    18
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    21
 * questions.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    22
 */
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    23
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    24
import java.beans.BeanDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    25
import java.beans.BeanInfo;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    26
import java.beans.Introspector;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    27
import java.util.Objects;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    28
import javax.swing.SwingContainer;
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    29
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    30
/**
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    31
 * @test
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    32
 * @bug 4058433
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    33
 * @summary Tests the SwingContainer annotation
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    34
 * @author Sergey Malenkov
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    35
 */
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    36
public class TestSwingContainer {
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    37
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    39
        test(X.class, null, null);
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    40
        test(H.class, true, "");
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    41
        test(G.class, true, "");
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    42
        test(F.class, true, "method");
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    43
        test(E.class, false, "");
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    44
        test(D.class, false, "");
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    45
        test(C.class, true, "");
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    46
        test(B.class, false, "method");
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    47
        test(A.class, true, "method");
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    48
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    49
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    50
    private static void test(Class<?> type, Object iC, Object cD) throws Exception {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    51
        System.out.println(type);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    52
        BeanInfo info = Introspector.getBeanInfo(type);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    53
        BeanDescriptor bd = info.getBeanDescriptor();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    54
        test(bd, "isContainer", iC);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    55
        test(bd, "containerDelegate", cD);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    56
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    57
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    58
    private static void test(BeanDescriptor bd, String name, Object expected) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    59
        Object value = bd.getValue(name);
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    60
        System.out.println("\t" + name + " = " + value);
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    61
        if (!Objects.equals(value, expected)) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    62
            throw new Error(name + ": expected = " + expected + "; actual = " + value);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    63
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    64
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    65
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    66
    public static class X {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    67
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    68
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    69
    @SwingContainer()
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    70
    public static class H {
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    71
    }
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    72
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    73
    @SwingContainer(delegate = "")
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    74
    public static class G {
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    75
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    76
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    77
    @SwingContainer(delegate = "method")
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    78
    public static class F {
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    79
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    80
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    81
    @SwingContainer(false)
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    82
    public static class E {
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    83
    }
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    84
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    85
    @SwingContainer(value = false, delegate = "")
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    86
    public static class D {
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    87
    }
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    88
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    89
    @SwingContainer(value = true, delegate = "")
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    90
    public static class C {
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    91
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    92
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    93
    @SwingContainer(value = false, delegate = "method")
31166
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    94
    public static class B {
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    95
    }
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    96
6448eff013a8 8076312: The behavior of the javax.swing.SwingContainer.delegate contradicts spec
serb
parents: 25566
diff changeset
    97
    @SwingContainer(value = true, delegate = "method")
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    98
    public static class A {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    99
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   100
}