@Test public void testSetAuthDataWithSameAccessToken() throws ParseException { FacebookController.FacebookSdkDelegate facebookSdk = mock(FacebookController.FacebookSdkDelegate.class); AccessToken accessToken = TestUtils.newAccessToken(); when(facebookSdk.getCurrentAccessToken()).thenReturn(accessToken); FacebookController controller = new FacebookController(facebookSdk); Map<String, String> authData = new HashMap<>(); authData.put("id", "test_id"); authData.put("access_token", "test_token"); authData.put("expiration_date", "2015-07-03T07:00:00.000Z"); authData.put("last_refresh_date", "2015-07-03T07:00:00.000Z"); controller.setAuthData(authData); verify(facebookSdk, never()).setCurrentAccessToken(any(AccessToken.class)); }
public void setAuthData(Map<String, String> authData) throws java.text.ParseException { if (authData == null) { facebookSdkDelegate.getLoginManager().logOut(); return; } String token = authData.get(KEY_ACCESS_TOKEN); String userId = authData.get(KEY_USER_ID); String lastRefreshDateString = authData.get(KEY_REFRESH_DATE); Date lastRefreshDate = null; if (lastRefreshDateString != null) { lastRefreshDate = parseDateString(lastRefreshDateString); } AccessToken currentAccessToken = facebookSdkDelegate.getCurrentAccessToken(); if (currentAccessToken != null) { String currToken = currentAccessToken.getToken(); String currUserId = currentAccessToken.getUserId(); Date currLastRefreshDate = currentAccessToken.getLastRefresh(); if (currToken != null && currToken.equals(token) && currUserId != null && currUserId.equals(userId)) { return; } if (currLastRefreshDate != null && lastRefreshDate != null && currLastRefreshDate.after(lastRefreshDate)) { return; } } String permissionsCommaDelineated = authData.get(KEY_PERMISSIONS); Set<String> permissions = null; if (permissionsCommaDelineated != null && !permissionsCommaDelineated.isEmpty()) { String permissionsArray[] = permissionsCommaDelineated.split(","); permissions = new HashSet<>(Arrays.asList(permissionsArray)); } AccessToken accessToken = new AccessToken( token, facebookSdkDelegate.getApplicationId(), userId, permissions, null, null, AccessTokenSource.DEVICE_AUTH, parseDateString(authData.get(KEY_EXPIRATION_DATE)), null, null); facebookSdkDelegate.setCurrentAccessToken(accessToken); }
FacebookController { public void setAuthData(Map<String, String> authData) throws java.text.ParseException { if (authData == null) { facebookSdkDelegate.getLoginManager().logOut(); return; } String token = authData.get(KEY_ACCESS_TOKEN); String userId = authData.get(KEY_USER_ID); String lastRefreshDateString = authData.get(KEY_REFRESH_DATE); Date lastRefreshDate = null; if (lastRefreshDateString != null) { lastRefreshDate = parseDateString(lastRefreshDateString); } AccessToken currentAccessToken = facebookSdkDelegate.getCurrentAccessToken(); if (currentAccessToken != null) { String currToken = currentAccessToken.getToken(); String currUserId = currentAccessToken.getUserId(); Date currLastRefreshDate = currentAccessToken.getLastRefresh(); if (currToken != null && currToken.equals(token) && currUserId != null && currUserId.equals(userId)) { return; } if (currLastRefreshDate != null && lastRefreshDate != null && currLastRefreshDate.after(lastRefreshDate)) { return; } } String permissionsCommaDelineated = authData.get(KEY_PERMISSIONS); Set<String> permissions = null; if (permissionsCommaDelineated != null && !permissionsCommaDelineated.isEmpty()) { String permissionsArray[] = permissionsCommaDelineated.split(","); permissions = new HashSet<>(Arrays.asList(permissionsArray)); } AccessToken accessToken = new AccessToken( token, facebookSdkDelegate.getApplicationId(), userId, permissions, null, null, AccessTokenSource.DEVICE_AUTH, parseDateString(authData.get(KEY_EXPIRATION_DATE)), null, null); facebookSdkDelegate.setCurrentAccessToken(accessToken); } }
FacebookController { public void setAuthData(Map<String, String> authData) throws java.text.ParseException { if (authData == null) { facebookSdkDelegate.getLoginManager().logOut(); return; } String token = authData.get(KEY_ACCESS_TOKEN); String userId = authData.get(KEY_USER_ID); String lastRefreshDateString = authData.get(KEY_REFRESH_DATE); Date lastRefreshDate = null; if (lastRefreshDateString != null) { lastRefreshDate = parseDateString(lastRefreshDateString); } AccessToken currentAccessToken = facebookSdkDelegate.getCurrentAccessToken(); if (currentAccessToken != null) { String currToken = currentAccessToken.getToken(); String currUserId = currentAccessToken.getUserId(); Date currLastRefreshDate = currentAccessToken.getLastRefresh(); if (currToken != null && currToken.equals(token) && currUserId != null && currUserId.equals(userId)) { return; } if (currLastRefreshDate != null && lastRefreshDate != null && currLastRefreshDate.after(lastRefreshDate)) { return; } } String permissionsCommaDelineated = authData.get(KEY_PERMISSIONS); Set<String> permissions = null; if (permissionsCommaDelineated != null && !permissionsCommaDelineated.isEmpty()) { String permissionsArray[] = permissionsCommaDelineated.split(","); permissions = new HashSet<>(Arrays.asList(permissionsArray)); } AccessToken accessToken = new AccessToken( token, facebookSdkDelegate.getApplicationId(), userId, permissions, null, null, AccessTokenSource.DEVICE_AUTH, parseDateString(authData.get(KEY_EXPIRATION_DATE)), null, null); facebookSdkDelegate.setCurrentAccessToken(accessToken); } FacebookController(FacebookSdkDelegate facebookSdkDelegate);   FacebookController(); }
FacebookController { public void setAuthData(Map<String, String> authData) throws java.text.ParseException { if (authData == null) { facebookSdkDelegate.getLoginManager().logOut(); return; } String token = authData.get(KEY_ACCESS_TOKEN); String userId = authData.get(KEY_USER_ID); String lastRefreshDateString = authData.get(KEY_REFRESH_DATE); Date lastRefreshDate = null; if (lastRefreshDateString != null) { lastRefreshDate = parseDateString(lastRefreshDateString); } AccessToken currentAccessToken = facebookSdkDelegate.getCurrentAccessToken(); if (currentAccessToken != null) { String currToken = currentAccessToken.getToken(); String currUserId = currentAccessToken.getUserId(); Date currLastRefreshDate = currentAccessToken.getLastRefresh(); if (currToken != null && currToken.equals(token) && currUserId != null && currUserId.equals(userId)) { return; } if (currLastRefreshDate != null && lastRefreshDate != null && currLastRefreshDate.after(lastRefreshDate)) { return; } } String permissionsCommaDelineated = authData.get(KEY_PERMISSIONS); Set<String> permissions = null; if (permissionsCommaDelineated != null && !permissionsCommaDelineated.isEmpty()) { String permissionsArray[] = permissionsCommaDelineated.split(","); permissions = new HashSet<>(Arrays.asList(permissionsArray)); } AccessToken accessToken = new AccessToken( token, facebookSdkDelegate.getApplicationId(), userId, permissions, null, null, AccessTokenSource.DEVICE_AUTH, parseDateString(authData.get(KEY_EXPIRATION_DATE)), null, null); facebookSdkDelegate.setCurrentAccessToken(accessToken); } FacebookController(FacebookSdkDelegate facebookSdkDelegate);   FacebookController(); void initialize(Context context, int callbackRequestCodeOffset); boolean onActivityResult(int requestCode, int resultCode, Intent data); Task<Map<String, String>> authenticateAsync(
            Activity activity,
            Fragment fragment,
            LoginAuthorizationType authorizationType,
            Collection<String> permissions); Map<String, String> getAuthData(AccessToken accessToken); void setAuthData(Map<String, String> authData); }
