PasswordCredentialVersion extends CredentialVersion { public void setPasswordAndGenerationParameters( final String password, final StringGenerationParameters generationParameters ) { if (password == null) { throw new IllegalArgumentException("password cannot be null"); } try { final String generationParameterJson = generationParameters != null ? jsonObjectMapper.writeValueAsString(generationParameters) : null; if (generationParameterJson != null) { final EncryptedValue encryptedParameters = getEncryptor().encrypt(generationParameterJson); delegate.setEncryptedGenerationParameters(encryptedParameters); } final EncryptedValue encryptedPassword = getEncryptor().encrypt(password); delegate.setEncryptedValueData(encryptedPassword); } catch (final Exception e) { throw new RuntimeException(e); } } PasswordCredentialVersion(final PasswordCredentialVersionData delegate);  PasswordCredentialVersion(final String name);  PasswordCredentialVersion();  PasswordCredentialVersion(
    final StringCredentialValue password,
    final StringGenerationParameters generationParameters,
    final Encryptor encryptor
  ); String getPassword(); void setPasswordAndGenerationParameters(
    final String password,
    final StringGenerationParameters generationParameters
  ); @Override StringGenerationParameters getGenerationParameters(); @Override boolean matchesGenerationParameters(final GenerationParameters generationParameters); @Override String getCredentialType(); @Override void rotate();  }
@Test public void setPasswordAndGenerationParameters_setsTheNonceAndEncryptedValue() { subject.setPasswordAndGenerationParameters(PASSWORD, null); assertThat(passwordCredentialData.getEncryptedValueData().getEncryptedValue(), notNullValue()); assertThat(passwordCredentialData.getNonce(), notNullValue()); }
@Test(expected = IllegalArgumentException.class) public void setPasswordAndGenerationParameters_throwsAnExceptionWhenSettingANullValue() { subject.setPasswordAndGenerationParameters(null, null); }
@Test public void setPasswordAndGenerationParameters_setsParamsNonceAndEncryptedGenerationParameters() { subject.setPasswordAndGenerationParameters(PASSWORD, generationParameters); assertThat(passwordCredentialData.getEncryptedGenerationParameters().getEncryptedValue(), notNullValue()); assertThat(passwordCredentialData.getEncryptedGenerationParameters().getNonce(), notNullValue()); }
@Test public void setPasswordAndGenerationParameters_shouldSetNullsIfTheParamsAreNulls() { subject.setPasswordAndGenerationParameters(PASSWORD, null); assertThat(passwordCredentialData.getEncryptedGenerationParameters(), nullValue()); }
@Test public void setPasswordAndGenerationParameters_shouldSaveGenerationParams_AsSnakeCaseJson() { subject.setPasswordAndGenerationParameters(PASSWORD, generationParameters); final String expectedJsonString = "{\"exclude_lower\":true}"; verify(encryptor, times(1)).encrypt(expectedJsonString); }