@Test public void testRecursive() { File childFile = mock(File.class); File childDir = mock(File.class); when(file.listFiles(fileFilter)).thenReturn(new File[]{childFile, childDir}); String childFileName = "childFile"; when(childFile.getName()).thenReturn(childFileName); when(childFile.isFile()).thenReturn(true); when(childFile.getParentFile()).thenReturn(file); when(childDir.isDirectory()).thenReturn(true); File grandChildFile = mock(File.class); when(grandChildFile.getParentFile()).thenReturn(childDir); String grandChildFileName = "grandChildFile"; when(grandChildFile.getName()).thenReturn(grandChildFileName); when(grandChildFile.isFile()).thenReturn(true); when(childDir.listFiles(fileFilter)).thenReturn(new File[]{grandChildFile}); Iterable<DataPacket> dataPackets = listFileCollector.getDataPackets(); Iterator<DataPacket> iterator = dataPackets.iterator(); assertTrue(iterator.hasNext()); assertEquals(childFileName, iterator.next().getAttributes().get("filename")); assertTrue(iterator.hasNext()); assertEquals(grandChildFileName, iterator.next().getAttributes().get("filename")); assertFalse(iterator.hasNext()); }
@Override public Iterable<DataPacket> getDataPackets() { long maxLastModified = System.currentTimeMillis() - 1; List<DataPacket> dataPackets = new ArrayList<>(); FileFilter fileFilter; if (filterModified) { ParcelableFileFilter modifiedCompoundFilter = new OrFileFilter(new DirectoryFileFilter(), new LastModifiedFileFilter(minModifiedTime, maxLastModified)); fileFilter = new AndFileFilter(modifiedCompoundFilter, this.fileFilter); } else { fileFilter = this.fileFilter; } listRecursive(baseDir, fileFilter, dataPackets); minModifiedTime = maxLastModified + 1; return dataPackets; }
ListFileCollector implements DataCollector { @Override public Iterable<DataPacket> getDataPackets() { long maxLastModified = System.currentTimeMillis() - 1; List<DataPacket> dataPackets = new ArrayList<>(); FileFilter fileFilter; if (filterModified) { ParcelableFileFilter modifiedCompoundFilter = new OrFileFilter(new DirectoryFileFilter(), new LastModifiedFileFilter(minModifiedTime, maxLastModified)); fileFilter = new AndFileFilter(modifiedCompoundFilter, this.fileFilter); } else { fileFilter = this.fileFilter; } listRecursive(baseDir, fileFilter, dataPackets); minModifiedTime = maxLastModified + 1; return dataPackets; } }
ListFileCollector implements DataCollector { @Override public Iterable<DataPacket> getDataPackets() { long maxLastModified = System.currentTimeMillis() - 1; List<DataPacket> dataPackets = new ArrayList<>(); FileFilter fileFilter; if (filterModified) { ParcelableFileFilter modifiedCompoundFilter = new OrFileFilter(new DirectoryFileFilter(), new LastModifiedFileFilter(minModifiedTime, maxLastModified)); fileFilter = new AndFileFilter(modifiedCompoundFilter, this.fileFilter); } else { fileFilter = this.fileFilter; } listRecursive(baseDir, fileFilter, dataPackets); minModifiedTime = maxLastModified + 1; return dataPackets; } ListFileCollector(File baseDir, ParcelableFileFilter fileFilter);  ListFileCollector(File baseDir, ParcelableFileFilter fileFilter, long minModifiedTime); protected  ListFileCollector(File baseDir, ParcelableFileFilter fileFilter, boolean filterModified, long minModifiedTime); }
ListFileCollector implements DataCollector { @Override public Iterable<DataPacket> getDataPackets() { long maxLastModified = System.currentTimeMillis() - 1; List<DataPacket> dataPackets = new ArrayList<>(); FileFilter fileFilter; if (filterModified) { ParcelableFileFilter modifiedCompoundFilter = new OrFileFilter(new DirectoryFileFilter(), new LastModifiedFileFilter(minModifiedTime, maxLastModified)); fileFilter = new AndFileFilter(modifiedCompoundFilter, this.fileFilter); } else { fileFilter = this.fileFilter; } listRecursive(baseDir, fileFilter, dataPackets); minModifiedTime = maxLastModified + 1; return dataPackets; } ListFileCollector(File baseDir, ParcelableFileFilter fileFilter);  ListFileCollector(File baseDir, ParcelableFileFilter fileFilter, long minModifiedTime); protected  ListFileCollector(File baseDir, ParcelableFileFilter fileFilter, boolean filterModified, long minModifiedTime); @Override Iterable<DataPacket> getDataPackets(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); }
ListFileCollector implements DataCollector { @Override public Iterable<DataPacket> getDataPackets() { long maxLastModified = System.currentTimeMillis() - 1; List<DataPacket> dataPackets = new ArrayList<>(); FileFilter fileFilter; if (filterModified) { ParcelableFileFilter modifiedCompoundFilter = new OrFileFilter(new DirectoryFileFilter(), new LastModifiedFileFilter(minModifiedTime, maxLastModified)); fileFilter = new AndFileFilter(modifiedCompoundFilter, this.fileFilter); } else { fileFilter = this.fileFilter; } listRecursive(baseDir, fileFilter, dataPackets); minModifiedTime = maxLastModified + 1; return dataPackets; } ListFileCollector(File baseDir, ParcelableFileFilter fileFilter);  ListFileCollector(File baseDir, ParcelableFileFilter fileFilter, long minModifiedTime); protected  ListFileCollector(File baseDir, ParcelableFileFilter fileFilter, boolean filterModified, long minModifiedTime); @Override Iterable<DataPacket> getDataPackets(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Creator<ListFileCollector> CREATOR; }