### Question:
AzureVaultKeyPairValidator implements ConstraintValidator<ValidAzureVaultKeyPair, AzureVaultKeyPair> { @Override public boolean isValid(final AzureVaultKeyPair keypair, final ConstraintValidatorContext cvc) { if (keypair == null) { return true; } return Objects.isNull(keypair.getPublicKeyVersion()) == Objects.isNull(keypair.getPrivateKeyVersion()); }  @Override boolean isValid(final AzureVaultKeyPair keypair, final ConstraintValidatorContext cvc);  }### Answer:
@Test public void nullKeyPairIsValid() { assertThat(validator.isValid(null, cvc)).isTrue(); }
@Test public void publicAndPrivateKeyVersionsNotSetIsValid() { when(keyPair.getPublicKeyVersion()).thenReturn(null); when(keyPair.getPrivateKeyVersion()).thenReturn(null); assertThat(validator.isValid(keyPair, cvc)).isTrue(); }
@Test public void publicAndPrivateKeyVersionsAreSetIsValid() { when(keyPair.getPublicKeyVersion()).thenReturn("pubVer"); when(keyPair.getPrivateKeyVersion()).thenReturn("privVer"); assertThat(validator.isValid(keyPair, cvc)).isTrue(); }
@Test public void onlyPublicKeyVersionSetIsNotValid() { when(keyPair.getPublicKeyVersion()).thenReturn("pubVer"); when(keyPair.getPrivateKeyVersion()).thenReturn(null); assertThat(validator.isValid(keyPair, cvc)).isFalse(); }
@Test public void onlyPrivateKeyVersionSetIsNotValid() { when(keyPair.getPublicKeyVersion()).thenReturn(null); when(keyPair.getPrivateKeyVersion()).thenReturn("privVer"); assertThat(validator.isValid(keyPair, cvc)).isFalse(); }