OcelotProcessor extends AbstractProcessor { void writeJsFileToJsDir(TypeElement element, ElementVisitor visitor, String packagePath, String fn, String dir) { if (null != dir) { try (Writer w = fws.getFileObjectWriter(dir + File.separatorChar + "srvs", packagePath + "." + fn)) { messager.printMessage(Diagnostic.Kind.MANDATORY_WARNING, " javascript generation class : " + element + " to : " + dir); element.accept(visitor, w); } catch (IOException ioe) { messager.printMessage(Diagnostic.Kind.MANDATORY_WARNING, " FAILED TO CREATE : " + packagePath + "." + fn); } } }  @Override void init(ProcessingEnvironment processingEnv); @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); void processElement(Element element);  }
@Test public void test_writeJsFileToJsDir() throws IOException { System.out.println("writeJsFileToJsDir"); TypeElement element = mock(TypeElement.class); ElementVisitor visitor = mock(ElementVisitor.class); Writer writer = mock(Writer.class); when(fws.getFileObjectWriter(eq("dir"+File.separatorChar+"srvs"), eq("packagePath.fn"))).thenReturn(writer).thenThrow(IOException.class); instance.writeJsFileToJsDir(element, visitor, "packagePath", "fn", "dir"); instance.writeJsFileToJsDir(element, visitor, "packagePath", "fn", "dir"); verify(element).accept(eq(visitor), eq(writer)); }