Source:
<code>public void testInitialAndAddMore() throws Exception { WatchServiceDirectoryScanner scanner = new WatchServiceDirectoryScanner(folder.getRoot().getAbsolutePath()); scanner.start(); List<File> files = scanner.listFiles(folder.getRoot()); assertEquals(3, files.size()); assertTrue(files.contains(top1)); assertTrue(files.contains(foo1)); assertTrue(files.contains(bar1)); File top2 = this.folder.newFile(); File foo2 = File.createTempFile("foo", ".txt", this.foo); File bar2 = File.createTempFile("bar", ".txt", this.bar); File baz = new File(this.foo, "baz"); baz.mkdir(); File baz1 = File.createTempFile("baz", ".txt", baz); files = scanner.listFiles(folder.getRoot()); int n = 0; List<File> accum = new ArrayList<File>(files); while (n++ < 300 && accum.size() != 4) { Thread.sleep(100); files = scanner.listFiles(folder.getRoot()); accum.addAll(files); } assertEquals(4, accum.size()); assertTrue(accum.contains(top2)); assertTrue(accum.contains(foo2)); assertTrue(accum.contains(bar2)); assertTrue(accum.contains(baz1)); List<File> filesForOverflow = new ArrayList<File>(512); for (int i = 0; i < 512; i++) { filesForOverflow.add(this.folder.newFile("" + i)); } files = scanner.listFiles(folder.getRoot()); <START> assertEquals(512, files.size()); <END> for (File fileForOverFlow : filesForOverflow) { files.contains(fileForOverFlow); } File baz2 = File.createTempFile("baz2", ".txt", baz); files = scanner.listFiles(folder.getRoot()); assertEquals(1, files.size()); assertTrue(files.contains(baz2)); scanner.stop(); }</code><technical_language>This pass OS X - investigating..</technical_language>

Target:
public void testInitialAndAddMore() throws Exception { WatchServiceDirectoryScanner scanner = new WatchServiceDirectoryScanner(folder.getRoot().getAbsolutePath()); scanner.start(); List<File> files = scanner.listFiles(folder.getRoot()); assertEquals(3, files.size()); assertTrue(files.contains(top1)); assertTrue(files.contains(foo1)); assertTrue(files.contains(bar1)); File top2 = this.folder.newFile(); File foo2 = File.createTempFile("foo", ".txt", this.foo); File bar2 = File.createTempFile("bar", ".txt", this.bar); File baz = new File(this.foo, "baz"); baz.mkdir(); File baz1 = File.createTempFile("baz", ".txt", baz); files = scanner.listFiles(folder.getRoot()); int n = 0; Set<File> accum = new HashSet<File>(files); while (n++ < 300 && accum.size() != 4) { Thread.sleep(100); files = scanner.listFiles(folder.getRoot()); accum.addAll(files); } assertEquals(4, accum.size()); assertTrue(accum.contains(top2)); assertTrue(accum.contains(foo2)); assertTrue(accum.contains(bar2)); assertTrue(accum.contains(baz1)); List<File> filesForOverflow = new ArrayList<File>(600); for (int i = 0; i < 600; i++) { filesForOverflow.add(this.folder.newFile("" + i)); } n = 0; while (n++ < 300 && accum.size() < 604) { Thread.sleep(100); files = scanner.listFiles(folder.getRoot()); accum.addAll(files); } assertEquals(604, accum.size()); for (File fileForOverFlow : filesForOverflow) { accum.contains(fileForOverFlow); } File baz2 = File.createTempFile("baz2", ".txt", baz); n = 0; while (n++ < 300 && accum.size() < 605) { Thread.sleep(100); files = scanner.listFiles(folder.getRoot()); accum.addAll(files); } assertTrue(accum.contains(baz2)); scanner.stop(); }