### Question:
HdfsFileFragmenter extends HdfsDataFragmenter { @Override public List<Fragment> getFragments() throws Exception { String fileName = hcfsType.getDataUri(jobConf, context); Path path = new Path(fileName); PxfInputFormat pxfInputFormat = new PxfInputFormat(); PxfInputFormat.setInputPaths(jobConf, path); FileStatus[] fileStatusArray; try { fileStatusArray = pxfInputFormat.listStatus(jobConf); } catch (InvalidInputException e) { if (StringUtils.equalsIgnoreCase("true", context.getOption(IGNORE_MISSING_PATH_OPTION))) { LOG.debug("Ignoring InvalidInputException", e); return fragments; } throw e; } fragments = Arrays.stream(fileStatusArray) .map(fileStatus -> new Fragment(fileStatus.getPath().toUri().toString())) .collect(Collectors.toList()); LOG.debug("Total number of fragments = {}", fragments.size()); return fragments; } HdfsFileFragmenter();   HdfsFileFragmenter(ConfigurationFactory configurationFactory); @Override List<Fragment> getFragments();  }### Answer:
@Test public void testFragmenterErrorsWhenPathDoesNotExist() throws Exception { expectedException.expect(InvalidInputException.class); expectedException.expectMessage("Input path does not exist:"); String path = this.getClass().getClassLoader().getResource("csv/").getPath(); context.setDataSource(path + "non-existent"); fragmenter.initialize(context); fragmenter.getFragments(); }
@Test public void testFragmenterReturnsListOfFiles() throws Exception { String path = this.getClass().getClassLoader().getResource("csv/").getPath(); context.setDataSource(path); fragmenter.initialize(context); List<Fragment> fragmentList = fragmenter.getFragments(); assertNotNull(fragmentList); assertEquals(8, fragmentList.size()); }
@Test public void testFragmenterWilcardPath() throws Exception { String path = this.getClass().getClassLoader().getResource("csv/").getPath(); context.setDataSource(path + "*.csv"); fragmenter.initialize(context); List<Fragment> fragmentList = fragmenter.getFragments(); assertNotNull(fragmentList); assertEquals(8, fragmentList.size()); }
@Test public void testInvalidInputPath() throws Exception { expectedException.expect(InvalidInputException.class); expectedException.expectMessage("Input Pattern file:/tmp/non-existent-path-on-disk/*.csv matches 0 files"); context.setDataSource("/tmp/non-existent-path-on-disk/*.csv"); fragmenter.initialize(context); fragmenter.getFragments(); }
@Test public void testInvalidInputPathIgnored() throws Exception { context.addOption("IGNORE_MISSING_PATH", "true"); context.setDataSource("/tmp/non-existent-path-on-disk/*.csv"); fragmenter.initialize(context); List<Fragment> fragmentList = fragmenter.getFragments(); assertNotNull(fragmentList); assertEquals(0, fragmentList.size()); }