@Test(expectedExceptions = CannotUploadExternalResourceException.class) public void testWriteWhenFileIsAnInvalidJarFile() throws IOException { String fileName = "myjar.jar"; 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); doThrow(new CannotUploadExternalResourceException(EXCEPTION_MESSAGE)).when(jarValidator).validateInputStream(byteArrayInputStream); underTest.write(inputStream, fileName, EXCEPTION_MESSAGE); }
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);  }