FileExtensionFilter { public List<DirEntry> filter(final List<DirEntry> entries) { final List<DirEntry> dir = Collections.checkedList(new ArrayList<DirEntry>(), DirEntry.class); for (final DirEntry entry : entries) { final String fileExtension = FilenameUtils.getExtension(entry.getName()).toLowerCase(); if (filterExtension.equals(fileExtension)) { dir.add(entry); } } return dir; } FileExtensionFilter(final String filterExtension); List<DirEntry> filter(final List<DirEntry> entries);  }
@Test public void testFilter() throws Exception { final List<DirEntry> list = TestUtils.getFileEntriesDirectoryList(); List<DirEntry> filteredList; filteredList = new FileExtensionFilter("jpg").filter(list); assertEquals(1, filteredList.size()); filteredList = new FileExtensionFilter("gif").filter(list); assertEquals(1, filteredList.size()); try { new FileExtensionFilter(null).filter(list); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { } try { new FileExtensionFilter("").filter(list); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { } }