ValueCredentialVersion extends CredentialVersion { @Override public void setValue(final String value) { if (value == null) { throw new IllegalArgumentException("value cannot be null"); } super.setValue(value); } ValueCredentialVersion(final ValueCredentialVersionData delegate);  ValueCredentialVersion(final String name);  ValueCredentialVersion();  ValueCredentialVersion(final StringCredentialValue value, final Encryptor encryptor); @Override void setValue(final String value); @Override boolean matchesGenerationParameters(final GenerationParameters generationParameters); @Override String getCredentialType(); @Override void rotate(); @Override GenerationParameters getGenerationParameters();  }
@Test public void setValue_encryptsValue() { valueCredentialData = new ValueCredentialVersionData("foo"); subject = new ValueCredentialVersion(valueCredentialData); subject.setEncryptor(encryptor); subject.setValue("my-value"); assertThat(valueCredentialData.getEncryptedValueData().getEncryptedValue(), notNullValue()); assertThat(valueCredentialData.getEncryptedValueData().getNonce(), notNullValue()); }
@Test public void getValue_decryptsValue() { valueCredentialData = new ValueCredentialVersionData("foo"); subject = new ValueCredentialVersion(valueCredentialData); subject.setEncryptor(encryptor); subject.setValue("my-value"); assertThat(subject.getValue(), equalTo("my-value")); }
@Test(expected = IllegalArgumentException.class) public void setValue_whenValueIsNull_throwsException() { valueCredentialData = new ValueCredentialVersionData("foo"); subject = new ValueCredentialVersion(valueCredentialData); subject.setEncryptor(encryptor); subject.setValue(null); }