UrlSafeTokenGenerator implements TokenGenerator { @Override public String generate() { String generatedToken = BaseEncoding.base64Url().encode(UUID.randomUUID().toString().getBytes()); return trimRight(generatedToken, '='); }  @Override String generate();  }
@Test public void happyPath() { String token = new UrlSafeTokenGenerator().generate(); assertThat(token,is(not(nullValue()))); }
@Test public void uniqueTokensAreGenerated() { UrlSafeTokenGenerator tokenGenerator = new UrlSafeTokenGenerator(); Set<String> tokens = Sets.newHashSet(); for (int i = 0; i < 10;i++) { tokens.add(tokenGenerator.generate()); } assertThat(tokens.size(), is(equalTo(10))); }