@Test public void usesFilerToOpenStream() throws IOException { Filer filer = mock(Filer.class); JavaFileObject fileObject = mock(JavaFileObject.class); when(filer.createSourceFile(anyString())).thenReturn(fileObject); OutputStream expectedOS = mock(OutputStream.class); when(fileObject.openOutputStream()).thenReturn(expectedOS); SourceCodeWriter sourceCodeWriter = new SourceCodeWriter(filer); JPackage jPackage = new JCodeModel()._package("some.package"); OutputStream resultingOS = sourceCodeWriter.openBinary(jPackage, "SomeClass.java"); assertSame(expectedOS, resultingOS); }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); JavaFileObject sourceFile = filer.createSourceFile(qualifiedClassName); return sourceFile.openOutputStream(); }
SourceCodeWriter extends CodeWriter { @Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); JavaFileObject sourceFile = filer.createSourceFile(qualifiedClassName); return sourceFile.openOutputStream(); } }
SourceCodeWriter extends CodeWriter { @Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); JavaFileObject sourceFile = filer.createSourceFile(qualifiedClassName); return sourceFile.openOutputStream(); } SourceCodeWriter(Filer filer); }
SourceCodeWriter extends CodeWriter { @Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); JavaFileObject sourceFile = filer.createSourceFile(qualifiedClassName); return sourceFile.openOutputStream(); } SourceCodeWriter(Filer filer); @Override OutputStream openBinary(JPackage pkg, String fileName); @Override void close(); }
SourceCodeWriter extends CodeWriter { @Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); JavaFileObject sourceFile = filer.createSourceFile(qualifiedClassName); return sourceFile.openOutputStream(); } SourceCodeWriter(Filer filer); @Override OutputStream openBinary(JPackage pkg, String fileName); @Override void close();  }