17d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller/* 27d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * Copyright (C) 2016 The Android Open Source Project 37d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * 47d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * Licensed under the Apache License, Version 2.0 (the "License"); 57d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * you may not use this file except in compliance with the License. 67d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * You may obtain a copy of the License at 77d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * 87d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * http://www.apache.org/licenses/LICENSE-2.0 97d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * 107d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * Unless required by applicable law or agreed to in writing, software 117d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * distributed under the License is distributed on an "AS IS" BASIS, 127d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * See the License for the specific language governing permissions and 147d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * limitations under the License. 157d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller */ 167d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 177d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerpackage libcore.java.lang.reflect.annotations; 187d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 197d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport junit.framework.TestCase; 207d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 217d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport java.lang.annotation.Annotation; 227d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport java.lang.reflect.Constructor; 237d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport java.lang.reflect.Executable; 247d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport java.lang.reflect.Method; 257d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport java.lang.reflect.Parameter; 267d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.AnnotationB; 277d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.AnnotationC; 287d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.AnnotationD; 297d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.Container; 307d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.Repeated; 317d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 327d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport static libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.EXPECT_EMPTY; 337d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport static libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.assertGetDeclaredAnnotation; 347d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport static libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.assertIsAnnotationPresent; 357d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerimport static libcore.java.lang.reflect.annotations.AnnotatedElementTestSupport.checkAnnotatedElementPresentMethods; 367d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 377d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller/** 387d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * Tests for the {@link java.lang.reflect.AnnotatedElement} methods from the {@link Parameter} 397d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * objects obtained from both {@link Constructor} and {@link Method}. 407d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller */ 417d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fullerpublic class AnnotatedElementParameterTest extends TestCase { 427d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 437d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller private static class MethodClass { 447d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void methodWithoutAnnotatedParameters(String parameter1, String parameter2) {} 457d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 467d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void methodWithAnnotatedParameters(@AnnotationB @AnnotationD String parameter1, 477d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller @AnnotationC @AnnotationD String parameter2) {} 487d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 497d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 507d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testMethodParameterAnnotations() throws Exception { 517d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<?> c = MethodClass.class; 527d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller { 537d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter[] parameters = c.getDeclaredMethod( 547d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller "methodWithoutAnnotatedParameters", String.class, String.class).getParameters(); 557d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter0 = parameters[0]; 567d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter0); 577d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 587d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter1 = parameters[1]; 597d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter1); 607d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 617d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller { 627d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter[] parameters = c.getDeclaredMethod( 637d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller "methodWithAnnotatedParameters", String.class, String.class).getParameters(); 647d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 657d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter0 = parameters[0]; 667d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter0, AnnotationB.class, AnnotationD.class); 677d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 687d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter1 = parameters[1]; 697d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter1, AnnotationC.class, AnnotationD.class); 707d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 717d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 727d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 737d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller private static class ConstructorClass { 747d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // No annotations. 757d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public ConstructorClass(Integer parameter1, Integer parameter2) {} 767d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 777d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // Annotations. 787d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public ConstructorClass(@AnnotationB @AnnotationD String parameter1, 797d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller @AnnotationC @AnnotationD String parameter2) {} 807d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 817d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 827d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testConstructorParameterAnnotations() throws Exception { 837d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<?> c = ConstructorClass.class; 847d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller { 857d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter[] parameters = 867d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller c.getDeclaredConstructor(Integer.class, Integer.class).getParameters(); 877d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter0 = parameters[0]; 887d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter0); 897d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 907d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter1 = parameters[1]; 917d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter1); 927d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 937d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller { 947d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter[] parameters = 957d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller c.getDeclaredConstructor(String.class, String.class).getParameters(); 967d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 977d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter0 = parameters[0]; 987d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter0, AnnotationB.class, AnnotationD.class); 997d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1007d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter1 = parameters[1]; 1017d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkAnnotatedElementPresentMethods(parameter1, AnnotationC.class, AnnotationD.class); 1027d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1037d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1047d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1057d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller private static class AnnotatedMethodClass { 1067d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller void noAnnotation(String p0) {} 1077d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1087d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller void multipleAnnotationOddity( 1097d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller @Repeated(1) @Container({@Repeated(2), @Repeated(3)}) String p0) {} 1107d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1117d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller void multipleAnnotationExplicitSingle(@Container({@Repeated(1)}) String p0) {} 1127d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1137d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller void multipleAnnotation(@Repeated(1) @Repeated(2) String p0) {} 1147d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1157d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller void singleAnnotation(@Repeated(1) String p0) {} 1167d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 117df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath static void staticSingleAnnotation(@Repeated(1) String p0) {} 118df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath 1197d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Method getMethodWithoutAnnotations() throws Exception { 1207d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedMethodClass.class.getDeclaredMethod("noAnnotation", String.class); 1217d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1227d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1237d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Method getMethodMultipleAnnotationOddity() throws Exception { 1247d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedMethodClass.class.getDeclaredMethod( 1257d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller "multipleAnnotationOddity", String.class); 1267d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1277d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1287d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Method getMethodMultipleAnnotationExplicitSingle() throws Exception { 1297d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedMethodClass.class.getDeclaredMethod( 1307d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller "multipleAnnotationExplicitSingle", String.class); 1317d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1327d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1337d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Method getMethodMultipleAnnotation() throws Exception { 1347d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedMethodClass.class.getDeclaredMethod("multipleAnnotation", String.class); 1357d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1367d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1377d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Method getMethodSingleAnnotation() throws Exception { 1387d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedMethodClass.class.getDeclaredMethod("singleAnnotation", String.class); 1397d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 140df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath 141df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath static Method getMethodStaticSingleAnnotation() throws Exception { 142df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath return AnnotatedMethodClass.class.getDeclaredMethod("staticSingleAnnotation", 143df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath String.class); 144df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath } 145df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath } 146df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath 147df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath private static abstract class AnnotatedMethodAbstractClass { 148df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath abstract void abstractSingleAnnotation(@Repeated(1) String p0); 149df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath 150df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath static Method getMethodAbstractSingleAnnotation() throws Exception { 151df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath return AnnotatedMethodAbstractClass.class.getDeclaredMethod( 152df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath "abstractSingleAnnotation", String.class); 153df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath } 1547d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1557d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1567d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // Tests for isAnnotationPresent and getDeclaredAnnotation. 1577d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testMethodDeclaredAnnotation() throws Exception { 1587d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> repeated = Repeated.class; 1597d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1607d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodWithoutAnnotations(), 1617d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, null); 1627d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1637d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationOddity(), 1647d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 1657d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1667d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationExplicitSingle(), 1677d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, null); 1687d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1697d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotation(), 1707d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, null); 1717d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1727d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodSingleAnnotation(), 1737d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 174df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath checkParameter0DeclaredAnnotation( 175df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath AnnotatedMethodClass.getMethodStaticSingleAnnotation(), 176df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath repeated, "@Repeated(1)"); 177df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath checkParameter0DeclaredAnnotation( 178df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath AnnotatedMethodAbstractClass.getMethodAbstractSingleAnnotation(), 179df976ebc5c3e5f8332f56d92da0298b11fd47c13Narayan Kamath repeated, "@Repeated(1)"); 1807d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1817d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> container = Container.class; 1827d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1837d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodWithoutAnnotations(), 1847d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, null); 1857d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1867d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationOddity(), 1877d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(2), @Repeated(3)})"); 1887d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1897d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationExplicitSingle(), 1907d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1)})"); 1917d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1927d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotation(), 1937d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1), @Repeated(2)})"); 1947d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 1957d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodSingleAnnotation(), 1967d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, null); 1977d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 1987d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 1997d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller private static class AnnotatedConstructorClass { 2007d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public AnnotatedConstructorClass(Boolean p0) {} 2017d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2027d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public AnnotatedConstructorClass( 2037d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller @Repeated(1) @Container({@Repeated(2), @Repeated(3)}) Long p0) {} 2047d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2057d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public AnnotatedConstructorClass(@Container({@Repeated(1)}) Double p0) {} 2067d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2077d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public AnnotatedConstructorClass(@Repeated(1) @Repeated(2) Integer p0) {} 2087d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2097d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public AnnotatedConstructorClass(@Repeated(1) String p0) {} 2107d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2117d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Constructor<?> getConstructorWithoutAnnotations() throws Exception { 2127d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedConstructorClass.class.getDeclaredConstructor(Boolean.class); 2137d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2147d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2157d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Constructor<?> getConstructorMultipleAnnotationOddity() throws Exception { 2167d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedConstructorClass.class.getDeclaredConstructor(Long.class); 2177d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2187d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2197d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Constructor<?> getConstructorMultipleAnnotationExplicitSingle() 2207d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller throws Exception { 2217d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedConstructorClass.class.getDeclaredConstructor(Double.class); 2227d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2237d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2247d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Constructor<?> getConstructorSingleAnnotation() throws Exception { 2257d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedConstructorClass.class.getDeclaredConstructor(String.class); 2267d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2277d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2287d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller static Constructor<?> getConstructorMultipleAnnotation() throws Exception { 2297d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller return AnnotatedConstructorClass.class.getDeclaredConstructor(Integer.class); 2307d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2317d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2327d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2337d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // Tests for isAnnotationPresent and getDeclaredAnnotation. 2347d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testConstructorDeclaredAnnotation() throws Exception { 2357d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> repeated = Repeated.class; 2367d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2377d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorWithoutAnnotations(), 2387d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, null); 2397d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2407d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationOddity(), 2417d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 2427d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2437d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationExplicitSingle(), 2447d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, null); 2457d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2467d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotation(), 2477d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, null); 2487d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2497d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorSingleAnnotation(), 2507d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 2517d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2527d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> container = Container.class; 2537d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2547d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorWithoutAnnotations(), 2557d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, null); 2567d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2577d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationOddity(), 2587d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(2), @Repeated(3)})"); 2597d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2607d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationExplicitSingle(), 2617d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1)})"); 2627d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2637d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotation(), 2647d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1), @Repeated(2)})"); 2657d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0DeclaredAnnotation( 2667d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorSingleAnnotation(), 2677d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, null); 2687d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2697d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2707d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller private static void checkParameter0DeclaredAnnotation( 2717d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Executable executable, Class<? extends Annotation> annotationType, 2727d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller String expectedAnnotationString) throws Exception { 2737d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter = executable.getParameters()[0]; 2747d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2757d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // isAnnotationPresent 2767d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller assertIsAnnotationPresent(parameter, annotationType, expectedAnnotationString != null); 2777d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2787d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // getDeclaredAnnotation 2797d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller assertGetDeclaredAnnotation(parameter, annotationType, expectedAnnotationString); 2807d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 2817d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 2827d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testMethodGetDeclaredAnnotationsByType() throws Exception { 2837d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> repeated = Repeated.class; 2847d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 2857d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodWithoutAnnotations(), 2867d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, EXPECT_EMPTY); 2877d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 2887d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationOddity(), 2897d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)", "@Repeated(3)"); 2907d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 2917d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationExplicitSingle(), 2927d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 2937d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 2947d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotation(), 2957d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)"); 2967d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 2977d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodSingleAnnotation(), 2987d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 2997d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 3007d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> container = Container.class; 3017d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3027d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodWithoutAnnotations(), 3037d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 3047d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3057d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationOddity(), 3067d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(2), @Repeated(3)})"); 3077d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3087d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationExplicitSingle(), 3097d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1)})"); 3107d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3117d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotation(), 3127d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1), @Repeated(2)})"); 3137d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3147d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodSingleAnnotation(), 3157d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 3167d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 3177d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 3187d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testConstructorGetDeclaredAnnotationsByType() throws Exception { 3197d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> repeated = Repeated.class; 3207d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3217d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorWithoutAnnotations(), 3227d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, EXPECT_EMPTY); 3237d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3247d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationOddity(), 3257d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)", "@Repeated(3)"); 3267d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3277d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationExplicitSingle(), 3287d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 3297d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3307d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotation(), 3317d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)"); 3327d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3337d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorSingleAnnotation(), 3347d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 3357d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 3367d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> container = Container.class; 3377d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3387d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorWithoutAnnotations(), 3397d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 3407d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3417d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationOddity(), 3427d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(2), @Repeated(3)})"); 3437d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3447d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationExplicitSingle(), 3457d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1)})"); 3467d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3477d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotation(), 3487d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1), @Repeated(2)})"); 3497d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetDeclaredAnnotationsByType( 3507d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorSingleAnnotation(), 3517d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 3527d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 3537d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 3547d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller private static void checkParameter0GetDeclaredAnnotationsByType( 3557d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Executable executable, Class<? extends Annotation> annotationType, 3567d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller String... expectedAnnotationStrings) throws Exception { 3577d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter = executable.getParameters()[0]; 3587d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetDeclaredAnnotationsByType( 3597d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter, annotationType, expectedAnnotationStrings); 3607d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 3617d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 3627d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testMethodGetAnnotationsByType() throws Exception { 3637d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> repeated = Repeated.class; 3647d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3657d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodWithoutAnnotations(), 3667d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, EXPECT_EMPTY); 3677d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3687d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationOddity(), 3697d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)", "@Repeated(3)"); 3707d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3717d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationExplicitSingle(), 3727d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 3737d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3747d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotation(), 3757d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)"); 3767d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3777d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodSingleAnnotation(), 3787d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 3797d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 3807d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> container = Container.class; 3817d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3827d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodWithoutAnnotations(), 3837d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 3847d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3857d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationOddity(), 3867d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(2), @Repeated(3)})"); 3877d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3887d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotationExplicitSingle(), 3897d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1)})"); 3907d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3917d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodMultipleAnnotation(), 3927d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1), @Repeated(2)})"); 3937d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 3947d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedMethodClass.getMethodSingleAnnotation(), 3957d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 3967d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 3977d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 3987d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testConstructorGetAnnotationsByType() throws Exception { 3997d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> repeated = Repeated.class; 4007d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4017d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorWithoutAnnotations(), 4027d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, EXPECT_EMPTY); 4037d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4047d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationOddity(), 4057d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)", "@Repeated(3)"); 4067d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4077d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationExplicitSingle(), 4087d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 4097d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4107d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotation(), 4117d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)", "@Repeated(2)"); 4127d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4137d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorSingleAnnotation(), 4147d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller repeated, "@Repeated(1)"); 4157d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 4167d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Class<? extends Annotation> container = Container.class; 4177d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4187d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorWithoutAnnotations(), 4197d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 4207d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4217d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationOddity(), 4227d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(2), @Repeated(3)})"); 4237d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4247d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotationExplicitSingle(), 4257d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1)})"); 4267d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4277d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorMultipleAnnotation(), 4287d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, "@Container({@Repeated(1), @Repeated(2)})"); 4297d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller checkParameter0GetAnnotationsByType( 4307d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedConstructorClass.getConstructorSingleAnnotation(), 4317d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller container, EXPECT_EMPTY); 4327d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 4337d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 4347d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller private static void checkParameter0GetAnnotationsByType( 4357d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Executable executable, Class<? extends Annotation> annotationType, 4367d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller String... expectedAnnotationStrings) throws Exception { 4377d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter = executable.getParameters()[0]; 4387d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetAnnotationsByType( 4397d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter, annotationType, expectedAnnotationStrings); 4407d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 4417d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 4427d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller /** 4437d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * As an inner class the constructor will actually have two parameters: the first, referencing 4447d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller * the enclosing object, is inserted by the compiler. 4457d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller */ 4467d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller class InnerClass { 4477d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller InnerClass(@Repeated(1) String p1) {} 4487d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 4497d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 4507d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller /** Special case testing for a compiler-generated constructor parameter. */ 4517d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller public void testImplicitConstructorParameters_singleAnnotation() throws Exception { 4527d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Constructor<InnerClass> constructor = 4537d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller InnerClass.class.getDeclaredConstructor( 4547d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementParameterTest.class, String.class); 4557d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter[] parameters = constructor.getParameters(); 4567d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 4577d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // The compiler-generated constructor should have no annotations. 4587d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter0 = parameters[0]; 4597d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetAnnotationsByType( 4607d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter0, Repeated.class, new String[0]); 4617d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetDeclaredAnnotationsByType( 4627d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter0, Repeated.class, new String[0]); 4637d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetDeclaredAnnotation( 4647d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter0, Repeated.class, null); 4657d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertIsAnnotationPresent(parameter0, Repeated.class, false); 4667d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller 4677d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller // The annotation should remain on the correct parameter. 4687d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller Parameter parameter1 = parameters[1]; 4697d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetAnnotationsByType( 4707d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter1, Repeated.class, new String[] {"@Repeated(1)"}); 4717d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetDeclaredAnnotationsByType( 4727d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter1, Repeated.class, new String[] {"@Repeated(1)"}); 4737d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertGetDeclaredAnnotation( 4747d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter1, Repeated.class, "@Repeated(1)"); 4757d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller AnnotatedElementTestSupport.assertIsAnnotationPresent( 4767d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller parameter1, Repeated.class, true); 4777d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller } 4787d38257be058ccc23f31a39ecf6d73294acb3c1eNeil Fuller} 479