### Question:
TokenIdFactory implements TokenIdGenerator { @Override public String generateTokenId(String existingId) { if (existingId != null){ return existingId; } return UUID.randomUUID().toString(); } @Inject  TokenIdFactory(KeyConversion encoding); String toSAMLPrimaryTokenId(String requestId); String fromSAMLPrimaryTokenId(String primaryId); String toSAMLSecondaryTokenId(String secondaryKey); String fromSAMLSecondaryTokenId(String secondaryId); String toSessionTokenId(InternalSession session); String toSessionTokenId(SessionID sessionID); @Override String generateTokenId(String existingId); static final String ID; }### Answer:
@Test public void shouldGetOAuthTokenIdWhenSet() { String key = "badger"; String result = factory.generateTokenId(key); assertEquals(result, key); }
@Test public void shouldGenerateRandomIdWhenOAuthTokenIdNotSet() { String result = factory.generateTokenId(null); assertNotNull(result); }