@Test public void testWriteWhenFileIsAClassFile() throws IOException { String fileName = "MyClass.class"; given(byteArrayInputStream.read(Mockito.any(byte[].class))).willReturn(1, -1); given(inputStreamUtil.transformToByteArray(inputStream)).willReturn(FILE_AS_BYTES); given(byteArrayInputStreamFactory.createByteArrayInputStream(FILE_AS_BYTES)).willReturn(byteArrayInputStream); given(classFilePathAssembler.createFilePath(byteArrayInputStream, fileName, EXCEPTION_MESSAGE)).willReturn(fileName); given(fileFactory.createFile(fileName)).willReturn(file); given(file.getParent()).willReturn(DIRECTORIES); given(fileOutputStreamFactory.createFileOutputStream(file)).willReturn(fileOutputStream); given(file.exists()).willReturn(true); underTest.write(inputStream, fileName, EXCEPTION_MESSAGE); verify(fileFactory).createFile(Mockito.anyString()); verify(inputStreamUtil).transformToByteArray(inputStream); verify(byteArrayInputStreamFactory, times(2)).createByteArrayInputStream(FILE_AS_BYTES); verify(classFilePathAssembler).createFilePath(byteArrayInputStream, fileName, EXCEPTION_MESSAGE); verify(fileFactory).createFile(fileName); verify(file).getParent(); verify(fileOutputStreamFactory).createFileOutputStream(file); verify(file).exists(); }
public void write(final InputStream inputStream, final String fileName, final String exceptionMessage) { boolean isClass = fileName.endsWith(".class"); boolean isJar = fileName.endsWith(".jar"); if (isClass) { writeClass(fileName, inputStream, exceptionMessage); } else if (isJar) { writeJar(fileName, inputStream, exceptionMessage); } else { writeOther(fileName, inputStream, exceptionMessage); } }
FileWriter { public void write(final InputStream inputStream, final String fileName, final String exceptionMessage) { boolean isClass = fileName.endsWith(".class"); boolean isJar = fileName.endsWith(".jar"); if (isClass) { writeClass(fileName, inputStream, exceptionMessage); } else if (isJar) { writeJar(fileName, inputStream, exceptionMessage); } else { writeOther(fileName, inputStream, exceptionMessage); } } }
FileWriter { public void write(final InputStream inputStream, final String fileName, final String exceptionMessage) { boolean isClass = fileName.endsWith(".class"); boolean isJar = fileName.endsWith(".jar"); if (isClass) { writeClass(fileName, inputStream, exceptionMessage); } else if (isJar) { writeJar(fileName, inputStream, exceptionMessage); } else { writeOther(fileName, inputStream, exceptionMessage); } }  }
FileWriter { public void write(final InputStream inputStream, final String fileName, final String exceptionMessage) { boolean isClass = fileName.endsWith(".class"); boolean isJar = fileName.endsWith(".jar"); if (isClass) { writeClass(fileName, inputStream, exceptionMessage); } else if (isJar) { writeJar(fileName, inputStream, exceptionMessage); } else { writeOther(fileName, inputStream, exceptionMessage); } }  void write(final InputStream inputStream, final String fileName, final String exceptionMessage); }
FileWriter { public void write(final InputStream inputStream, final String fileName, final String exceptionMessage) { boolean isClass = fileName.endsWith(".class"); boolean isJar = fileName.endsWith(".jar"); if (isClass) { writeClass(fileName, inputStream, exceptionMessage); } else if (isJar) { writeJar(fileName, inputStream, exceptionMessage); } else { writeOther(fileName, inputStream, exceptionMessage); } }  void write(final InputStream inputStream, final String fileName, final String exceptionMessage);  }