IdPropertyResolverUtils { public static boolean isAnnotated(AnnotatedElement element) { final List<Class<? extends Annotation>> annotations = getIdAnnotations(); for (Class<? extends Annotation> annotation : annotations) { if (AnnotationUtils.findAnnotation(element, annotation) != null) { return true; } } return false; } private  IdPropertyResolverUtils(); static String getPropertyNameFromAnnotatedMethod(Class<?> entityType, Class<?> idType,
                                                            Method idAnnotatedMethod); static boolean isAnnotated(AnnotatedElement element);  }
@Test public void testReadingAnnotationFromField() throws Exception { assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedIdFieldFromJPA.class.getDeclaredField("customIdProperty")), is(true)); assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedEmbeddedIdFieldFromJPA.class.getDeclaredField("customIdProperty")), is(true)); assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedIdField.class.getDeclaredField("id")), is(true)); assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedEmbeddedIdField.class.getDeclaredField("id")), is(true)); }
@Test public void testReadingAnnotationFromMethod() throws Exception { assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedIdGetterFromJPA.class.getDeclaredMethod("getMyCustomId")), is(true)); assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedEmbeddedIdGetterFromJPA.class.getDeclaredMethod("getMyCustomId")), is(true)); assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedIdGetter.class.getDeclaredMethod("getId")), is(true)); assertThat(IdPropertyResolverUtils.isAnnotated(EntityWithAnnotatedEmbeddedIdGetter.class.getDeclaredMethod("getId")), is(true)); }