UsernameGenerator { public StringCredentialValue generateCredential() { final StringGenerationParameters parameters = new StringGenerationParameters(); parameters.setLength(20); parameters.setExcludeNumber(true); return passayStringCredentialGenerator.generateCredential(parameters); } @Autowired  UsernameGenerator(final PassayStringCredentialGenerator passayStringCredentialGenerator); StringCredentialValue generateCredential();  }
@Test public void generateCredential_generatesACredential() { final StringCredentialValue expected = new StringCredentialValue("fake-credential"); when(passayStringCredentialGenerator.generateCredential(any(StringGenerationParameters.class))) .thenReturn(expected); final StringCredentialValue credential = subject.generateCredential(); assertThat(credential, equalTo(expected)); }
@Test public void generateCredential_usesAppropriateGenerationParameters() { final ArgumentCaptor<StringGenerationParameters> captor = ArgumentCaptor.forClass(StringGenerationParameters.class); subject.generateCredential(); verify(passayStringCredentialGenerator, times(1)) .generateCredential(captor.capture()); final StringGenerationParameters actual = captor.getValue(); assertThat(actual.getLength(), equalTo(20)); assertThat(actual.isExcludeLower(), equalTo(false)); assertThat(actual.isExcludeUpper(), equalTo(false)); assertThat(actual.isExcludeNumber(), equalTo(true)); assertThat(actual.isIncludeSpecial(), equalTo(false)); }