### Question:
ClusterServiceRunner { public void redeployGatewayCertificate(Long stackId) { Stack stack = stackService.getByIdWithListsInTransaction(stackId); Cluster cluster = clusterService.retrieveClusterByStackIdWithoutAuth(stack.getId()) .orElseThrow(NotFoundException.notFound("cluster", stack.getId())); hostRunner.redeployGatewayCertificate(stack, cluster); }  void runAmbariServices(Long stackId); void updateAmbariClientConfig(Stack stack, Cluster cluster); void updateSaltState(Long stackId); void redeployGatewayCertificate(Long stackId); String changePrimaryGateway(Long stackId);  }### Answer:
@Test public void testRedeployGatewayCertificateWhenClusterCouldNotBeFoundByStackId() { when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack); when(clusterService.retrieveClusterByStackIdWithoutAuth(anyLong())).thenThrow(new NotFoundException("Cluster could not be found")); Assertions.assertThrows(NotFoundException.class, () -> underTest.redeployGatewayCertificate(0L)); }
@Test public void testRedeployGatewayCertificateWhenRedeployOnHostRunnerThrowRuntimeException() { when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack); when(clusterService.retrieveClusterByStackIdWithoutAuth(anyLong())).thenReturn(Optional.of(cluster)); doThrow(new RuntimeException("Stg. failed")).when(hostRunner).redeployGatewayCertificate(any(), any()); Assertions.assertThrows(RuntimeException.class, () -> underTest.redeployGatewayCertificate(0L)); }
@Test public void testRedeployGatewayCertificateHappyFlow() { when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack); when(clusterService.retrieveClusterByStackIdWithoutAuth(anyLong())).thenReturn(Optional.of(cluster)); underTest.redeployGatewayCertificate(0L); verify(hostRunner, times(1)).redeployGatewayCertificate(any(), any()); }