FileWriterServices { public Writer getFileObjectWriterInClassOutput(String pkg, String name) throws IOException { FileObject resource = filer.createResource(StandardLocation.CLASS_OUTPUT, pkg, name); return resource.openWriter(); } FileWriterServices(Messager messager, Filer filer); void copyResourceToClassesOutput(String path, String filename); void copyResourceToDir(String path, String filename, String dir); Writer getFileObjectWriterInClassOutput(String pkg, String name); Writer getFileObjectWriter(String path, String filename);  }
@Test public void testGetFileObjectWriterInClassOutput() throws Exception { System.out.println("getFileObjectWriterInClassOutput"); String pkg = "PKG"; String name= "NAME"; FileObject fileObject = mock(FileObject.class); Messager messager = mock(Messager.class); Filer filer = mock(Filer.class); Writer writer = mock(Writer.class); BodyWriter bodyWriter = mock(BodyWriter.class); FileWriterServices instance = spy(new FileWriterServices(messager, filer)); instance.bodyWriter = bodyWriter; when(filer.createResource(eq(StandardLocation.CLASS_OUTPUT), eq(pkg), eq(name))).thenReturn(fileObject); when(fileObject.openWriter()).thenReturn(writer); Writer result = instance.getFileObjectWriterInClassOutput(pkg, name); assertThat(result).isEqualTo(writer); }