### Question:
ChangePrimaryGatewayService { public Optional<String> getPrimaryGatewayInstanceId(Stack stack) { Optional<String> primaryGatewayInstanceId = Optional.empty(); try { primaryGatewayInstanceId = Optional.of(gatewayConfigService.getPrimaryGatewayConfig(stack).getInstanceId()); } catch (NotFoundException e) { LOGGER.debug("No active primary gateway found"); } return primaryGatewayInstanceId; }  Optional<String> getPrimaryGatewayInstanceId(Stack stack); String selectNewPrimaryGatewayInstanceId(Stack stack, List<String> repairInstanceIds); void changePrimaryGatewayMetadata(Stack stack, Optional<String> formerPrimaryGatwayInstanceId, String newPrimaryGatewayInstanceId);  }### Answer:
@Test void testGetPrimaryGatewayInstanceIdWhenPresent() { Stack stack = mock(Stack.class); GatewayConfig gatewayConfig = mock(GatewayConfig.class); when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig); when(gatewayConfig.getInstanceId()).thenReturn(INSTANCE_ID_1); assertEquals(Optional.of(INSTANCE_ID_1), underTest.getPrimaryGatewayInstanceId(stack)); verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack)); }
@Test void testGetPrimaryGatewayInstanceIdWhenNotPresent() { Stack stack = mock(Stack.class); when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenThrow(NotFoundException.class); assertEquals(Optional.empty(), underTest.getPrimaryGatewayInstanceId(stack)); verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack)); }