### Question:
EnvironmentModificationService { public EnvironmentDto changeCredentialByEnvironmentCrn(String accountId, String crn, EnvironmentChangeCredentialDto dto) { Environment environment = environmentService .findByResourceCrnAndAccountIdAndArchivedIsFalse(crn, accountId) .orElseThrow(() -> new NotFoundException(String.format("No environment found with CRN '%s'", crn))); return changeCredential(accountId, crn, dto, environment); } EnvironmentModificationService(EnvironmentDtoConverter environmentDtoConverter, EnvironmentService environmentService,
            CredentialService credentialService, NetworkService networkService, AuthenticationDtoConverter authenticationDtoConverter,
            ParametersService parametersService, EnvironmentFlowValidatorService environmentFlowValidatorService,
            EnvironmentResourceService environmentResourceService); EnvironmentDto editByName(String environmentName, EnvironmentEditDto editDto); EnvironmentDto editByCrn(String crn, EnvironmentEditDto editDto); EnvironmentDto changeCredentialByEnvironmentName(String accountId, String environmentName, EnvironmentChangeCredentialDto dto); EnvironmentDto changeCredentialByEnvironmentCrn(String accountId, String crn, EnvironmentChangeCredentialDto dto); EnvironmentDto changeTelemetryFeaturesByEnvironmentName(String accountId, String environmentName,
            EnvironmentFeatures features); EnvironmentDto changeTelemetryFeaturesByEnvironmentCrn(String accountId, String crn,
            EnvironmentFeatures features);  }### Answer:
@Test void changeCredentialByEnvironmentCrn() { String credentialName = "credentialName"; final Credential value = new Credential(); EnvironmentChangeCredentialDto environmentChangeDto = EnvironmentChangeCredentialDto.EnvironmentChangeCredentialDtoBuilder .anEnvironmentChangeCredentialDto() .withCredentialName(credentialName) .build(); when(environmentService .findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(Optional.of(new Environment())); when(credentialService.getByNameForAccountId(eq(credentialName), eq(ACCOUNT_ID), eq(ENVIRONMENT))).thenReturn(value); environmentModificationServiceUnderTest.changeCredentialByEnvironmentCrn(ACCOUNT_ID, CRN, environmentChangeDto); ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class); verify(environmentService).save(environmentArgumentCaptor.capture()); assertEquals(value, environmentArgumentCaptor.getValue().getCredential()); }