### Question:
ZooKeeperInstance implements Instance { @Override public String getInstanceID() { if (instanceId == null) { instanceId = ClientContext.getInstanceID(zooCache, instanceName); } ClientContext.verifyInstanceId(zooCache, instanceId, instanceName); return instanceId; } ZooKeeperInstance(String instanceName, String zooKeepers);   ZooKeeperInstance(ClientConfiguration config, ZooCacheFactory zcf);  ZooKeeperInstance(ClientConfiguration config); @Override String getInstanceID(); @Override List<String> getMasterLocations(); @Override String getRootTabletLocation(); @Override String getInstanceName(); @Override String getZooKeepers(); @Override int getZooKeepersSessionTimeOut(); @Override Connector getConnector(String principal, AuthenticationToken token); @Override String toString();  }### Answer:
@Test public void testGetInstanceID_FromCache() { expect(zc.get(Constants.ZROOT + Constants.ZINSTANCES + "/instance")) .andReturn(IID_STRING.getBytes(UTF_8)); expect(zc.get(Constants.ZROOT + "/" + IID_STRING)).andReturn("yup".getBytes()); replay(zc); assertEquals(IID_STRING, zki.getInstanceID()); }
@Test public void testGetInstanceID_Direct() { ClientConfiguration config = createMock(ClientConfiguration.class); mockIdConstruction(config); replay(config); zki = new ZooKeeperInstance(config, zcf); expect(zc.get(Constants.ZROOT + "/" + IID_STRING)).andReturn("yup".getBytes()); replay(zc); assertEquals(IID_STRING, zki.getInstanceID()); }
@Test(expected = RuntimeException.class) public void testGetInstanceID_IDMissingForName() { expect(zc.get(Constants.ZROOT + Constants.ZINSTANCES + "/instance")) .andReturn(IID_STRING.getBytes(UTF_8)); expect(zc.get(Constants.ZROOT + "/" + IID_STRING)).andReturn(null); replay(zc); zki.getInstanceID(); }
@Test(expected = RuntimeException.class) public void testGetInstanceID_IDMissingForID() { ClientConfiguration config = createMock(ClientConfiguration.class); mockIdConstruction(config); replay(config); zki = new ZooKeeperInstance(config, zcf); expect(zc.get(Constants.ZROOT + "/" + IID_STRING)).andReturn(null); replay(zc); zki.getInstanceID(); }