GovDocs { public static final GovDocsCorpora newInstance(final File root) { Preconditions.checkNotNull(root, "root==null"); Preconditions.checkArgument(root.isDirectory(), "root should be an existing directory."); boolean isZip = isZip(root); Pattern foldPattern = (isZip) ? GovDocsZipped.ZIP_PATTERN : AbstractGovDocs.DIR_PATTERN; FilenameFilter filter = new RegexFileFilter(foldPattern); final File[] folders = root.listFiles(filter); int count = 0; long size = 0L; final Set<String> exts = new HashSet<String>(); for (File folder : folders) { FolderDetails foldDets; try { foldDets = (isZip) ? getZipFolderDetails(folder) : getFolderDetails(folder); } catch (ZipException excep) { System.err.println("Folder: " + folder.getAbsolutePath() + " does not appear to be a valid zip file."); excep.printStackTrace(); continue; } catch (IOException excep) { System.err.println("IOException reading Folder: " + folder.getAbsolutePath()); excep.printStackTrace(); continue; } count+=foldDets.count; size+=foldDets.size; exts.addAll(foldDets.exts); } CorpusDetails details = Corpora.details(count, size).name(GovDocsCorpora.NAME).type(GovDocsCorpora.TYPE).extensions(exts).build(); return (isZip) ? GovDocsZipped.newInstance(root, details, folders.length) : GovDocsDirectories.newInstance(root, details, folders.length); } private  GovDocs(); static final GovDocsCorpora newInstance(final File root);  }
@Test(expected = NullPointerException.class) public final void testGetNullDir() { GovDocs.newInstance(null); }
@Test(expected = IllegalArgumentException.class) public final void testGetNotDir() { GovDocs.newInstance(new File("c@n't exist?*")); }
@Test public final void testGetCount() throws URISyntaxException { File realRoot = new File("S:/govdocs/"); if (!realRoot.isDirectory()) return; GovDocsCorpora govDocs = GovDocs.newInstance(realRoot); System.out.println(govDocs.getCount()); assertTrue("missing test data? count: " + govDocs.getCount(), govDocs.getCount() > 0); }
@Test public final void testGetCountZip() throws URISyntaxException { GovDocsCorpora govDocs = GovDocs.newInstance(AllFidgetTests.getGovDocsZip()); assertTrue("missing test data? count: " + govDocs.getCount(), govDocs.getCount() == 11); }
@Test public final void testGetCountDir() throws URISyntaxException { GovDocsCorpora govDocs = GovDocs.newInstance(AllFidgetTests.getGovDocsDir()); assertTrue("missing test data? count: " + govDocs.getCount(), govDocs.getCount() == 11); }
@Test public final void testGetSize() throws URISyntaxException { GovDocsCorpora govDocs = GovDocs.newInstance(AllFidgetTests.getGovDocsDir()); assertTrue("No data found size: " + govDocs.getSize(), govDocs.getSize() > 0); }