### Question:
FileStatusTreeTraverser extends TreeTraverser<FileStatus> { @Override public Iterable<FileStatus> children(FileStatus root) { if (root.isFile()) { return ImmutableList.of(); } try { FileStatus[] listStatus = fileSystem.listStatus(root.getPath()); if (listStatus == null || listStatus.length == 0) { return ImmutableList.of(); } return ImmutableList.copyOf(listStatus); } catch (IOException e) { throw new CircusTrainException("Unable to list children for path: " + root.getPath()); } } FileStatusTreeTraverser(FileSystem fileSystem); @Override Iterable<FileStatus> children(FileStatus root);  }### Answer:
@Test public void typical() throws IOException { when(status.isFile()).thenReturn(false); FileStatus fileStatus = new FileStatus(); when(fileSystem.listStatus(any(Path.class))).thenReturn(new FileStatus[] { fileStatus }); Iterable<FileStatus> children = traverser.children(status); verify(fileSystem).listStatus(any(Path.class)); assertThat(Iterables.size(children), is(1)); assertTrue(children.iterator().next() == fileStatus); }
@Test public void noChildren() throws IOException { when(status.isFile()).thenReturn(false); when(fileSystem.listStatus(any(Path.class))).thenReturn(new FileStatus[] {}); Iterable<FileStatus> children = traverser.children(status); verify(fileSystem).listStatus(any(Path.class)); assertThat(Iterables.size(children), is(0)); }
@Test public void nullListStatus() throws IOException { when(status.isFile()).thenReturn(false); when(fileSystem.listStatus(any(Path.class))).thenReturn(null); Iterable<FileStatus> children = traverser.children(status); verify(fileSystem).listStatus(any(Path.class)); assertThat(Iterables.size(children), is(0)); }
@Test public void rootIsFile() throws IOException { when(status.isFile()).thenReturn(true); Iterable<FileStatus> children = traverser.children(status); verify(fileSystem, never()).listStatus(any(Path.class)); assertThat(Iterables.size(children), is(0)); }
@Test(expected = CircusTrainException.class) public void fileSystemException() throws IOException { when(status.isFile()).thenReturn(false); doThrow(IOException.class).when(fileSystem).listStatus(any(Path.class)); traverser.children(status); }