@Test public void testSetNewAccessToken() throws Exception { credentialStore.authenticate(accessToken, refreshToken, expiresIn, new Date(1000)); credentialStore.setNewAccessToken(accessToken, expiresIn); assertEquals(credentialStore.getAuthStatus(), CredentialStore.AUTHENTICATED); assertTrue(credentialStore.getTokenAcquisitionTime().getTime() != new Date(1000).getTime()); try { credentialStore.setNewAccessToken("", expiresIn); assertTrue(false); } catch (Exception ignored) { } }
synchronized void setNewAccessToken(@NonNull String accessToken, int expiresIn) { if(accessToken.length() == 0) throw new IllegalArgumentException("accessToken.isEmpty()"); this.accessToken = accessToken; this.expiresIn = expiresIn; this.tokenAcquisitionTime = new Date(); authStatus = AUTHENTICATED; persister.persistUser(this); }
CredentialStore { synchronized void setNewAccessToken(@NonNull String accessToken, int expiresIn) { if(accessToken.length() == 0) throw new IllegalArgumentException("accessToken.isEmpty()"); this.accessToken = accessToken; this.expiresIn = expiresIn; this.tokenAcquisitionTime = new Date(); authStatus = AUTHENTICATED; persister.persistUser(this); } }
CredentialStore { synchronized void setNewAccessToken(@NonNull String accessToken, int expiresIn) { if(accessToken.length() == 0) throw new IllegalArgumentException("accessToken.isEmpty()"); this.accessToken = accessToken; this.expiresIn = expiresIn; this.tokenAcquisitionTime = new Date(); authStatus = AUTHENTICATED; persister.persistUser(this); } CredentialStore(CredentialPersister persister); }
CredentialStore { synchronized void setNewAccessToken(@NonNull String accessToken, int expiresIn) { if(accessToken.length() == 0) throw new IllegalArgumentException("accessToken.isEmpty()"); this.accessToken = accessToken; this.expiresIn = expiresIn; this.tokenAcquisitionTime = new Date(); authStatus = AUTHENTICATED; persister.persistUser(this); } 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 void setNewAccessToken(@NonNull String accessToken, int expiresIn) { if(accessToken.length() == 0) throw new IllegalArgumentException("accessToken.isEmpty()"); this.accessToken = accessToken; this.expiresIn = expiresIn; this.tokenAcquisitionTime = new Date(); authStatus = AUTHENTICATED; persister.persistUser(this); } 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; }