OcelotProcessor extends AbstractProcessor { void writeJsFile(TypeElement element, ElementVisitor visitor, String packagePath, String fn) { try (Writer w = fws.getFileObjectWriterInClassOutput(packagePath, fn)) { 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_writeJsFile() throws IOException { System.out.println("writeJsFile"); TypeElement element = mock(TypeElement.class); ElementVisitor visitor = mock(ElementVisitor.class); Writer writer = mock(Writer.class); when(fws.getFileObjectWriterInClassOutput(eq("packagePath"), eq("fn"))).thenReturn(writer).thenThrow(IOException.class); instance.writeJsFile(element, visitor, "packagePath", "fn"); instance.writeJsFile(element, visitor, "packagePath", "fn"); verify(element).accept(eq(visitor), eq(writer)); }