### Question:
SpringSecurityBasicAuthCredentialProviderFactory extends CredentialProviderFactory<CredentialGenerationConfig> { @Override public CredentialProvider create(CredentialGenerationConfig config) { return new CredentialProvider() { @Override public Mono<BackingApplication> addCredentials(BackingApplication backingApplication, String serviceInstanceGuid) { return generateCredentials(config, backingApplication, serviceInstanceGuid) .flatMap(user -> addUserToEnvironment(backingApplication, user)) .thenReturn(backingApplication); } @Override public Mono<BackingApplication> deleteCredentials(BackingApplication backingApplication, String serviceInstanceGuid) { return credentialGenerator .deleteUser(backingApplication.getName(), serviceInstanceGuid, CREDENTIAL_DESCRIPTOR) .thenReturn(backingApplication); } }; } SpringSecurityBasicAuthCredentialProviderFactory(CredentialGenerator credentialGenerator); @Override CredentialProvider create(CredentialGenerationConfig config); static final String SPRING_SECURITY_USER_NAME_KEY; static final String SPRING_SECURITY_USER_PASSWORD_KEY; }### Answer:
@Test @SuppressWarnings("unchecked") void addCredentials() { BackingApplication backingApplication = BackingApplication.builder() .build(); given(credentialGenerator.generateUser(backingApplication.getName(), "service-instance-id", "basic", 8, true, false, true, false)) .willReturn(Mono.just(Tuples.of("username", "password"))); StepVerifier .create(provider.addCredentials(backingApplication, "service-instance-id")) .expectNext(backingApplication) .verifyComplete(); assertThat(backingApplication.getEnvironment()) .containsEntry(SPRING_SECURITY_USER_NAME_KEY, "username") .containsEntry(SPRING_SECURITY_USER_PASSWORD_KEY, "password"); }
@Test void deleteCredentials() { BackingApplication backingApplication = BackingApplication .builder() .build(); given(credentialGenerator.deleteUser(backingApplication.getName(), "service-instance-id", "basic")) .willReturn(Mono.empty()); StepVerifier .create(provider.deleteCredentials(backingApplication, "service-instance-id")) .expectNext(backingApplication) .verifyComplete(); then(credentialGenerator).should().deleteUser(backingApplication.getName(), "service-instance-id", "basic"); verifyNoMoreInteractions(credentialGenerator); }