AuthTicketCache extends ComponentSupport { public void add(final String user, final String token) { synchronized (lock) { expireTokens(); UserAuthToken key = new UserAuthToken(user, token); checkState(!tokens.containsKey(key), "Duplicate token"); tokens.put(key, now()); } } @Inject  AuthTicketCache(@Named(CPREFIX + ".expireAfter:-20s}") final Time expireAfter); @VisibleForTesting  AuthTicketCache(); void add(final String user, final String token); boolean remove(final String user, final String token);  }
@Test(expected = IllegalStateException.class) public void addDoesNotAllowDuplicates() { AuthTicketCache tokens = new AuthTicketCache(); tokens.add("user","foo"); tokens.add("user","foo"); }