### Question:
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public EnvironmentDto getByCrnAndAccountId(String crn, String accountId) { LOGGER.debug("Getting environment by crn '{}' and account id '{}'.", crn, accountId); Optional<Environment> environment = environmentRepository .findByResourceCrnAndAccountIdAndArchivedIsFalse(crn, accountId); MDCBuilder.buildMdcContext(environment.orElseThrow(() -> new NotFoundException(String.format("No environment found with resource CRN '%s'.", crn)))); return environmentDtoConverter.environmentToDto(environment.get()); } EnvironmentService(
            EnvironmentValidatorService validatorService,
            EnvironmentRepository environmentRepository,
            PlatformParameterService platformParameterService,
            EnvironmentDtoConverter environmentDtoConverter,
            DelegatingCliEnvironmentRequestConverter delegatingCliEnvironmentRequestConverter,
            GrpcUmsClient grpcUmsClient,
            TransactionService transactionService); Environment save(Environment environment); Environment saveWithOwnerRoleAssignment(Environment environment); EnvironmentDto getEnvironmentDto(Environment environment); EnvironmentDto getByNameAndAccountId(String environmentName, String accountId); EnvironmentDto getByCrnAndAccountId(String crn, String accountId); List<EnvironmentDto> listByAccountId(String accountId); void setRegions(Environment environment, Set<String> requestedRegions, CloudRegions cloudRegions); CloudRegions getRegionsByEnvironment(Environment environment); Environment findEnvironmentByIdOrThrow(Long id); Optional<Environment> findEnvironmentById(Long id); Optional<EnvironmentDto> findById(Long id); void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions); List<EnvironmentDto> findAllByIdInAndStatusIn(Collection<Long> resourceIds, Collection<EnvironmentStatus> environmentStatuses); List<EnvironmentDto> findAllByStatusIn(Collection<EnvironmentStatus> environmentStatuses); Object getCreateEnvironmentForCli(EnvironmentRequest environmentRequest, String cloudPlatform); Object getCreateEnvironmentForCli(EnvironmentDto environmentDto); void setAdminGroupName(Environment environment, String adminGroupName); Collection<Environment> findByResourceCrnInAndAccountIdAndArchivedIsFalse(Collection<String> crns, String accountId); Collection<Environment> findByNameInAndAccountIdAndArchivedIsFalse(Collection<String> environmentNames, String accountId); String getCrnByNameAndAccountId(String environmentName, String accountId); @Override Long getResourceIdByResourceCrn(String resourceCrn); @Override Long getResourceIdByResourceName(String resourceName); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType(); List<String> findNameWithAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); List<Environment> findAllByAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); void assignEnvironmentAdminRole(String userCrn, String environmentCrn); List<Environment> findAllForAutoSync();  }### Answer:
@Test public void getByCrnAndAccountId() { when(environmentRepository .findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(TestConstants.CRN), eq(TestConstants.ACCOUNT_ID))) .thenReturn(Optional.of(environment)); when(environmentDtoConverter.environmentToDto(any())).thenReturn(environmentDto); assertEquals(environmentDto, environmentServiceUnderTest .getByCrnAndAccountId(TestConstants.CRN, TestConstants.ACCOUNT_ID)); }