OcelotProcessor extends AbstractProcessor { Set<TypeElement> getTypeElementContainsJsRemoveAnno(RoundEnvironment roundEnv) { Set<TypeElement> elements = new HashSet<>(); for (Element element : roundEnv.getElementsAnnotatedWith(JsCacheRemove.class)) { if(ExecutableElement.class.isInstance(element)) { TypeElement te = (TypeElement) ((ExecutableElement) element).getEnclosingElement(); elements.add(te); } } for (Element element : roundEnv.getElementsAnnotatedWith(JsCacheRemoves.class)) { if(ExecutableElement.class.isInstance(element)) { TypeElement te = (TypeElement) ((ExecutableElement) element).getEnclosingElement(); elements.add(te); } } return elements; }  @Override void init(ProcessingEnvironment processingEnv); @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); void processElement(Element element);  }
@Test public void getTypeElementContainsJsRemoveAnnoTest() { System.out.println("getTypeElementContainsJsRemoveAnno"); RoundEnvironment roundEnv = mock(RoundEnvironment.class); ExecutableElement ee0 = mock(ExecutableElement.class); ExecutableElement ee1 = mock(ExecutableElement.class); ExecutableElement ee2 = mock(ExecutableElement.class); ExecutableElement ee3 = mock(ExecutableElement.class); TypeElement te1 = mock(TypeElement.class); TypeElement te2 = mock(TypeElement.class); TypeElement te3 = mock(TypeElement.class); Set elements = new HashSet<>(); elements.add(ee0); elements.add(ee1); elements.add(ee2); elements.add(ee3); when(ee0.getEnclosingElement()).thenReturn(te1); when(ee1.getEnclosingElement()).thenReturn(te1); when(ee2.getEnclosingElement()).thenReturn(te2); when(ee3.getEnclosingElement()).thenReturn(te3); when(roundEnv.getElementsAnnotatedWith(eq(JsCacheRemove.class))).thenReturn(elements); when(roundEnv.getElementsAnnotatedWith(eq(JsCacheRemoves.class))).thenReturn(elements); Set<TypeElement> result = instance.getTypeElementContainsJsRemoveAnno(roundEnv); assertThat(result).hasSize(3); }