EmbeddedUserService implements UserService { @Override public String encrypt(final String raw) { return passwordEncoder.encode(raw); } @Autowired  EmbeddedUserService(final UserRepository userRepository, final SecureRandom secureRandom); @Override void save(final UserEntity userEntity); @Override UserEntity getById(final UUID key); @Override boolean containsKey(final UUID key); @Override boolean containsName(final String name); @Override UserEntity findByName(final String name); @Override String encrypt(final String raw); @Override boolean matches(final String raw, final String encoded); @Override long count();  }
@Test public void testEncrypt() { Mockito.doAnswer((Answer<Void>) mock -> { final byte[] bytes = mock.getArgument(0); for (int i = 0; i < bytes.length; ++i) { bytes[i] = 0x42; } return null; }).when(mockSecureRandom).nextBytes(ArgumentMatchers.any()); assertEquals(ENCRYPTED_PASSWORD, userService.encrypt(UNENCRYPTED_PASSWORD)); Mockito.verify(mockSecureRandom).nextBytes(ArgumentMatchers.any()); }