@Test
public void testCopyMethodAnnotationsToField() {

  final CtClass ctclass = ClassPool.getDefault().makeClass("test");
  final CtMethod createdMethod = addNewMethod(ctclass, "doNothing");
  annotateMethod(createdMethod, "value", 123);
  final CtField createdField = addNewField(ctclass, "toField");
  JavassistUtils.copyMethodAnnotationsToField(createdMethod, createdField);
  IntegerMemberValue i = null;
  for (final Annotation annot : ((AnnotationsAttribute) createdField.getFieldInfo().getAttribute(
      AnnotationsAttribute.visibleTag)).getAnnotations()) {
    i = (IntegerMemberValue) annot.getMemberValue("value");
    if (i != null) {
      break;
    }
  }
  if ((i == null) || (i.getValue() != 123)) {
    fail("Expected annotation value 123 but found " + i);
  }
}