### Question:
AuthorizationServer { public AccessToken isValidToken(String token) { AccessToken accessToken = db.findAccessToken(token); if (accessToken != null && accessToken.isValid()) { if (accessToken.tokenExpired()) { db.updateAccessTokenValidStatus(accessToken.getToken(), false); return null; } return accessToken; } return null; }  ClientCredentials issueClientCredentials(HttpRequest req); String issueAuthorizationCode(HttpRequest req); AccessToken issueAccessToken(HttpRequest req); static String [] getBasicAuthorizationClientCredentials(HttpRequest req); AccessToken isValidToken(String token); ApplicationInfo getApplicationInfo(String clientId); boolean revokeUserAccessTokens(HttpRequest req); boolean revokeToken(HttpRequest req); boolean updateClientApp(HttpRequest req, String clientId);  }### Answer:
@Test public void when_expired_token_update_valid_to_false() throws Exception { String token = "a9855207b560ac824dfb84f4d235243afdccfacaa3a32c66baeeec06eb0afa9c"; AccessToken accessToken = mock(AccessToken.class); given(accessToken.getToken()).willReturn(token); given(accessToken.isValid()).willReturn(true); given(authServer.db.findAccessToken(accessToken.getToken())).willReturn(accessToken); given(accessToken.tokenExpired()).willReturn(true); AccessToken result = authServer.isValidToken(token); verify(authServer.db).updateAccessTokenValidStatus(accessToken.getToken(), false); assertNull(result); }
@Test public void when_valid_token_return_access_token() throws Exception { String token = "a9855207b560ac824dfb84f4d235243afdccfacaa3a32c66baeeec06eb0afa9c"; AccessToken accessToken = mock(AccessToken.class); given(accessToken.getToken()).willReturn(token); given(accessToken.isValid()).willReturn(true); given(authServer.db.findAccessToken(accessToken.getToken())).willReturn(accessToken); AccessToken result = authServer.isValidToken(token); assertEquals(result, accessToken); }
@Test public void when_invalid_token_found_return_null() throws Exception { String token = "a9855207b560ac824dfb84f4d235243afdccfacaa3a32c66baeeec06eb0afa9c"; AccessToken accessToken = mock(AccessToken.class); willReturn(false).given(accessToken).isValid(); given(accessToken.getToken()).willReturn(token); given(authServer.db.findAccessToken(accessToken.getToken())).willReturn(accessToken); AccessToken result = authServer.isValidToken(token); assertNull(result); }
@Test public void when_not_valid_token_return_null() throws Exception { String token = "a9855207b560ac824dfb84f4d235243afdccfacaa3a32c66baeeec06eb0afa9c"; AccessToken result = authServer.isValidToken(token); assertNull(result); }