AbstractDataServiceVisitor implements ElementVisitor<String, Writer> ,ProcessorConstants { String getJsClassname(TypeElement typeElement) { DataService dsAnno = typeElement.getAnnotation(DataService.class); String name = dsAnno.name(); if (name.isEmpty()) { name = typeElement.getSimpleName().toString(); } return name; } 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 testGetJsClassname() { TypeElement typeElement = mock(TypeElement.class); DataService ds = mock(DataService.class); Name name = mock(Name.class); when(typeElement.getAnnotation(eq(DataService.class))).thenReturn(ds); when(typeElement.getSimpleName()).thenReturn(name); when(name.toString()).thenReturn("DefaultClassName"); when(ds.name()).thenReturn("").thenReturn("SpecifiedClassName"); String result = instance.getJsClassname(typeElement); assertThat(result).isEqualTo("DefaultClassName"); result = instance.getJsClassname(typeElement); assertThat(result).isEqualTo("SpecifiedClassName"); }