Path: blob/master/test/jdk/java/lang/annotation/repeatingAnnotations/OrderUnitTest.java
41153 views
/*1* Copyright (c) 2013, 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*/2223/*24* @test25* @bug 800491226* @summary Unit test for order of annotations returned by get[Declared]AnnotationsByType.27*28* @run main OrderUnitTest29*/3031import java.lang.annotation.*;32import java.lang.reflect.*;3334public class OrderUnitTest {3536public static void main(String[] args) {37testOrder(Case1.class);38testOrder(Case2.class);39}4041private static void testOrder(AnnotatedElement e) {42Annotation[] decl = e.getDeclaredAnnotations();43Foo[] declByType = e.getDeclaredAnnotationsByType(Foo.class);4445if (decl[0] instanceof Foo != declByType[0].isDirect() ||46decl[1] instanceof Foo != declByType[1].isDirect()) {47throw new RuntimeException("Order of directly / indirectly present " +48"annotations from getDeclaredAnnotationsByType does not " +49"match order from getDeclaredAnnotations.");50}51}52}5354@Retention(RetentionPolicy.RUNTIME)55@interface FooContainer {56Foo[] value();57}5859@Retention(RetentionPolicy.RUNTIME)60@Repeatable(FooContainer.class)61@interface Foo {62boolean isDirect();63}646566@Foo(isDirect = true) @FooContainer({@Foo(isDirect = false)})67class Case1 {68}697071@FooContainer({@Foo(isDirect = false)}) @Foo(isDirect = true)72class Case2 {73}747576