1 /*
 2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 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
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
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
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 8022324
27  * @summary Test Class.getAnnotatedInterfaces() returns 0-length array as
28  *          specified.
29  */
30 
31 import java.lang.reflect.AnnotatedType;
32 import java.util.Arrays;
33 
34 public class GetAnnotatedInterfaces {
35     private static final Class<?>[] testData = {
36         GetAnnotatedInterfaces.class,
37         (new Clz() {}).getClass(),
38         (new Object() {}).getClass(),
39         Object[].class,
40         Object[][].class,
41         Object[][][].class,
42         Object.class,
43         void.class,
44         int.class,
45     };
46 
47     private static int failed = 0;
48     private static int tests = 0;
49 
50     public static void main(String[] args) throws Exception {
51         testReturnsZeroLengthArray();
52 
53         if (failed != 0)
54             throw new RuntimeException("Test failed, check log for details");
55         if (tests != 9)
56             throw new RuntimeException("Not all cases ran, failing");
57     }
58 
59     private static void testReturnsZeroLengthArray() {
60         for (Class<?> toTest : testData) {
61             tests++;
62 
63             AnnotatedType[] res = toTest.getAnnotatedInterfaces();
64 
65             if (res == null) {
66                 failed++;
67                 System.out.println(toTest + ".class.getAnnotatedInterface() returns" +
68                         "'null' should zero length array");
69             } else if (res.length != 0) {
70                 failed++;
71                 System.out.println(toTest + ".class.getAnnotatedInterfaces() returns: "
72                         + Arrays.asList(res) + ", should be a zero length array of AnnotatedType");
73             }
74         }
75     }
76 
77     interface If {}
78 
79     abstract static class Clz {}
80 }