@Test(expectedExceptions = CannotUploadExternalResourceException.class)
public void testWriteWhenFileIsAnInvalidJarFile() throws IOException {

    //GIVEN
    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);
    //WHEN
    underTest.write(inputStream, fileName, EXCEPTION_MESSAGE);
    //THEN error is thrown
}