Skip to content

Commit 67b6d53

Browse files
committed
Merge pull request #317 from ParsePlatform/grantland.lazy
Simplify authenticating w/ third party & automatic users
2 parents 1e1f146 + 7d908f3 commit 67b6d53

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

Parse/src/main/java/com/parse/ParseUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ public ParseUser then(Task<Void> task) throws Exception {
11271127
};
11281128

11291129
// Handle claiming of user.
1130-
return getCurrentUserAsync().onSuccessTask(new Continuation<ParseUser, Task<ParseUser>>() {
1130+
return getCurrentUserController().getAsync(false).onSuccessTask(new Continuation<ParseUser, Task<ParseUser>>() {
11311131
@Override
11321132
public Task<ParseUser> then(Task<ParseUser> task) throws Exception {
11331133
final ParseUser user = task.getResult();

Parse/src/test/java/com/parse/ParseUserTest.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.junit.Assert.assertTrue;
3737
import static org.mockito.Matchers.any;
3838
import static org.mockito.Matchers.anyBoolean;
39+
import static org.mockito.Matchers.anyMapOf;
3940
import static org.mockito.Matchers.anyString;
4041
import static org.mockito.Matchers.eq;
4142
import static org.mockito.Mockito.doReturn;
@@ -44,6 +45,7 @@
4445
import static org.mockito.Mockito.spy;
4546
import static org.mockito.Mockito.times;
4647
import static org.mockito.Mockito.verify;
48+
import static org.mockito.Mockito.verifyNoMoreInteractions;
4749
import static org.mockito.Mockito.when;
4850

4951
// For ParseExecutors.main()
@@ -379,6 +381,39 @@ public void testSignUpAsyncWithNoCurrentUserAndSignUpFailure() throws Exception
379381

380382
//region testLogInWithAsync
381383

384+
@Test
385+
public void testLoginWithAsyncWithoutExistingLazyUser() throws ParseException {
386+
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
387+
when(currentUserController.getAsync(false)).thenReturn(Task.<ParseUser>forResult(null));
388+
when(currentUserController.setAsync(any(ParseUser.class)))
389+
.thenReturn(Task.<Void>forResult(null));
390+
391+
ParseUser.State userState = mock(ParseUser.State.class);
392+
when(userState.className()).thenReturn("_User");
393+
when(userState.objectId()).thenReturn("1234");
394+
when(userState.isComplete()).thenReturn(true);
395+
396+
ParseUserController userController = mock(ParseUserController.class);
397+
when(userController.logInAsync(anyString(), anyMapOf(String.class, String.class)))
398+
.thenReturn(Task.forResult(userState));
399+
400+
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
401+
ParseCorePlugins.getInstance().registerUserController(userController);
402+
403+
String authType = "facebook";
404+
Map<String, String> authData = new HashMap<>();
405+
authData.put("token", "123");
406+
ParseUser user = ParseTaskUtils.wait(ParseUser.logInWithInBackground(authType, authData));
407+
408+
verify(currentUserController).getAsync(false);
409+
verify(userController).logInAsync(authType, authData);
410+
verify(currentUserController).setAsync(user);
411+
assertSame(userState, user.getState());
412+
413+
verifyNoMoreInteractions(currentUserController);
414+
verifyNoMoreInteractions(userController);
415+
}
416+
382417
@Test
383418
public void testLoginWithAsyncWithLinkedLazyUser() throws Exception {
384419
// Register a mock currentUserController to make getCurrentUser work
@@ -391,7 +426,7 @@ public void testLoginWithAsyncWithLinkedLazyUser() throws Exception {
391426
.when(partialMockCurrentUser)
392427
.resolveLazinessAsync(Matchers.<Task<Void>>any());
393428
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
394-
when(currentUserController.getAsync()).thenReturn(Task.forResult(partialMockCurrentUser));
429+
when(currentUserController.getAsync(false)).thenReturn(Task.forResult(partialMockCurrentUser));
395430
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
396431

397432
String authType = "facebook";
@@ -421,7 +456,7 @@ public void testLoginWithAsyncWithLinkedLazyUseAndResolveLazinessFailure() throw
421456
.when(partialMockCurrentUser)
422457
.resolveLazinessAsync(Matchers.<Task<Void>>any());
423458
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
424-
when(currentUserController.getAsync()).thenReturn(Task.forResult(partialMockCurrentUser));
459+
when(currentUserController.getAsync(false)).thenReturn(Task.forResult(partialMockCurrentUser));
425460
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
426461

427462
String authType = "facebook";
@@ -495,7 +530,7 @@ public void testLoginWithAsyncWithLinkedNotLazyUserLinkFailure() throws Exceptio
495530
.when(partialMockCurrentUser)
496531
.linkWithInBackground(anyString(), Matchers.<Map<String, String>>any());
497532
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
498-
when(currentUserController.getAsync()).thenReturn(Task.forResult(partialMockCurrentUser));
533+
when(currentUserController.getAsync(false)).thenReturn(Task.forResult(partialMockCurrentUser));
499534
when(currentUserController.setAsync(any(ParseUser.class)))
500535
.thenReturn(Task.<Void>forResult(null));
501536
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
@@ -531,7 +566,7 @@ public void testLoginWithAsyncWithNoCurrentUser() throws Exception {
531566
ParseCorePlugins.getInstance().registerUserController(userController);
532567
// Register a mock currentUserController to make getCurrentUser work
533568
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
534-
when(currentUserController.getAsync()).thenReturn(Task.<ParseUser>forResult(null));
569+
when(currentUserController.getAsync(false)).thenReturn(Task.<ParseUser>forResult(null));
535570
when(currentUserController.setAsync(any(ParseUser.class)))
536571
.thenReturn(Task.<Void>forResult(null));
537572
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);

0 commit comments

Comments
 (0)