### Question:
ClusterKerberosService { public void leaveDomains(Stack stack) throws CloudbreakException { leaveDomains(stack, stackUtil.collectReachableNodes(stack)); }  void leaveDomains(Stack stack); void leaveDomains(Stack stack, Set<Node> nodes);  }### Answer:
@Test public void testAdLeave() throws CloudbreakException, CloudbreakOrchestratorFailedException { when(kerberosConfigService.get(anyString(), anyString())).thenReturn(Optional.of(kerberosConfig)); when(kerberosDetailService.isAdJoinable(any())).thenReturn(Boolean.TRUE); when(stackUtil.collectReachableNodes(any())).thenReturn(Set.of(node)); underTest.leaveDomains(stack); verify(stackUtil).collectReachableNodes(stack); verify(hostOrchestrator, times(1)) .leaveDomain(any(GatewayConfig.class), eq(Set.of(node)), eq("ad_member"), eq("ad_leave"), any(ExitCriteriaModel.class)); }
@Test public void testIpaLeave() throws CloudbreakException, CloudbreakOrchestratorFailedException { when(kerberosConfigService.get(anyString(), anyString())).thenReturn(Optional.of(kerberosConfig)); when(kerberosDetailService.isIpaJoinable(any())).thenReturn(Boolean.TRUE); underTest.leaveDomains(stack); verify(hostOrchestrator, times(1)) .leaveDomain(any(GatewayConfig.class), any(), eq("ipa_member"), eq("ipa_leave"), any(ExitCriteriaModel.class)); }
@Test(expected = CloudbreakException.class) public void testExceptionMapped() throws CloudbreakOrchestratorFailedException, CloudbreakException { when(kerberosConfigService.get(anyString(), anyString())).thenReturn(Optional.of(kerberosConfig)); when(kerberosDetailService.isAdJoinable(any())).thenReturn(Boolean.TRUE); doThrow(new CloudbreakOrchestratorFailedException("error")).when(hostOrchestrator) .leaveDomain(any(GatewayConfig.class), any(), eq("ad_member"), eq("ad_leave"), any(ExitCriteriaModel.class)); underTest.leaveDomains(stack); }