jdk/test/java/lang/annotation/typeAnnotations/GetAnnotatedInterfaces.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 20481 2735b307d256
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20481
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     1
/*
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     4
 *
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     8
 *
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    13
 * accompanied this code).
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    14
 *
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    18
 *
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    21
 * questions.
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    22
 */
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    23
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    24
/*
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    25
 * @test
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    26
 * @bug 8022324
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    27
 * @summary Test Class.getAnnotatedInterfaces() returns 0-length array as
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    28
 *          specified.
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    29
 */
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    30
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    31
import java.lang.reflect.AnnotatedType;
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    32
import java.util.Arrays;
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    33
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    34
public class GetAnnotatedInterfaces {
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    35
    private static final Class<?>[] testData = {
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    36
        GetAnnotatedInterfaces.class,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    37
        (new Clz() {}).getClass(),
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    38
        (new Object() {}).getClass(),
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    39
        Object[].class,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    40
        Object[][].class,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    41
        Object[][][].class,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    42
        Object.class,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    43
        void.class,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    44
        int.class,
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    45
    };
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    46
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    47
    private static int failed = 0;
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    48
    private static int tests = 0;
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    49
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    50
    public static void main(String[] args) throws Exception {
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    51
        testReturnsZeroLengthArray();
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    52
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    53
        if (failed != 0)
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    54
            throw new RuntimeException("Test failed, check log for details");
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    55
        if (tests != 9)
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    56
            throw new RuntimeException("Not all cases ran, failing");
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    57
    }
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    58
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    59
    private static void testReturnsZeroLengthArray() {
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    60
        for (Class<?> toTest : testData) {
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    61
            tests++;
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    62
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    63
            AnnotatedType[] res = toTest.getAnnotatedInterfaces();
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    64
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    65
            if (res == null) {
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    66
                failed++;
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    67
                System.out.println(toTest + ".class.getAnnotatedInterface() returns" +
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    68
                        "'null' should zero length array");
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    69
            } else if (res.length != 0) {
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    70
                failed++;
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    71
                System.out.println(toTest + ".class.getAnnotatedInterfaces() returns: "
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    72
                        + Arrays.asList(res) + ", should be a zero length array of AnnotatedType");
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    73
            }
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    74
        }
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    75
    }
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    76
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    77
    interface If {}
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    78
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 20481
diff changeset
    79
    abstract static class Clz {}
20481
2735b307d256 8007072: Update Core Reflection for Type Annotations to match latest spec
jfranck
parents:
diff changeset
    80
}