@Test
public void test() throws Exception {

    // Mock file system
    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;
        }
    });
    // Write ZIP to output stream
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ZipStreamingOutput zip = new ZipStreamingOutput(source, fs);
    zip.write(out);
    // Verify output stream
    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);
    // Verify path deleted
    deleteLatch.await(1, TimeUnit.SECONDS);
    Mockito.verify(fs).delete(source, true);
}