OAuthToken extends AbstractAuthzEntity implements Principal { @Transient @JsonIgnore public boolean isExpired() { if (getCreatedDate() == null) { return true; } Calendar now = Calendar.getInstance(); Calendar expireDate = (Calendar) getCreatedDate().clone(); expireDate.add(Calendar.SECOND, getExpiresIn().intValue()); return now.after(expireDate); }  String getIssuer(); void setIssuer(final String issuer); HttpSession getHttpSession(); void setHttpSession(final HttpSession httpSession); UserIdentity getIdentity(); void setIdentity(final UserIdentity identity); Client getClient(); void setClient(final Client client); OAuthToken getAuthToken(); void setAuthToken(final OAuthToken authToken); OAuthTokenType getTokenType(); void setTokenType(final OAuthTokenType tokenType); Long getExpiresIn(); void setExpiresIn(final int expiresIn); @JsonSetter void setExpiresIn(final long expiresIn); void setExpiresIn(final Number expiresIn); @JsonIgnore SortedMap<String, ApplicationScope> getScopes(); @JsonIgnore void setScopes(final SortedMap<String, ApplicationScope> scopes); @Transient @JsonIgnore boolean isExpired(); URI getRedirect(); void setRedirect(final URI redirect); @Override @Transient @JsonIgnore String getName(); @Override @Transient @JsonIgnore User getOwner();  }
@Test public void testIsExpired() { OAuthToken token = new OAuthToken(); TimeZone utc = TimeZone.getTimeZone("UTC"); TimeZone pdt = TimeZone.getTimeZone("PDT"); Calendar recentUTC = Calendar.getInstance(utc); recentUTC.add(Calendar.SECOND, -100); Calendar recentPDT = Calendar.getInstance(pdt); recentPDT.add(Calendar.SECOND, -100); assertTrue(token.isExpired()); token.setCreatedDate(recentUTC); token.setExpiresIn((long) 103); assertFalse(token.isExpired()); token.setExpiresIn((long) 99); assertTrue(token.isExpired()); token.setCreatedDate(recentPDT); token.setExpiresIn((long) 103); assertFalse(token.isExpired()); token.setExpiresIn((long) 99); assertTrue(token.isExpired()); }