### Question:
AnnotationUtils { public static String addXmlAdaptorAnnotation(final String source, final String returnType, final AdapterWrapper wrapper) { final CompilationUnit unit = JavaSourceUtils.getCompilationUnit(source); final AST ast = unit.getAST(); final ExistingMethodsVisitor methodsVisitor = JavaSourceUtils.getMethodCollection(unit); final List<MethodDeclaration> getterMethods = methodsVisitor.getGetterMethods(); boolean needsImport = false; for (MethodDeclaration getterMethod : getterMethods) { final Type returnType2 = getterMethod.getReturnType2(); if (returnType2.isSimpleType()) { final SimpleType simpleType = (SimpleType) returnType2; if (!simpleType.getName().getFullyQualifiedName().equals(returnType)) { continue; } } else { log.warn("TODO: Cannot map type: {}", returnType2); continue; } @SuppressWarnings("rawtypes") final List parameters = getterMethod.parameters(); if (parameters == null || parameters.size() == 0) { final SingleMemberAnnotation generatedAnnotation = ast.newSingleMemberAnnotation(); generatedAnnotation.setTypeName(ast.newName(XmlJavaTypeAdapter.class.getSimpleName())); final TypeLiteral typeLiteral = ast.newTypeLiteral(); typeLiteral.setType(ast.newSimpleType(ast.newName(wrapper.className))); generatedAnnotation.setValue(typeLiteral); JavaSourceUtils.addAnnotation(getterMethod, generatedAnnotation); JavaSourceUtils.addImport(unit, XmlJavaTypeAdapter.class.getName()); needsImport = true; } } if (needsImport) { JavaSourceUtils.addImport(unit, wrapper.importPath); } return JavaSourceUtils.rewrite(unit, ast); } private  AnnotationUtils(); @SuppressWarnings("unchecked") static String addXmlRootAnnotation(final String source, final String name); static String addXmlAdaptorAnnotation(final String source, final String returnType, final AdapterWrapper wrapper); static String addXmlElementAnnotation(final String source); static String addXmlAccessNoneAnnotation(final String source); static T getClassAnnotation(final Class<?> clazz, final Class<T> annotationClass); static Collection<Field> getAnnotatedFields(final Class<?> clazz, final Class<? extends Annotation> annotationClass); @SuppressWarnings({"unchecked"}) static Class<T> findClass(final String name); static Collection<Field> getClassFields(Class<?> clazz); static Collection<Method> getMethods(Class<?> clazz); static String addKnownAdapters(final String source); static final Set<String> KNOWN_XML_TYPES; }### Answer:
@Test public void testXmlAdaptorAnnotation() throws Exception { final String javaFile = GlobalUtils.readStreamAsText(getClass().getResourceAsStream("/AnnotationTestClass.txt")); assertNotNull("Expected to find /AnnotationTestClass.txt file", javaFile); final String annotationName = "HippoHtmlAdapter"; final String importPath = "org.onehippo.cms7.essentials.components.rest.adapters"; final String hippoHtml = "HippoHtml"; String annotated = AnnotationUtils.addXmlAdaptorAnnotation(javaFile, hippoHtml, new AnnotationUtils.AdapterWrapper(importPath, annotationName)); int nrOfItems = StringUtils.countMatches(annotated, annotationName); assertEquals(1, nrOfItems); annotated = AnnotationUtils.addXmlAdaptorAnnotation(javaFile, hippoHtml, new AnnotationUtils.AdapterWrapper(importPath, annotationName)); nrOfItems = StringUtils.countMatches(annotated, annotationName); assertEquals(1, nrOfItems); }