### Question:
NotificationEventPathFilter implements PathFilter { @Override public boolean accept(Path path) { return !(path == null || (toIgnoreHiddenFiles && path.getName().startsWith("."))) && watchDirectory.matcher(path.toString()).matches(); } NotificationEventPathFilter(Pattern watchDirectory, boolean toIgnoreHiddenFiles); @Override boolean accept(Path path);  }### Answer:
@Test public void acceptShouldProperlyReturnFalseWithNullPath() throws Exception { assertFalse(new NotificationEventPathFilter(Pattern.compile(""), true).accept(null)); }
@Test public void acceptPathShouldProperlyIgnorePathsWhereTheLastComponentStartsWithADot() throws Exception { PathFilter filter = new NotificationEventPathFilter(Pattern.compile(".*"), true); assertFalse(filter.accept(new Path("/.some_hidden_file"))); assertFalse(filter.accept(new Path("/some/long/path/.some_hidden_file/"))); }
@Test public void acceptPathShouldProperlyAcceptPathsWhereTheNonLastComponentStartsWithADot() throws Exception { PathFilter filter = new NotificationEventPathFilter(Pattern.compile(".*"), true); assertTrue(filter.accept(new Path("/some/long/path/.some_hidden_file/should/work"))); assertTrue(filter.accept(new Path("/.some_hidden_file/should/still/accept"))); }
@Test public void acceptPathShouldProperlyMatchAllSubdirectoriesThatMatchWatchDirectoryAndFileFilter() throws Exception { PathFilter filter = new NotificationEventPathFilter(Pattern.compile("/root(/.*)?"), true); assertTrue(filter.accept(new Path("/root/sometest.txt"))); }
@Test public void acceptPathShouldProperlyMatchWhenWatchDirectoryMatchesPath() throws Exception { PathFilter filter = new NotificationEventPathFilter(Pattern.compile("/root(/.*)?"), false); assertTrue(filter.accept(new Path("/root"))); }