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());
  }
  public void testDateTimeFormatterLocaleChange()
      throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
          InvalidKeySpecException, KeyStoreException, CertificateException, NoSuchProviderException,
          InvalidAlgorithmParameterException, UnrecoverableEntryException, DigestException,
          IllegalBlockSizeException, BadPaddingException, IOException, NameNotFoundException,
          NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    DefaultTokenCacheStore store = (DefaultTokenCacheStore) setupItems();
    ArrayList<TokenCacheItem> tokens = store.getTokensForResource("resource");
    // Serializing without miliseconds
    long precision = 1000;
    TokenCacheItem item = tokens.get(0);
    String cacheKey = CacheKey.createCacheKey(item);
    Calendar time = Calendar.getInstance();
    Date dateTimeNow = time.getTime();
    long timeNowMiliSeconds = dateTimeNow.getTime();
    item.setExpiresOn(dateTimeNow);
    store.setItem(cacheKey, item);
    TokenCacheItem fromCache = store.getItem(cacheKey);
    assertTrue(Math.abs(timeNowMiliSeconds - fromCache.getExpiresOn().getTime()) < precision);

    // Parse for different settings
    Locale.setDefault(Locale.FRANCE);
    fromCache = store.getItem(cacheKey);
    assertTrue(Math.abs(timeNowMiliSeconds - fromCache.getExpiresOn().getTime()) < precision);

    Locale.setDefault(Locale.US);
    fromCache = store.getItem(cacheKey);
    assertTrue(Math.abs(timeNowMiliSeconds - fromCache.getExpiresOn().getTime()) < precision);

    TimeZone.setDefault(TimeZone.getTimeZone("GMT+03:00"));
    fromCache = store.getItem(cacheKey);
    assertTrue(Math.abs(timeNowMiliSeconds - fromCache.getExpiresOn().getTime()) < precision);

    TimeZone.setDefault(TimeZone.getTimeZone("GMT+05:00"));
    fromCache = store.getItem(cacheKey);
    assertTrue(Math.abs(timeNowMiliSeconds - fromCache.getExpiresOn().getTime()) < precision);
  }