### Question:
GlusterWatchService implements WatchService { @Override public void close() throws IOException { if (running) { running = false; for (GlusterWatchKey k : paths) { k.cancel(); } } }  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 public void testClose_whenNotRunning() throws IOException { watchService.setRunning(false); GlusterWatchKey mockKey = mock(GlusterWatchKey.class); watchService.getPaths().add(mockKey); watchService.close(); Mockito.verify(mockKey, Mockito.never()).cancel(); }
@Test public void testClose() throws IOException { watchService.setRunning(true); GlusterWatchKey mockKey = mock(GlusterWatchKey.class); watchService.getPaths().add(mockKey); watchService.close(); Mockito.verify(mockKey).cancel(); assertFalse(watchService.isRunning()); }