AbstractDataServiceVisitor implements ElementVisitor<String, Writer> ,ProcessorConstants { protected List<ExecutableElement> getOrderedMethods(TypeElement typeElement, Comparator<ExecutableElement> comparator) { List<ExecutableElement> methods = ElementFilter.methodsIn(typeElement.getEnclosedElements()); Collections.sort(methods, comparator); return methods; } AbstractDataServiceVisitor(ProcessingEnvironment environment); @Override String visitType(TypeElement typeElement, Writer writer); @Override String visit(Element e, Writer p); @Override String visit(Element e); @Override String visitPackage(PackageElement e, Writer p); @Override String visitVariable(VariableElement e, Writer p); @Override String visitExecutable(ExecutableElement e, Writer p); @Override String visitTypeParameter(TypeParameterElement e, Writer p); @Override String visitUnknown(Element e, Writer p);  }
@Test public void getOrderedMethodsTest() { System.out.println("getOrderedMethods"); TypeElement typeElement = mock(TypeElement.class); Comparator comparator = mock(Comparator.class); when(comparator.compare(any(ExecutableElement.class), any(ExecutableElement.class))).thenReturn(0); ExecutableElement m1 = mock(ExecutableElement.class); when(m1.getKind()).thenReturn(ElementKind.METHOD); ExecutableElement m2 = mock(ExecutableElement.class); when(m2.getKind()).thenReturn(ElementKind.METHOD); List<ExecutableElement> list = Arrays.asList(m1, m2); when(typeElement.getEnclosedElements()).thenReturn((List)list); List<ExecutableElement> result = instance.getOrderedMethods(typeElement, comparator); assertThat(result).hasSize(2); }