FacebookController { public void setAuthData(Map<String, String> authData) throws java.text.ParseException { if (authData == null) { facebookSdkDelegate.getLoginManager().logOut(); return; } String token = authData.get(KEY_ACCESS_TOKEN); String userId = authData.get(KEY_USER_ID); String lastRefreshDateString = authData.get(KEY_REFRESH_DATE); Date lastRefreshDate = null; if (lastRefreshDateString != null) { lastRefreshDate = parseDateString(lastRefreshDateString); } AccessToken currentAccessToken = facebookSdkDelegate.getCurrentAccessToken(); if (currentAccessToken != null) { String currToken = currentAccessToken.getToken(); String currUserId = currentAccessToken.getUserId(); Date currLastRefreshDate = currentAccessToken.getLastRefresh(); if (currToken != null && currToken.equals(token) && currUserId != null && currUserId.equals(userId)) { return; } if (currLastRefreshDate != null && lastRefreshDate != null && currLastRefreshDate.after(lastRefreshDate)) { return; } } String permissionsCommaDelineated = authData.get(KEY_PERMISSIONS); Set<String> permissions = null; if (permissionsCommaDelineated != null && !permissionsCommaDelineated.isEmpty()) { String permissionsArray[] = permissionsCommaDelineated.split(","); permissions = new HashSet<>(Arrays.asList(permissionsArray)); } AccessToken accessToken = new AccessToken( token, facebookSdkDelegate.getApplicationId(), userId, permissions, null, null, AccessTokenSource.DEVICE_AUTH, parseDateString(authData.get(KEY_EXPIRATION_DATE)), null, null); facebookSdkDelegate.setCurrentAccessToken(accessToken); } FacebookController(FacebookSdkDelegate facebookSdkDelegate);   FacebookController(); void initialize(Context context, int callbackRequestCodeOffset); boolean onActivityResult(int requestCode, int resultCode, Intent data); Task<Map<String, String>> authenticateAsync(
            Activity activity,
            Fragment fragment,
            LoginAuthorizationType authorizationType,
            Collection<String> permissions); Map<String, String> getAuthData(AccessToken accessToken); void setAuthData(Map<String, String> authData); static final int DEFAULT_AUTH_ACTIVITY_CODE; }