List of usage examples for javax.tools JavaFileManager getJavaFileForOutput
JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling)
throws IOException;
From source file:org.cloudfoundry.tools.compiler.CloudFoundryJavaCompilerTest.java
@Test public void shouldCompileVirtualFile() throws Exception { JavaFileObject sourceFile = mock(JavaFileObject.class); given(sourceFile.getKind()).willReturn(Kind.SOURCE); given(sourceFile.getName()).willReturn("Example.java"); given(sourceFile.getCharContent(anyBoolean())).willReturn(getExampleJavaContent()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); JavaFileObject classFile = mock(JavaFileObject.class); given(classFile.openOutputStream()).willReturn(outputStream); JavaFileManager fileManager = mock(JavaFileManager.class); given(fileManager.getJavaFileForOutput(Matchers.any(Location.class), anyString(), eq(Kind.CLASS), eq(sourceFile))).willReturn(classFile); Iterable<? extends JavaFileObject> compilationUnits = Collections.singleton(sourceFile); CompilationTask task = this.javaCompiler.getTask(null, fileManager, null, standardCompilerOptions(), null, compilationUnits);/* ww w .ja v a2 s . c om*/ assertThat(task.call(), is(Boolean.TRUE)); assertThat(outputStream.toByteArray().length, is(greaterThan(0))); }