public void testGetTokensForUser() throws NoSuchAlgorithmException, NoSuchPaddingException {
    DefaultTokenCacheStore store = (DefaultTokenCacheStore) setupItems();

    ArrayList<TokenCacheItem> tokens = store.getTokensForUser("userid1");
    assertEquals("token size", 2, tokens.size());

    tokens = store.getTokensForUser("userid2");
    assertEquals("token size", 2, tokens.size());
  }
  public void testExpireBuffer() throws NoSuchAlgorithmException, NoSuchPaddingException {
    DefaultTokenCacheStore store = (DefaultTokenCacheStore) setupItems();

    ArrayList<TokenCacheItem> tokens = store.getTokensForUser("userid1");
    Calendar expireTime = Calendar.getInstance();
    Logger.d(TAG, "Time now: " + expireTime.getTime());
    expireTime.add(Calendar.SECOND, 240);
    Logger.d(TAG, "Time modified: " + expireTime.getTime());

    // Sets token to expire if less than this buffer
    AuthenticationSettings.INSTANCE.setExpirationBuffer(300);
    for (TokenCacheItem item : tokens) {
      item.setExpiresOn(expireTime.getTime());
      assertTrue("Should say expired", TokenCacheItem.isTokenExpired(item.getExpiresOn()));
    }

    // Set expire time ahead of buffer 240 +100 secs more than 300secs
    // buffer
    expireTime.add(Calendar.SECOND, 100);
    for (TokenCacheItem item : tokens) {
      item.setExpiresOn(expireTime.getTime());
      assertFalse(
          "Should not say expired since time is more than buffer",
          TokenCacheItem.isTokenExpired(item.getExpiresOn()));
    }
  }
  public void testExpiringTokens() throws NoSuchAlgorithmException, NoSuchPaddingException {
    DefaultTokenCacheStore store = (DefaultTokenCacheStore) setupItems();

    ArrayList<TokenCacheItem> tokens = store.getTokensForUser("userid1");
    ArrayList<TokenCacheItem> expireTokenList = store.getTokensAboutToExpire();
    assertEquals("token size", 0, expireTokenList.size());
    assertEquals("token size", 2, tokens.size());

    TokenCacheItem expire = tokens.get(0);

    Calendar timeAhead = Calendar.getInstance();
    timeAhead.add(Calendar.MINUTE, -10);
    expire.setExpiresOn(timeAhead.getTime());

    store.setItem(CacheKey.createCacheKey(expire), expire);

    expireTokenList = store.getTokensAboutToExpire();
    assertEquals("token size", 1, expireTokenList.size());
  }