FileFilter { public boolean isAllowed(VirtualFile f) { if (myTypeManager.isFileIgnored(f.getName())) return false; if (f.isDirectory()) return true; return !myTypeManager.getFileTypeByFile(f).isBinary(); } FileFilter(FileIndex fi, FileTypeManager tm); boolean isAllowedAndUnderContentRoot(VirtualFile f); boolean isUnderContentRoot(VirtualFile f); boolean isAllowed(VirtualFile f); static final long MAX_FILE_SIZE; }
@Test public void testFilteringFileOfUndesiredType() { expect(tm.isFileIgnored((String)anyObject())).andStubReturn(false); expect(tm.getFileTypeByFile(f1)).andStubReturn(nonBinary); expect(tm.getFileTypeByFile(f2)).andStubReturn(binary); replay(tm); FileFilter f = new FileFilter(fi, tm); assertTrue(f.isAllowed(f1)); assertFalse(f.isAllowed(f2)); }
@Test public void testFilteringIgnoredFiles() { f1 = new TestVirtualFile("allowed", null, -1); f2 = new TestVirtualFile("filtered", null, -1); expect(tm.isFileIgnored("allowed")).andReturn(false); expect(tm.isFileIgnored("filtered")).andReturn(true); expect(tm.getFileTypeByFile((VirtualFile)anyObject())).andStubReturn(nonBinary); replay(tm); FileFilter f = new FileFilter(fi, tm); assertTrue(f.isAllowed(f1)); assertFalse(f.isAllowed(f2)); }
@Test public void testFilteringIgnoredDirectories() { f1 = new TestVirtualFile("allowed"); f2 = new TestVirtualFile("filtered"); expect(tm.isFileIgnored("allowed")).andReturn(false); expect(tm.isFileIgnored("filtered")).andReturn(true); replay(tm); FileFilter f = new FileFilter(fi, tm); assertTrue(f.isAllowed(f1)); assertFalse(f.isAllowed(f2)); }
@Test public void testDoesNotCheckFileTypeForDirectories() { f1 = new TestVirtualFile("dir"); expect(tm.isFileIgnored("dir")).andReturn(false); replay(tm); FileFilter f = new FileFilter(fi, tm); assertTrue(f.isAllowed(f1)); verify(tm); }