### Question:
VirtualGroupService { public String getVirtualGroup(VirtualGroupRequest virtualGroupRequest, String right) { String virtualGroup; String adminGroup = virtualGroupRequest.getAdminGroup(); if (StringUtils.isEmpty(adminGroup)) { virtualGroup = createOrGetVirtualGroup(virtualGroupRequest.getAccountId(), virtualGroupRequest.getEnvironmentCrn(), right); } else { virtualGroup = adminGroup; LOGGER.info("Admingroup [{}] given by the user is used for {} right on {} environment", adminGroup, right, virtualGroupRequest.getEnvironmentCrn()); } return virtualGroup; }  Map<UmsRight, String> createVirtualGroups(String accountId, String environmentCrn); String getVirtualGroup(VirtualGroupRequest virtualGroupRequest, String right); void cleanupVirtualGroups(String accountId, String environmentCrn);  }### Answer:
@Test public void testGetVirtualGroupWithNoAdminGroupProvidedAndNewGroupNeedsToBeCreated() { 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); VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(ENV_CRN, null); String result = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.ENVIRONMENT_ACCESS.getRight()); verify(grpcUmsClient, times(1)).setWorkloadAdministrationGroupName(crnCaptor.capture(), eq(ACCOUNT_ID), eq(Optional.empty()), rightCaptor.capture(), eq(ENV_CRN)); assertEquals(INTERNAL_ACTOR_CRN, crnCaptor.getValue()); assertEquals(MOCK_VIRTUAL_GROUP, result); assertTrue(rightCaptor.getAllValues().contains(UmsRight.ENVIRONMENT_ACCESS.getRight())); }
@Test public void testGetVirtualGroupWithEmptyGroupProvidedAndNewGroupNeedsToBeCreated() { 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); VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(ENV_CRN, ""); String result = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.ENVIRONMENT_ACCESS.getRight()); verify(grpcUmsClient, times(1)).setWorkloadAdministrationGroupName(crnCaptor.capture(), eq(ACCOUNT_ID), eq(Optional.empty()), rightCaptor.capture(), eq(ENV_CRN)); assertEquals(INTERNAL_ACTOR_CRN, crnCaptor.getValue()); assertEquals(MOCK_VIRTUAL_GROUP, result); assertTrue(rightCaptor.getAllValues().contains(UmsRight.ENVIRONMENT_ACCESS.getRight())); }
@Test public void testGetVirtualGroupWenAdminGroupIsProvided() { VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(ENV_CRN, "mockgroup"); String result = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.ENVIRONMENT_ACCESS.getRight()); verify(grpcUmsClient, times(0)).getWorkloadAdministrationGroupName(anyString(), eq(ACCOUNT_ID), eq(Optional.empty()), anyString(), eq(ENV_CRN)); verify(grpcUmsClient, times(0)).setWorkloadAdministrationGroupName(anyString(), eq(ACCOUNT_ID), eq(Optional.empty()), anyString(), eq(ENV_CRN)); assertEquals("mockgroup", result); }