DirectoryExporter implements Exporter { @Override public void export(Handler handler) throws IOException { if (!mDir.isDirectory()) throw new IOException("not a directory"); for (String fileName : mDir.list()) { exportFile(fileName, new FileInputStream(new File(mDir, fileName)), handler); } } DirectoryExporter(File dir); @Override void export(Handler handler);  }
@Test(expected = NullPointerException.class) public void reportsErrorOnUsingNullFile() throws Exception { new DirectoryExporter(null).export(this); }
@Test(expected = NullPointerException.class) public void reportsErrorOnUsingNullHandler() throws Exception { File dir = mock(File.class); when(dir.isDirectory()).thenReturn(true); new DirectoryExporter(dir).export(null); }
@Test(expected = IOException.class) public void supportsOnlyDirectories() throws Exception { File file = mock(File.class); when(file.isDirectory()).thenReturn(false); new DirectoryExporter(file).export(null); }
@Test public void exportsFileFromDirectory() throws Exception { new DirectoryExporter(mDir).export(this); }