I have the following code:
import java.lang.annotation.*;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {}
and this failing test:
@MyAnnotation
private Object obj = new Object();
@Test
public void test() throws Exception {
assertEquals(1, obj.getClass().getAnnotations().length);
}
resulting in:
java.lang.AssertionError:
Expected :1
Actual :0