KeyStoreSecretProvider implements SecretProvider { @Override public boolean setToken(ZonkyApiToken apiToken) { try { if (apiToken == null) { this.ksh.delete(ALIAS_TOKEN); this.ksh.save(); return true; } else { return this.set(ALIAS_TOKEN, () -> ZonkyApiTokenImpl.marshal(apiToken) .toCharArray()); } } catch (final Exception ex) { LOGGER.warn("Failed storing Zonky API token to the keystore.", ex); return false; } } KeyStoreSecretProvider(final KeyStoreHandler ksh); @Override char[] getPassword(); @Override String getUsername(); @Override Optional<ZonkyApiToken> getToken(); @Override boolean setToken(ZonkyApiToken apiToken); boolean setPassword(final char[] password); boolean setUsername(final String username); @Override boolean isPersistent();  }
@Test void setToken() { final SecretProvider p = newProvider(USR, PWD); assertThat(p.getToken()).isEmpty(); final ZonkyApiToken token = new ZonkyApiTokenImpl(UUID.randomUUID() .toString(), UUID.randomUUID() .toString(), 299); assertThat(p.setToken(token)).isTrue(); assertThat(p.getToken()).contains(token); assertThat(p.setToken(null)).isTrue(); assertThat(p.getToken()).isEmpty(); }