DirEntryKindFilter { public List<DirEntry> filter(final List<DirEntry> entries) { final List<DirEntry> list = Collections.checkedList(new ArrayList<DirEntry>(), DirEntry.class); for (final DirEntry entry : entries) { if (kind == entry.getKind()) { list.add(entry); } } return list; } DirEntryKindFilter(final DirEntry.Kind kind); List<DirEntry> filter(final List<DirEntry> entries);  }
@Test public void testFilter() throws Exception { final List<DirEntry> list = getDirectoryList(); List<DirEntry> filteredList; try { new DirEntryKindFilter(DirEntry.Kind.NONE).filter(list); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { } try { new DirEntryKindFilter(DirEntry.Kind.ANY).filter(list); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { } try { new DirEntryKindFilter(DirEntry.Kind.UNKNOWN).filter(list); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { } filteredList = new DirEntryKindFilter(DirEntry.Kind.DIR).filter(list); assertEquals(4, filteredList.size()); filteredList = new DirEntryKindFilter(DirEntry.Kind.FILE).filter(list); assertEquals(9, filteredList.size()); try { new DirEntryKindFilter(null).filter(list); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { } }