### Question:
VirtualGroupService { public Map<UmsRight, String> createVirtualGroups(String accountId, String environmentCrn) { Map<UmsRight, String> virtualGroups = new HashMap<>(); for (UmsRight right : UmsRight.values()) { virtualGroups.put(right, createOrGetVirtualGroup(accountId, environmentCrn, right.getRight())); } return virtualGroups; }  Map<UmsRight, String> createVirtualGroups(String accountId, String environmentCrn); String getVirtualGroup(VirtualGroupRequest virtualGroupRequest, String right); void cleanupVirtualGroups(String accountId, String environmentCrn);  }### Answer:
@Test public void testCreateVirtualGroupsWithNonExistingGroups() { doThrow(new StatusRuntimeException(Status.NOT_FOUND)) .when(grpcUmsClient).getWorkloadAdministrationGroupName(anyString(), eq(ACCOUNT_ID), eq(Optional.empty()), anyString(), eq(ENV_CRN)); when(grpcUmsClient.setWorkloadAdministrationGroupName(anyString(), eq(ACCOUNT_ID), eq(Optional.empty()), anyString(), eq(ENV_CRN))).thenReturn(MOCK_VIRTUAL_GROUP); Map<UmsRight, String> result = virtualGroupService.createVirtualGroups(ACCOUNT_ID, ENV_CRN); assertEquals(UmsRight.values().length, result.size()); verify(grpcUmsClient, times(UmsRight.values().length)).setWorkloadAdministrationGroupName(crnCaptor.capture(), eq(ACCOUNT_ID), eq(Optional.empty()), rightCaptor.capture(), eq(ENV_CRN)); assertEquals(INTERNAL_ACTOR_CRN, crnCaptor.getValue()); for (UmsRight umsRight : UmsRight.values()) { assertEquals(MOCK_VIRTUAL_GROUP, result.get(umsRight)); assertTrue(rightCaptor.getAllValues().contains(umsRight.getRight())); } }
@Test public void testCreateVirtualGroupsWithExistingGroups() { when(grpcUmsClient.getWorkloadAdministrationGroupName(anyString(), eq(ACCOUNT_ID), eq(Optional.empty()), anyString(), eq(ENV_CRN))).thenReturn(MOCK_VIRTUAL_GROUP); Map<UmsRight, String> result = virtualGroupService.createVirtualGroups(ACCOUNT_ID, ENV_CRN); assertEquals(UmsRight.values().length, result.size()); verify(grpcUmsClient, times(0)).setWorkloadAdministrationGroupName(anyString(), eq(ACCOUNT_ID), eq(Optional.empty()), anyString(), eq(ENV_CRN)); for (UmsRight umsRight : UmsRight.values()) { assertEquals(MOCK_VIRTUAL_GROUP, result.get(umsRight)); } }