FileBasedUserRepository implements UserRepository<U> { @Override public Optional<String> findCredentialByUserName(String userName) { return credentials.get(userName); } FileBasedUserRepository(Class<U> userClass, ObjectMapper mapper, U defaultAdmin,
                                   Path usersPath, Path credentialsPath, boolean reloadOnChange); @Override Optional<U> findUserByName(String name); @Override Optional<String> findCredentialByUserName(String userName); @Override boolean isAdminDefined(); @Override U defaultAdmin();  }
@Test public void should_load_credentials() throws Exception { FileBasedUserRepository<StdUser> repo = newRepo(false); Files.copy(getClass().getResourceAsStream("credentials.json"), credentialsPath, StandardCopyOption.REPLACE_EXISTING); assertThat(repo.findCredentialByUserName("admin").isPresent()).isFalse(); assertThat(repo.findCredentialByUserName("john")).isEqualTo(Optional.of("johnpwd")); }
@Test public void should_reload_credentials() throws Exception { FileBasedUserRepository<StdUser> repo = newRepo(true); Files.copy(getClass().getResourceAsStream("credentials.json"), credentialsPath, StandardCopyOption.REPLACE_EXISTING); assertThat(repo.findCredentialByUserName("john")).isEqualTo(Optional.of("johnpwd")); Thread.sleep(1000); Files.copy(getClass().getResourceAsStream("credentials2.json"), credentialsPath, StandardCopyOption.REPLACE_EXISTING); assertThat(repo.findCredentialByUserName("john")).isEqualTo(Optional.of("johnpwd2")); }