### Question:
HostDeletionService { public void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts) throws FreeIpaClientException, DeleteException { try { Pair<Set<String>, Map<String, String>> removeHostsResult = removeHosts(client, hosts); if (!removeHostsResult.getSecond().isEmpty()) { throw new DeleteException(HOST_DELETION_FAILED + ' ' + removeHostsResult.getSecond()); } } catch (RetryableFreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new RetryableFreeIpaClientException(HOST_DELETION_FAILED, e, new DeleteException(HOST_DELETION_FAILED)); } catch (FreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new DeleteException(HOST_DELETION_FAILED); } }  Pair<Set<String>, Map<String, String>> removeHosts(FreeIpaClient client, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeServers(FreeIpaClient client, Set<String> hosts); void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts);  }### Answer:
@Test(expected = DeleteException.class) public void expectDeleteExceptionIfHostCollectionFails() throws FreeIpaClientException { when(freeIpaClient.findAllHost()).thenThrow(new FreeIpaClientException("error")); underTest.deleteHostsWithDeleteException(freeIpaClient, Set.of("testHost")); }
@Test(expected = DeleteException.class) public void expectDeleteExceptionWhenOneFailedDeletion() throws FreeIpaClientException { Set<String> hosts = Set.of("host1", "host2"); Host host1 = new Host(); host1.setFqdn("host1"); Host host2 = new Host(); host2.setFqdn("host2"); when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2)); when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException("not handled")); underTest.deleteHostsWithDeleteException(freeIpaClient, hosts); }