### Question:
ZooAuthenticationKeyWatcher implements Watcher { public void updateAuthKeys() throws KeeperException, InterruptedException { if (zk.exists(baseNode, this)) { log.info("Added {} existing AuthenticationKeys to local cache from ZooKeeper", updateAuthKeys(baseNode)); } } ZooAuthenticationKeyWatcher(AuthenticationTokenSecretManager secretManager, ZooReader zk,
      String baseNode); @Override void process(WatchedEvent event); void updateAuthKeys();  }### Answer:
@Test public void testInitialUpdateNoNode() throws Exception { expect(zk.exists(baseNode, keyWatcher)).andReturn(false); replay(zk); keyWatcher.updateAuthKeys(); verify(zk); assertEquals(0, secretManager.getKeys().size()); assertNull(secretManager.getCurrentKey()); }
@Test public void testInitialUpdateWithKeys() throws Exception { List<String> children = Arrays.asList("1", "5"); AuthenticationKey key1 = new AuthenticationKey(1, 0L, 10000L, keyGen.generateKey()), key2 = new AuthenticationKey(5, key1.getExpirationDate(), 20000L, keyGen.generateKey()); expect(zk.exists(baseNode, keyWatcher)).andReturn(true); expect(zk.getChildren(baseNode, keyWatcher)).andReturn(children); expect(zk.getData(baseNode + "/" + key1.getKeyId(), keyWatcher, null)) .andReturn(serialize(key1)); expect(zk.getData(baseNode + "/" + key2.getKeyId(), keyWatcher, null)) .andReturn(serialize(key2)); replay(zk); keyWatcher.updateAuthKeys(); verify(zk); assertEquals(2, secretManager.getKeys().size()); assertEquals(key1, secretManager.getKeys().get(key1.getKeyId())); assertEquals(key2, secretManager.getKeys().get(key2.getKeyId())); }
@Test public void missingKeyAfterGetChildren() throws Exception { List<String> children = Arrays.asList("1"); AuthenticationKey key1 = new AuthenticationKey(1, 0L, 10000L, keyGen.generateKey()); expect(zk.exists(baseNode, keyWatcher)).andReturn(true); expect(zk.getChildren(baseNode, keyWatcher)).andReturn(children); expect(zk.getData(baseNode + "/" + key1.getKeyId(), keyWatcher, null)) .andThrow(new NoNodeException()); replay(zk); keyWatcher.updateAuthKeys(); verify(zk); assertEquals("Secret manager should be empty after a disconnect", 0, secretManager.getKeys().size()); assertNull("Current key should be null", secretManager.getCurrentKey()); }