EncryptedValueDataService { public void rotate(final EncryptedValue encryptedValue) { final String decryptedValue = encryptor.decrypt(encryptedValue); final EncryptedValue newEncryptedValue = encryptor.encrypt(decryptedValue); newEncryptedValue.setUuid(encryptedValue.getUuid()); encryptedValueRepository.saveAndFlush(newEncryptedValue); } @Autowired protected  EncryptedValueDataService(
    final EncryptedValueRepository encryptedValueRepository,
    final Encryptor encryptor); Long countAllByCanaryUuid(final UUID uuid); Slice<EncryptedValue> findByCanaryUuids(final List<UUID> canaryUuids); void rotate(final EncryptedValue encryptedValue);  }
@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())); }