CopyListing extends Configured { protected abstract void doBuildListing(Path pathToListFile, DistCpContext distCpContext) throws IOException; protected  CopyListing(Configuration configuration, Credentials credentials); final void buildListing(Path pathToListFile,
      DistCpContext distCpContext); static CopyListing getCopyListing(Configuration configuration,
      Credentials credentials, DistCpContext context);  }
@Test public void testFailOnCloseError() throws IOException { File inFile = File.createTempFile("TestCopyListingIn", null); inFile.deleteOnExit(); File outFile = File.createTempFile("TestCopyListingOut", null); outFile.deleteOnExit(); List<Path> srcs = new ArrayList<Path>(); srcs.add(new Path(inFile.toURI())); Exception expectedEx = new IOException("boom"); SequenceFile.Writer writer = mock(SequenceFile.Writer.class); doThrow(expectedEx).when(writer).close(); SimpleCopyListing listing = new SimpleCopyListing(getConf(), CREDENTIALS); final DistCpOptions options = new DistCpOptions.Builder(srcs, new Path(outFile.toURI())).build(); Exception actualEx = null; try { listing.doBuildListing(writer, new DistCpContext(options)); } catch (Exception e) { actualEx = e; } Assert.assertNotNull("close writer didn't fail", actualEx); Assert.assertEquals(expectedEx, actualEx); }