@Test
public void rotate() throws Exception {

  final EncryptedValue newEncryption = new EncryptedValue(UUID.randomUUID(), "expected value".getBytes(UTF_8),
    "nonce".getBytes(UTF_8));
  final EncryptedValue value = new EncryptedValue();
  value.setEncryptedValue("bytes".getBytes(UTF_8));
  value.setEncryptionKeyUuid(UUID.randomUUID());
  value.setNonce("nonce".getBytes(UTF_8));
  when(encryptor.decrypt(any(EncryptedValue.class))).thenReturn("expected value");
  when(encryptor.encrypt("expected value")).thenReturn(newEncryption);
  subject.rotate(value);
  verify(encryptedValueRepository).saveAndFlush(newEncryption);
  assertThat(newEncryption.getUuid(), equalTo(value.getUuid()));
}