36
36
import static org .junit .Assert .assertTrue ;
37
37
import static org .mockito .Matchers .any ;
38
38
import static org .mockito .Matchers .anyBoolean ;
39
+ import static org .mockito .Matchers .anyMapOf ;
39
40
import static org .mockito .Matchers .anyString ;
40
41
import static org .mockito .Matchers .eq ;
41
42
import static org .mockito .Mockito .doReturn ;
44
45
import static org .mockito .Mockito .spy ;
45
46
import static org .mockito .Mockito .times ;
46
47
import static org .mockito .Mockito .verify ;
48
+ import static org .mockito .Mockito .verifyNoMoreInteractions ;
47
49
import static org .mockito .Mockito .when ;
48
50
49
51
// For ParseExecutors.main()
@@ -379,6 +381,39 @@ public void testSignUpAsyncWithNoCurrentUserAndSignUpFailure() throws Exception
379
381
380
382
//region testLogInWithAsync
381
383
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
+
382
417
@ Test
383
418
public void testLoginWithAsyncWithLinkedLazyUser () throws Exception {
384
419
// Register a mock currentUserController to make getCurrentUser work
@@ -391,7 +426,7 @@ public void testLoginWithAsyncWithLinkedLazyUser() throws Exception {
391
426
.when (partialMockCurrentUser )
392
427
.resolveLazinessAsync (Matchers .<Task <Void >>any ());
393
428
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
394
- when (currentUserController .getAsync ()).thenReturn (Task .forResult (partialMockCurrentUser ));
429
+ when (currentUserController .getAsync (false )).thenReturn (Task .forResult (partialMockCurrentUser ));
395
430
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
396
431
397
432
String authType = "facebook" ;
@@ -421,7 +456,7 @@ public void testLoginWithAsyncWithLinkedLazyUseAndResolveLazinessFailure() throw
421
456
.when (partialMockCurrentUser )
422
457
.resolveLazinessAsync (Matchers .<Task <Void >>any ());
423
458
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
424
- when (currentUserController .getAsync ()).thenReturn (Task .forResult (partialMockCurrentUser ));
459
+ when (currentUserController .getAsync (false )).thenReturn (Task .forResult (partialMockCurrentUser ));
425
460
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
426
461
427
462
String authType = "facebook" ;
@@ -495,7 +530,7 @@ public void testLoginWithAsyncWithLinkedNotLazyUserLinkFailure() throws Exceptio
495
530
.when (partialMockCurrentUser )
496
531
.linkWithInBackground (anyString (), Matchers .<Map <String , String >>any ());
497
532
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
498
- when (currentUserController .getAsync ()).thenReturn (Task .forResult (partialMockCurrentUser ));
533
+ when (currentUserController .getAsync (false )).thenReturn (Task .forResult (partialMockCurrentUser ));
499
534
when (currentUserController .setAsync (any (ParseUser .class )))
500
535
.thenReturn (Task .<Void >forResult (null ));
501
536
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
@@ -531,7 +566,7 @@ public void testLoginWithAsyncWithNoCurrentUser() throws Exception {
531
566
ParseCorePlugins .getInstance ().registerUserController (userController );
532
567
// Register a mock currentUserController to make getCurrentUser work
533
568
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
534
- when (currentUserController .getAsync ()).thenReturn (Task .<ParseUser >forResult (null ));
569
+ when (currentUserController .getAsync (false )).thenReturn (Task .<ParseUser >forResult (null ));
535
570
when (currentUserController .setAsync (any (ParseUser .class )))
536
571
.thenReturn (Task .<Void >forResult (null ));
537
572
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
0 commit comments