### Question:
GatewayNotifier implements Runnable { public void distributeInvalidatedCredentials(String instanceId) { final Notification notification = new Notification(null, instanceId, Type.DISTRIBUTE_INVALIDATED_CREDENTIALS); addToQueue(notification); } GatewayNotifier(@Qualifier("restTemplateWithKeystore") RestTemplate restTemplate, MessageService messageService); @PostConstruct void afterPropertiesSet(); @PreDestroy void preDestroy(); void serviceUpdated(String serviceId, String instanceId); void serviceCancelledRegistration(String serviceId); void distributeInvalidatedCredentials(String instanceId); @Override void run(); static final String GATEWAY_SERVICE_ID; }### Answer:
@Test public void testDistributeInvalidatedCredentials() { InstanceInfo targetInstanceInfo = createInstanceInfo("host", 1000, 1433); String targetInstanceId = targetInstanceInfo.getInstanceId(); InstanceInfo gatewayInstance = createInstanceInfo("gateway", 111, 123); String gatewayUrl = "https: Application application = mock(Application.class); when(application.getInstances()).thenReturn(Collections.singletonList(gatewayInstance)); when(registry.getApplication("GATEWAY")).thenReturn(application); final String messageNotifyError = "org.zowe.apiml.discovery.errorNotifyingGateway"; when(messageService.createMessage(messageNotifyError)).thenReturn(createMessage(messageNotifyError)); final String messageKey = "org.zowe.apiml.discovery.registration.gateway.notify"; Message msg = createMessage(messageKey, gatewayUrl, targetInstanceId); when(messageService.createMessage(messageKey, gatewayUrl, targetInstanceId)).thenReturn(msg); gatewayNotifierSync.distributeInvalidatedCredentials(targetInstanceId); verify(restTemplate, times(1)).getForEntity(eq(gatewayUrl), any(), (Exception) any()); when(restTemplate.getForEntity(anyString(), any())).thenThrow(new RuntimeException()); gatewayNotifierSync.distributeInvalidatedCredentials(targetInstanceId); verify(messageService, times(1)).createMessage(messageKey, gatewayUrl, targetInstanceId); }