### Question:
TranslatorCompiler { File copyTranslatorScript() { final File tempFile = createTemporaryFile(); try (final InputStream scriptInput = getScriptStream(); OutputStreamWriter scriptOutput = new OutputStreamWriter(new FileOutputStream(tempFile), Charset.forName("utf-8"))) { IOUtils.copy(scriptInput, scriptOutput, Charset.forName("utf-8")); } catch (final IOException e) { throw new RuntimeException("Failed to copy XML translator to local file.", e); } return tempFile; }  void compile();  }### Answer:
@Test public void testCopyTranslatorScript() throws Exception { final File tempFile = mock(File.class); final InputStream scriptStream = mock(InputStream.class); final TranslatorCompiler injected = new TranslatorCompiler() { @Override File createTemporaryFile() { return tempFile; } @Override InputStream getScriptStream() { return scriptStream; } }; final FileOutputStream fileOut = mock(FileOutputStream.class); whenNew(FileOutputStream.class).withArguments(tempFile).thenReturn(fileOut); final OutputStreamWriter writer = mock(OutputStreamWriter.class); whenNew(OutputStreamWriter.class).withArguments(fileOut, Charset.forName("utf-8")).thenReturn(writer); mockStatic(IOUtils.class); assertThat(injected.copyTranslatorScript()).isEqualTo(tempFile); verifyStatic(IOUtils.class); IOUtils.copy(scriptStream, writer, Charset.forName("utf-8")); }