3636import static org .junit .Assert .assertTrue ;
3737import static org .mockito .Matchers .any ;
3838import static org .mockito .Matchers .anyBoolean ;
39+ import static org .mockito .Matchers .anyMapOf ;
3940import static org .mockito .Matchers .anyString ;
4041import static org .mockito .Matchers .eq ;
4142import static org .mockito .Mockito .doReturn ;
4445import static org .mockito .Mockito .spy ;
4546import static org .mockito .Mockito .times ;
4647import static org .mockito .Mockito .verify ;
48+ import static org .mockito .Mockito .verifyNoMoreInteractions ;
4749import 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