### Question:
ZipStreamingOutput implements StreamingOutput { @Override public void write(@Nonnull final OutputStream output) throws IOException { try { writeZip(output); } catch (Exception e) { throw new SparkShellPluginIoException("Unrecognized exception encountered when attempting to write results to zip stream", e); } finally { HadoopUtil.deleteLater(folder, fileSystem); } } ZipStreamingOutput(@Nonnull final Path folder, @Nonnull final FileSystem fs); @Override void write(@Nonnull final OutputStream output);  }### Answer:
@Test public void test() throws Exception { final FileSystem fs = Mockito.mock(FileSystem.class); final Path source = new Path("/tmp/source"); final LocatedFileStatus file1 = createFile("_SUCCESS", source); final LocatedFileStatus file2 = createFile("part-0", source); Mockito.when(fs.listFiles(source, false)).thenReturn(new ForwardingRemoteIterator<>(Iterators.forArray(file1, file2))); final FSDataInputStream fileStream = new FSDataInputStream(new SeekableNullInputStream()); Mockito.when(fs.open(file1.getPath())).thenReturn(fileStream); Mockito.when(fs.open(file2.getPath())).thenReturn(fileStream); final CountDownLatch deleteLatch = new CountDownLatch(1); Mockito.when(fs.delete(source, true)).then(new Answer<Boolean>() { @Override public Boolean answer(final InvocationOnMock invocation) { deleteLatch.countDown(); return true; } }); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ZipStreamingOutput zip = new ZipStreamingOutput(source, fs); zip.write(out); final ZipInputStream in = new ZipInputStream(out.toInputStream()); ZipEntry entry = in.getNextEntry(); Assert.assertNotNull("Missing _SUCCESS entry", entry); Assert.assertEquals("_SUCCESS", entry.getName()); entry = in.getNextEntry(); Assert.assertNotNull("Missing part-0 entry", entry); Assert.assertEquals("part-0", entry.getName()); entry = in.getNextEntry(); Assert.assertNull("Unexpected entry", entry); deleteLatch.await(1, TimeUnit.SECONDS); Mockito.verify(fs).delete(source, true); }