### Question:
GlusterWatchService implements WatchService { public WatchKey registerPath(GlusterPath path, WatchEvent.Kind... kinds) { if (!running) { throw new ClosedWatchServiceException(); } for (GlusterWatchKey k : paths) { if (k.getPath().equals(path)) { k.setKinds(kinds); return k; } } GlusterWatchKey key = new GlusterWatchKey(path, kinds); paths.add(key); return key; }  WatchKey registerPath(GlusterPath path, WatchEvent.Kind... kinds); @Override void close(); @Override WatchKey poll(); @Override WatchKey poll(long timeout, TimeUnit unit); @Override WatchKey take(); static final int MILLIS_PER_SECOND; static final int MILLIS_PER_MINUTE; static final int MILLIS_PER_HOUR; static final int MILLIS_PER_DAY; static long PERIOD; }### Answer:
@Test(expected = ClosedWatchServiceException.class) public void testRegisterPath_whenNotRunning() { watchService.setRunning(false); GlusterPath mockPath = mock(GlusterPath.class); watchService.registerPath(mockPath); }
@Test public void testRegisterPath() { watchService.setRunning(true); GlusterPath mockPath = mock(GlusterPath.class); WatchEvent.Kind mockKind = mock(WatchEvent.Kind.class); watchService.registerPath(mockPath, mockKind); GlusterWatchKey event = watchService.getPaths().iterator().next(); assertEquals(mockPath, event.getPath()); assertEquals(mockKind, event.getKinds()[0]); }
@Test public void testRegisterPath_whenPathExists() { watchService.setRunning(true); GlusterPath mockPath = mock(GlusterPath.class); GlusterWatchKey keyFix = new GlusterWatchKey(mockPath, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_MODIFY}); watchService.getPaths().add(keyFix); watchService.registerPath(mockPath, StandardWatchEventKinds.ENTRY_CREATE); GlusterWatchKey event = watchService.getPaths().iterator().next(); assertEquals(mockPath, event.getPath()); assertEquals(StandardWatchEventKinds.ENTRY_CREATE, event.getKinds()[0]); }