@Test public void testGetAuthStatus() throws Exception { credentialStore.init(accessToken, refreshToken, expiresIn, acquisitionTime, CredentialStore.AUTHENTICATED); assertEquals(credentialStore.getAuthStatus(), CredentialStore.AUTHENTICATED); credentialStore.init(accessToken, refreshToken, 0, acquisitionTime, CredentialStore.NOT_AUTHENTICATED); assertEquals(credentialStore.getAuthStatus(), CredentialStore.NOT_AUTHENTICATED); credentialStore.init(accessToken, refreshToken, 0, acquisitionTime, CredentialStore.AUTHENTICATED); assertEquals(credentialStore.getAuthStatus(), CredentialStore.TOKEN_EXPIRED); credentialStore.init(accessToken, refreshToken, 601, acquisitionTime, CredentialStore.AUTHENTICATED); assertEquals(credentialStore.getAuthStatus(), CredentialStore.AUTHENTICATED); credentialStore.init(accessToken, refreshToken, 500, acquisitionTime, CredentialStore.AUTHENTICATED); assertEquals(credentialStore.getAuthStatus(), CredentialStore.TOKEN_EXPIRED); assertNull(credentialStore.getAccessToken()); assertTrue(credentialStore.getExpiresIn() < 0); assertNull(credentialStore.getTokenAcquisitionTime()); assertNotNull(credentialStore.getRefreshToken()); }
synchronized @AuthStatus int getAuthStatus() { if(authStatus == NOT_AUTHENTICATED) return authStatus; long currentTimeMillisec = new Date().getTime() / 1000; long tokenAcquisitionTimeMillisec = this.tokenAcquisitionTime.getTime() / 1000; int offsetMillisec = 600; if(currentTimeMillisec - tokenAcquisitionTimeMillisec >= expiresIn - offsetMillisec) authStatus = TOKEN_EXPIRED; return authStatus; }
CredentialStore { synchronized @AuthStatus int getAuthStatus() { if(authStatus == NOT_AUTHENTICATED) return authStatus; long currentTimeMillisec = new Date().getTime() / 1000; long tokenAcquisitionTimeMillisec = this.tokenAcquisitionTime.getTime() / 1000; int offsetMillisec = 600; if(currentTimeMillisec - tokenAcquisitionTimeMillisec >= expiresIn - offsetMillisec) authStatus = TOKEN_EXPIRED; return authStatus; } }
CredentialStore { synchronized @AuthStatus int getAuthStatus() { if(authStatus == NOT_AUTHENTICATED) return authStatus; long currentTimeMillisec = new Date().getTime() / 1000; long tokenAcquisitionTimeMillisec = this.tokenAcquisitionTime.getTime() / 1000; int offsetMillisec = 600; if(currentTimeMillisec - tokenAcquisitionTimeMillisec >= expiresIn - offsetMillisec) authStatus = TOKEN_EXPIRED; return authStatus; } CredentialStore(CredentialPersister persister); }
CredentialStore { synchronized @AuthStatus int getAuthStatus() { if(authStatus == NOT_AUTHENTICATED) return authStatus; long currentTimeMillisec = new Date().getTime() / 1000; long tokenAcquisitionTimeMillisec = this.tokenAcquisitionTime.getTime() / 1000; int offsetMillisec = 600; if(currentTimeMillisec - tokenAcquisitionTimeMillisec >= expiresIn - offsetMillisec) authStatus = TOKEN_EXPIRED; return authStatus; } CredentialStore(CredentialPersister persister); void init(String accessToken, String refreshToken, int expiresIn, Date tokenAcquisitionTime, @AuthStatus int authStatus); String getAccessToken(); String getRefreshToken(); int getExpiresIn(); Date getTokenAcquisitionTime(); }
CredentialStore { synchronized @AuthStatus int getAuthStatus() { if(authStatus == NOT_AUTHENTICATED) return authStatus; long currentTimeMillisec = new Date().getTime() / 1000; long tokenAcquisitionTimeMillisec = this.tokenAcquisitionTime.getTime() / 1000; int offsetMillisec = 600; if(currentTimeMillisec - tokenAcquisitionTimeMillisec >= expiresIn - offsetMillisec) authStatus = TOKEN_EXPIRED; return authStatus; } CredentialStore(CredentialPersister persister); void init(String accessToken, String refreshToken, int expiresIn, Date tokenAcquisitionTime, @AuthStatus int authStatus); String getAccessToken(); String getRefreshToken(); int getExpiresIn(); Date getTokenAcquisitionTime(); final static int NOT_AUTHENTICATED; final static int TOKEN_EXPIRED; final static int AUTHENTICATED; }