Annotation { public java.util.Map<String, AnnotationProperty> getProperties() { return properties; } Annotation(Class<?> annotationClass, boolean visible, java.util.Map<String, AnnotationProperty> properties); Class<?> getAnnotationClass(); boolean isVisible(); java.util.Map<String, AnnotationProperty> getProperties(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testEnumAnnotations() { Mirror<AnnotatedEnumObject> mirror = Mirrors.newMirrorFactory().getMirror(AnnotatedEnumObject.class); final Property<AnnotatedEnumObject, Object> property1 = mirror.getProperty("property1"); final List<Annotation> annotations = property1.getAnnotations(); Assert.assertEquals(1, annotations.size()); final Map<String, AnnotationProperty> propertyMap = annotations.iterator().next().getProperties(); Assert.assertEquals(1, propertyMap.size()); Assert.assertTrue(propertyMap.containsKey("value")); final AnnotationProperty value = propertyMap.get("value"); Assert.assertSame(TestEnum.VALUE1, value.getValue()); }
@Test public void testAnnotatedAnnotations() { Mirror<AnnotatedAnnotationObject> mirror = Mirrors.newMirrorFactory().getMirror(AnnotatedAnnotationObject.class); final List<Annotation> annotations = mirror.getProperty("property").getAnnotations(); Assert.assertEquals(1, annotations.size()); final Annotation annotation1 = annotations.iterator().next(); final AnnotationProperty annotationProperty = annotation1.getProperties().get("value"); final Annotation annotation2 = (Annotation) annotationProperty.getValue(); Assert.assertEquals("Annotation !", annotation2.getProperties().get("value").getValue()); }
@Test public void testArrayAnnotations() { Mirror<ArrayAnnotatedObject> mirror = Mirrors.newMirrorFactory().getMirror(ArrayAnnotatedObject.class); final List<Annotation> annotations = mirror.getProperty("property").getAnnotations(); Assert.assertEquals(1, annotations.size()); final Annotation annotation = annotations.iterator().next(); final AnnotationProperty annotationProperty = annotation.getProperties().get("stringValue"); String[] value = (String[]) annotationProperty.getValue(); Assert.assertArrayEquals(new String[] {"1", "2", "3"}, value); final AnnotationProperty annotationPropertyInt = annotation.getProperties().get("intValue"); int[] intValue = (int[]) annotationPropertyInt.getValue(); Assert.assertArrayEquals(new int[] {1, 2, 3}, intValue); final AnnotationProperty annotationPropertyLong = annotation.getProperties().get("longValue"); long[] longValue = (long[]) annotationPropertyLong.getValue(); Assert.assertArrayEquals(new long[] {99999, 99998, 99997}, longValue); final AnnotationProperty annotationPropertyChar = annotation.getProperties().get("charValue"); char[] charValue = (char[]) annotationPropertyChar.getValue(); Assert.assertArrayEquals(new char[] {'a', 'b', 'c'}, charValue); final AnnotationProperty annotationPropertyBoolean = annotation.getProperties().get("booleanValue"); boolean[] booleanValue = (boolean[]) annotationPropertyBoolean.getValue(); Assert.assertTrue(booleanValue[0]); Assert.assertTrue(booleanValue[1]); Assert.assertFalse(booleanValue[2]); final AnnotationProperty annotationPropertyByte = annotation.getProperties().get("byteValue"); byte[] byteValue = (byte[]) annotationPropertyByte.getValue(); Assert.assertArrayEquals(new byte[] {0xa, 0xb}, byteValue); final AnnotationProperty annotationPropertyDouble = annotation.getProperties().get("doubleValue"); double[] doubleValue = (double[]) annotationPropertyDouble.getValue(); Assert.assertTrue(123456.789 == doubleValue[0]); final AnnotationProperty annotationPropertyFloat = annotation.getProperties().get("floatValue"); float[] floatValue = (float[]) annotationPropertyFloat.getValue(); Assert.assertTrue(987.123F == floatValue[0]); final AnnotationProperty annotationPropertyShort = annotation.getProperties().get("shortValue"); short[] shortValue = (short[]) annotationPropertyShort.getValue(); Assert.assertTrue(((short) 42) == shortValue[0]); }
@Test public void testArrayOfEnumAnnotations() { Mirror<ArrayOfEnumAnnotationObject> mirror = Mirrors.newMirrorFactory().getMirror(ArrayOfEnumAnnotationObject.class); final List<Annotation> annotations = mirror.getProperty("property").getAnnotations(); Assert.assertEquals(1, annotations.size()); final Annotation annotation = annotations.iterator().next(); final AnnotationProperty annotationProperty = annotation.getProperties().get("values"); final TestEnum[] value = (TestEnum[]) annotationProperty.getValue(); Assert.assertEquals(2, value.length); Assert.assertSame(TestEnum.VALUE1, value[0]); Assert.assertSame(TestEnum.VALUE2, value[1]); }