### Question:
EnvironmentResourceDeletionService { public void deleteClusterDefinitionsOnCloudbreak(String environmentCrn) { try { Set<String> names = getClusterDefinitionNamesInEnvironment(TEMP_WORKSPACE_ID, environmentCrn); clusterTemplateV4Endpoint.deleteMultiple(TEMP_WORKSPACE_ID, names, null, environmentCrn); } catch (WebApplicationException e) { propagateException("Failed to delete cluster definition(s) from Cloudbreak due to:", e); } catch (ProcessingException | UnableToDeleteClusterDefinitionException e) { propagateException("Failed to delete cluster definition(s) from Cloudbreak due to:", e); } } EnvironmentResourceDeletionService(SdxEndpoint sdxEndpoint, DatalakeV4Endpoint datalakeV4Endpoint, DistroXV1Endpoint distroXV1Endpoint,
            ClusterTemplateV4Endpoint clusterTemplateV4Endpoint); void deleteClusterDefinitionsOnCloudbreak(String environmentCrn); Set<String> getAttachedSdxClusterCrns(Environment environment); Set<String> getDatalakeClusterNames(Environment environment);  }### Answer:
@Test void testWhenDeleteClusterDefinitionsOnCloudbreakThrowsWebApplicationExceptionThenItShouldBeCatchedAndEnvironmentServiceExceptionShouldBeThrown() { WebApplicationException exception = Mockito.mock(WebApplicationException.class); when(clusterTemplateViewV4Responses.getResponses()).thenReturn(Collections.emptySet()); when(clusterTemplateV4Endpoint.list(anyLong())).thenReturn(clusterTemplateViewV4Responses); doThrow(exception).when(clusterTemplateV4Endpoint).deleteMultiple(eq(WORKSPACE_ID), any(), any(), eq(ENVIRONMENT_CRN)); Response response = Mockito.mock(Response.class); when(exception.getResponse()).thenReturn(response); when(response.readEntity(any(Class.class))).thenReturn("error"); Assertions.assertThrows(EnvironmentServiceException.class, () -> environmentResourceDeletionServiceUnderTest.deleteClusterDefinitionsOnCloudbreak(ENVIRONMENT_CRN)); verify(clusterTemplateV4Endpoint).deleteMultiple(anyLong(), any(), any(), anyString()); verify(clusterTemplateV4Endpoint).deleteMultiple(eq(WORKSPACE_ID), any(), any(), eq(ENVIRONMENT_CRN)); }
@Test void testWhenDeleteClusterDefinitionsOnCloudbreakThrowsProcessingExceptionThenItShouldBeCatchedAndEnvironmentServiceExceptionShouldBeThrown() { doThrow(ProcessingException.class).when(clusterTemplateV4Endpoint).deleteMultiple(eq(WORKSPACE_ID), any(), any(), eq(ENVIRONMENT_CRN)); when(clusterTemplateViewV4Responses.getResponses()).thenReturn(Collections.emptySet()); when(clusterTemplateV4Endpoint.list(anyLong())).thenReturn(clusterTemplateViewV4Responses); Assertions.assertThrows(EnvironmentServiceException.class, () -> environmentResourceDeletionServiceUnderTest.deleteClusterDefinitionsOnCloudbreak(ENVIRONMENT_CRN)); verify(clusterTemplateV4Endpoint).deleteMultiple(anyLong(), any(), any(), anyString()); verify(clusterTemplateV4Endpoint).deleteMultiple(eq(WORKSPACE_ID), any(), any(), eq(ENVIRONMENT_CRN)); }
@Test void testWhenDeleteClusterDefinitionsThrowsUnableToDeleteClusterDefinitionExceptionThenItShouldBeCatchedAndEnvironmentServiceExceptionShouldBeThrown() { doThrow(UnableToDeleteClusterDefinitionException.class).when(clusterTemplateV4Endpoint).deleteMultiple(eq(WORKSPACE_ID), any(), any(), eq(ENVIRONMENT_CRN)); when(clusterTemplateViewV4Responses.getResponses()).thenReturn(Collections.emptySet()); when(clusterTemplateV4Endpoint.list(anyLong())).thenReturn(clusterTemplateViewV4Responses); Assertions.assertThrows(EnvironmentServiceException.class, () -> environmentResourceDeletionServiceUnderTest.deleteClusterDefinitionsOnCloudbreak(ENVIRONMENT_CRN)); verify(clusterTemplateV4Endpoint).deleteMultiple(anyLong(), any(), any(), anyString()); verify(clusterTemplateV4Endpoint).deleteMultiple(eq(WORKSPACE_ID), any(), any(), eq(ENVIRONMENT_CRN)); }