### Question:
DirectoryIterator { public static Iterator<File> get(String directoryIteratorType, File dir, String extensionFilter, boolean recursive) throws IOException { try { if (directoryIteratorType.indexOf('.') == -1) { directoryIteratorType = DirectoryIterator.class.getPackage() .getName() + "." + directoryIteratorType; } DirectoryIterator it = (DirectoryIterator) Class.forName( directoryIteratorType).newInstance(); it.setDirectory(dir); it.setRecursive(recursive); if (extensionFilter != null) it.setExtensionFilter(extensionFilter); return it.iterator(); } catch (Throwable t) { throw new IOException(t); } } DirectoryIterator(); DirectoryIterator setDirectory(File dir); DirectoryIterator setExtensionFilter(String ext); DirectoryIterator setRecursive(boolean isRecursive); abstract Iterator<File> iterator(); static Iterator<File> get(String directoryIteratorType, File dir,
            String extensionFilter, boolean recursive); static final String LARGE; static final String ZIP; }### Answer:
@Test public void testDefault() throws Exception { File dir = Resources.getFile("directoryIterator/default"); Iterator<File> it = DirectoryIterator.get( DefaultDirectoryIterator.class.getSimpleName(), dir, null, false); ArrayList<File> list = newArrayList(it); assertEquals(3, list.size()); assertEquals("test", asText(list.get(0)).substring(0, 4)); it = DirectoryIterator.get( DefaultDirectoryIterator.class.getSimpleName(), dir, "tm", false); list = Lists.newArrayList(it); assertEquals(1, list.size()); }
@Test public void testZip() throws Exception { File dir = Resources.getFile("directoryIterator/zipFileIterator.zip"); Iterator<File> it = DirectoryIterator.get( ZipDirectoryIterator.class.getSimpleName(), dir, null, false); ArrayList<File> list = newArrayList(it); assertEquals(3, list.size()); assertEquals("test", asText(list.get(0)).substring(0, 4)); }
@Test public void testLarge() throws Exception { if (IS_OS_LINUX || IS_OS_MAC) { File dir = Resources.getFile("directoryIterator/default"); Iterator<File> it = DirectoryIterator.get( LargeDirectoryIterator.class.getSimpleName(), dir, null, false); ArrayList<File> list = newArrayList(it); assertEquals(3, list.size()); assertEquals("test", asText(list.get(0)).substring(0, 4)); it = DirectoryIterator.get( LargeDirectoryIterator.class.getSimpleName(), dir, "tm", false); list = newArrayList(it); assertEquals(1, list.size()); } }