ConsulAdvertiser { public void deregister() { final AgentClient agent = consul.agentClient(); try { if (!agent.isRegistered(serviceId)) { LOGGER.info("No service registered with ID \"{}\"", serviceId); return; } } catch (ConsulException e) { LOGGER.error("Failed to determine if service ID \"{}\" is registered", serviceId, e); return; } LOGGER.info("Deregistering service ID \"{}\"", serviceId); try { consul.agentClient().deregister(serviceId); } catch (ConsulException e) { LOGGER.error("Failed to deregister service from Consul", e); } } ConsulAdvertiser(
      final Environment environment,
      final ConsulFactory configuration,
      final Consul consul,
      final String serviceId); String getServiceId(); boolean register(
      final String applicationScheme, final int applicationPort, final int adminPort); boolean register(
      final String applicationScheme,
      final int applicationPort,
      final int adminPort,
      Collection<String> ipAddresses); void deregister();  }
@Test public void testDeregister() { final String serviceId = advertiser.getServiceId(); when(agent.isRegistered(serviceId)).thenReturn(true); advertiser.deregister(); verify(agent).deregister(serviceId); }
@Test public void testDeregisterException() { when(agent.isRegistered(anyString())).thenReturn(true); doThrow(new ConsulException("error")).when(agent).deregister(anyString()); advertiser.deregister(); verify(agent).deregister(anyString()); }