### Question:
DateRangeFolderFilenameFilter implements FilenameFilter { @Override public boolean accept( File dir, String name ) { if ( dir.isDirectory() ) { try { Date folderDate = format.parse( name ); int startCompare = 0; int endCompare = 0; if ( startingDate != null ) { startCompare = folderDate.compareTo( startingDate ); } if ( endingDate != null ) { endCompare = folderDate.compareTo( endingDate ); } return startCompare >= 0 && endCompare <= 0; } catch ( ParseException e ) { return false; } } else { return false; } } DateRangeFolderFilenameFilter( SimpleDateFormat format );  DateRangeFolderFilenameFilter( SimpleDateFormat format, Date startingDate );  DateRangeFolderFilenameFilter( SimpleDateFormat format, String startingDate );  DateRangeFolderFilenameFilter( SimpleDateFormat format, Date startingDate, Date endingDate );  DateRangeFolderFilenameFilter( SimpleDateFormat format, String startingDate, String endingDate ); Date getEndingDate(); void setEndingDate( Date endingDate ); void setEndingDate( String endingDate ); Date getStartingDate(); void setStartingDate( Date startingDate ); void setStartingDate( String startingDate ); @Override boolean accept( File dir, String name );  }### Answer:
@Test public void testAccept_notFolder() throws Exception { filter = new DateRangeFolderFilenameFilter( format, start ); File f = spy( new File( "" ) ); when( f.isDirectory() ).thenReturn( false ); assertFalse( filter.accept( f, end ) ); }
@Test public void testAccept_startDateSet() throws Exception { filter = new DateRangeFolderFilenameFilter( format, start ); File f = spy( new File( "" ) ); when( f.isDirectory() ).thenReturn( true ); assertTrue( filter.accept( f, end ) ); assertTrue( "Start date is not inclusive", filter.accept( f, start ) ); assertFalse( "Before start date was accepted", filter.accept( f, "20000101" ) ); }
@Test public void testAccept_startDateSet_endDateSet() throws Exception { filter = new DateRangeFolderFilenameFilter( format, start, end ); File f = spy( new File( "" ) ); when( f.isDirectory() ).thenReturn( true ); assertTrue( "End date is not inclusive", filter.accept( f, end ) ); assertTrue( "Start date is not inclusive", filter.accept( f, start ) ); assertTrue( "Between start and end date is not accepted", filter.accept( f, between ) ); assertFalse( "Before start date was accepted", filter.accept( f, "20000101" ) ); assertFalse( "After end date was accepted", filter.accept( f, "21000101" ) ); }
@Test public void testAccept_startDateNull_endDateSet() throws Exception { filter = new DateRangeFolderFilenameFilter( format, null, end ); File f = spy( new File( "" ) ); when( f.isDirectory() ).thenReturn( true ); assertTrue( "End date is not inclusive", filter.accept( f, end ) ); assertTrue( "Before end date was not accepted", filter.accept( f, "20000101" ) ); assertFalse( "After end date was accepted", filter.accept( f, "21000101" ) ); }
@Test public void testAccept_invalidDateStringFolder() throws Exception { filter = new DateRangeFolderFilenameFilter( format, start, end ); File f = spy( new File( "" ) ); when( f.isDirectory() ).thenReturn( true ); assertFalse( "Invalid date was accepted", filter.accept( f, "not a date" ) ); }