15
15
import org .junit .Test ;
16
16
import org .junit .rules .ExpectedException ;
17
17
import org .junit .runner .RunWith ;
18
+ import org .mockito .Matchers ;
18
19
import org .robolectric .RobolectricGradleTestRunner ;
19
20
import org .robolectric .annotation .Config ;
20
21
21
- import java .util .Arrays ;
22
+ import java .util .Collections ;
22
23
import java .util .HashMap ;
23
24
import java .util .Map ;
24
25
import java .util .concurrent .Semaphore ;
34
35
import static org .junit .Assert .assertTrue ;
35
36
import static org .mockito .Matchers .any ;
36
37
import static org .mockito .Matchers .anyBoolean ;
37
- import static org .mockito .Matchers .anyMap ;
38
38
import static org .mockito .Matchers .anyString ;
39
39
import static org .mockito .Matchers .eq ;
40
40
import static org .mockito .Mockito .doReturn ;
@@ -86,7 +86,7 @@ public void testImmutableKeys() {
86
86
}
87
87
88
88
try {
89
- user .removeAll ("sessionToken" , Arrays . asList ());
89
+ user .removeAll ("sessionToken" , Collections . emptyList ());
90
90
} catch (IllegalArgumentException e ) {
91
91
assertTrue (e .getMessage ().contains ("Cannot modify" ));
92
92
}
@@ -165,12 +165,12 @@ public void testSignUpAsyncWithObjectIdSetAndAuthDataSet() throws Exception {
165
165
ParseUser partialMockUser = spy (user );
166
166
doReturn (Task .<Void >forResult (null ))
167
167
.when (partialMockUser )
168
- .saveAsync (anyString (), any (Task . class ));
168
+ .saveAsync (anyString (), Matchers .< Task < Void >> any ());
169
169
170
170
ParseTaskUtils .wait (partialMockUser .signUpAsync (Task .<Void >forResult (null )));
171
171
172
172
// Verify user is saved
173
- verify (partialMockUser , times (1 )).saveAsync (eq ("sessionToken" ), any (Task . class ));
173
+ verify (partialMockUser , times (1 )).saveAsync (eq ("sessionToken" ), Matchers .< Task < Void >> any ());
174
174
}
175
175
176
176
@ Test
@@ -220,7 +220,7 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUser() throws Exception {
220
220
when (currentUser .isLinked (ParseAnonymousUtils .AUTH_TYPE )).thenReturn (true );
221
221
when (currentUser .getSessionToken ()).thenReturn ("oldSessionToken" );
222
222
when (currentUser .getAuthData ()).thenReturn (new HashMap <String , Map <String , String >>());
223
- when (currentUser .saveAsync (anyString (), any (Task . class )))
223
+ when (currentUser .saveAsync (anyString (), Matchers .< Task < Void >> any ()))
224
224
.thenReturn (Task .<Void >forResult (null ));
225
225
ParseUser .State state = new ParseUser .State .Builder ()
226
226
.put ("oldKey" , "oldValue" )
@@ -248,7 +248,7 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUser() throws Exception {
248
248
verify (currentUser , times (1 )).setUsername ("userName" );
249
249
verify (currentUser , times (1 )).setPassword ("password" );
250
250
// Make sure we save currentUser
251
- verify (currentUser , times (1 )).saveAsync (eq ("oldSessionToken" ), any (Task . class ));
251
+ verify (currentUser , times (1 )).saveAsync (eq ("oldSessionToken" ), Matchers .< Task < Void >> any ());
252
252
// Make sure we merge currentUser with user after save
253
253
assertEquals ("oldValue" , user .get ("oldKey" ));
254
254
// Make sure set currentUser
@@ -269,7 +269,7 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUserSaveFailure() throws Exce
269
269
ParseException saveException = new ParseException (ParseException .OTHER_CAUSE , "" );
270
270
doReturn (Task .<Void >forError (saveException ))
271
271
.when (partialMockCurrentUser )
272
- .saveAsync (anyString (), any (Task . class ));
272
+ .saveAsync (anyString (), Matchers .< Task < Void >> any ());
273
273
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
274
274
when (currentUserController .getAsync (anyBoolean ()))
275
275
.thenReturn (Task .forResult (partialMockCurrentUser ));
@@ -293,7 +293,8 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUserSaveFailure() throws Exce
293
293
// Make sure we sync user with currentUser
294
294
verify (partialMockCurrentUser , times (1 )).copyChangesFrom (eq (user ));
295
295
// Make sure we save currentUser
296
- verify (partialMockCurrentUser , times (1 )).saveAsync (eq ("oldSessionToken" ), any (Task .class ));
296
+ verify (partialMockCurrentUser , times (1 ))
297
+ .saveAsync (eq ("oldSessionToken" ), Matchers .<Task <Void >>any ());
297
298
// Make sure we restore old username and password after save fails
298
299
verify (partialMockCurrentUser , times (1 )).setUsername ("oldUserName" );
299
300
verify (partialMockCurrentUser , times (1 )).setPassword ("oldPassword" );
@@ -388,23 +389,22 @@ public void testLoginWithAsyncWithLinkedLazyUser() throws Exception {
388
389
when (partialMockCurrentUser .getSessionToken ()).thenReturn ("oldSessionToken" );
389
390
doReturn (Task .<ParseUser >forResult (null ))
390
391
.when (partialMockCurrentUser )
391
- .resolveLazinessAsync (any (Task . class ));
392
+ .resolveLazinessAsync (Matchers .< Task < Void >> any ());
392
393
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
393
394
when (currentUserController .getAsync ()).thenReturn (Task .forResult (partialMockCurrentUser ));
394
395
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
395
396
396
- ParseUser user = new ParseUser ();
397
397
String authType = "facebook" ;
398
398
Map <String , String > authData = new HashMap <>();
399
399
authData .put ("token" , "123" );
400
- ParseUser userAfterLogin = ParseTaskUtils .wait (user .logInWithAsync (authType , authData ));
400
+ ParseUser userAfterLogin = ParseTaskUtils .wait (ParseUser .logInWithAsync (authType , authData ));
401
401
402
402
// Make sure we stripAnonymity
403
403
assertNull (userAfterLogin .getAuthData ().get (ParseAnonymousUtils .AUTH_TYPE ));
404
404
// Make sure we update authData
405
405
assertEquals (authData , userAfterLogin .getAuthData ().get ("facebook" ));
406
406
// Make sure we resolveLaziness
407
- verify (partialMockCurrentUser , times (1 )).resolveLazinessAsync (any (Task . class ));
407
+ verify (partialMockCurrentUser , times (1 )).resolveLazinessAsync (Matchers .< Task < Void >> any ());
408
408
}
409
409
410
410
@ Test
@@ -418,21 +418,20 @@ public void testLoginWithAsyncWithLinkedLazyUseAndResolveLazinessFailure() throw
418
418
when (partialMockCurrentUser .getSessionToken ()).thenReturn ("oldSessionToken" );
419
419
doReturn (Task .<ParseUser >forError (new Exception ()))
420
420
.when (partialMockCurrentUser )
421
- .resolveLazinessAsync (any (Task . class ));
421
+ .resolveLazinessAsync (Matchers .< Task < Void >> any ());
422
422
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
423
423
when (currentUserController .getAsync ()).thenReturn (Task .forResult (partialMockCurrentUser ));
424
424
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
425
425
426
- ParseUser user = new ParseUser ();
427
426
String authType = "facebook" ;
428
427
Map <String , String > authData = new HashMap <>();
429
428
authData .put ("token" , "123" );
430
429
431
- Task <ParseUser > loginTask = user .logInWithAsync (authType , authData );
430
+ Task <ParseUser > loginTask = ParseUser .logInWithAsync (authType , authData );
432
431
loginTask .waitForCompletion ();
433
432
434
433
// Make sure we try to resolveLaziness
435
- verify (partialMockCurrentUser , times (1 )).resolveLazinessAsync (any (Task . class ));
434
+ verify (partialMockCurrentUser , times (1 )).resolveLazinessAsync (Matchers .< Task < Void >> any ());
436
435
// Make sure we do not save new authData
437
436
assertNull (partialMockCurrentUser .getAuthData ().get ("facebook" ));
438
437
// Make sure we restore anonymity after resolve laziness failure
@@ -452,17 +451,16 @@ public void testLoginWithAsyncWithLinkedNotLazyUser() throws Exception {
452
451
when (partialMockCurrentUser .getSessionToken ()).thenReturn ("sessionToken" );
453
452
doReturn (Task .<Void >forResult (null ))
454
453
.when (partialMockCurrentUser )
455
- .linkWithAsync (anyString (), anyMap (), anyString ());
454
+ .linkWithAsync (anyString (), Matchers .< Map < String , String >> any (), anyString ());
456
455
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
457
456
when (currentUserController .getAsync ()).thenReturn (Task .forResult (partialMockCurrentUser ));
458
457
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
459
458
460
- ParseUser user = new ParseUser ();
461
459
String authType = "facebook" ;
462
460
Map <String , String > authData = new HashMap <>();
463
461
authData .put ("token" , "123" );
464
462
465
- ParseUser userAfterLogin = ParseTaskUtils .wait (user .logInWithAsync (authType , authData ));
463
+ ParseUser userAfterLogin = ParseTaskUtils .wait (ParseUser .logInWithAsync (authType , authData ));
466
464
467
465
// Make sure we link authData
468
466
verify (partialMockCurrentUser , times (1 )).linkWithAsync (
@@ -478,7 +476,8 @@ public void testLoginWithAsyncWithLinkedNotLazyUserLinkFailure() throws Exceptio
478
476
.put ("newKey" , "newValue" )
479
477
.sessionToken ("newSessionToken" )
480
478
.build ();
481
- when (userController .logInAsync (anyString (), anyMap ())).thenReturn (Task .forResult (newUserState ));
479
+ when (userController .logInAsync (anyString (), Matchers .<Map <String , String >>any ()))
480
+ .thenReturn (Task .forResult (newUserState ));
482
481
ParseCorePlugins .getInstance ().registerUserController (userController );
483
482
// Register a mock currentUserController to make getCurrentUser work
484
483
ParseUser currentUser = new ParseUser ();
@@ -490,19 +489,18 @@ public void testLoginWithAsyncWithLinkedNotLazyUserLinkFailure() throws Exceptio
490
489
new ParseException (ParseException .ACCOUNT_ALREADY_LINKED , "Account already linked" );
491
490
doReturn (Task .<Void >forError (linkException ))
492
491
.when (partialMockCurrentUser )
493
- .linkWithAsync (anyString (), anyMap (), anyString ());
492
+ .linkWithAsync (anyString (), Matchers .< Map < String , String >> any (), anyString ());
494
493
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
495
494
when (currentUserController .getAsync ()).thenReturn (Task .forResult (partialMockCurrentUser ));
496
495
when (currentUserController .setAsync (any (ParseUser .class )))
497
496
.thenReturn (Task .<Void >forResult (null ));
498
497
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
499
498
500
499
501
- ParseUser user = new ParseUser ();
502
500
String authType = "facebook" ;
503
501
Map <String , String > authData = new HashMap <>();
504
502
authData .put ("token" , "123" );
505
- ParseUser userAfterLogin = ParseTaskUtils .wait (user .logInWithAsync (authType , authData ));
503
+ ParseUser userAfterLogin = ParseTaskUtils .wait (ParseUser .logInWithAsync (authType , authData ));
506
504
507
505
// Make sure we link authData
508
506
verify (partialMockCurrentUser , times (1 )).linkWithAsync (
@@ -524,22 +522,21 @@ public void testLoginWithAsyncWithNoCurrentUser() throws Exception {
524
522
.put ("newKey" , "newValue" )
525
523
.sessionToken ("newSessionToken" )
526
524
.build ();
527
- when (userController .logInAsync (anyString (), anyMap ())).thenReturn (Task .forResult (newUserState ));
525
+ when (userController .logInAsync (anyString (), Matchers .<Map <String , String >>any ()))
526
+ .thenReturn (Task .forResult (newUserState ));
528
527
ParseCorePlugins .getInstance ().registerUserController (userController );
529
528
// Register a mock currentUserController to make getCurrentUser work
530
- ParseUser currentUser = new ParseUser ();
531
529
ParseCurrentUserController currentUserController = mock (ParseCurrentUserController .class );
532
530
when (currentUserController .getAsync ()).thenReturn (Task .<ParseUser >forResult (null ));
533
531
when (currentUserController .setAsync (any (ParseUser .class )))
534
532
.thenReturn (Task .<Void >forResult (null ));
535
533
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
536
534
537
- ParseUser user = new ParseUser ();
538
535
String authType = "facebook" ;
539
536
Map <String , String > authData = new HashMap <>();
540
537
authData .put ("token" , "123" );
541
538
542
- ParseUser userAfterLogin = ParseTaskUtils .wait (user .logInWithAsync (authType , authData ));
539
+ ParseUser userAfterLogin = ParseTaskUtils .wait (ParseUser .logInWithAsync (authType , authData ));
543
540
544
541
// Make sure we login authData
545
542
verify (userController , times (1 )).logInAsync ("facebook" , authData );
@@ -565,7 +562,7 @@ public void testLinkWithAsyncWithSaveAsyncSuccess() throws Exception {
565
562
// Register a mock authenticationProvider
566
563
ParseAuthenticationProvider provider = mock (ParseAuthenticationProvider .class );
567
564
when (provider .getAuthType ()).thenReturn ("facebook" );
568
- when (provider .restoreAuthentication (anyMap ())).thenReturn (true );
565
+ when (provider .restoreAuthentication (Matchers .< Map < String , String >> any ())).thenReturn (true );
569
566
ParseUser .registerAuthenticationProvider (provider );
570
567
571
568
ParseUser user = new ParseUser ();
@@ -577,7 +574,7 @@ public void testLinkWithAsyncWithSaveAsyncSuccess() throws Exception {
577
574
ParseUser partialMockUser = spy (user );
578
575
doReturn (Task .<Void >forResult (null ))
579
576
.when (partialMockUser )
580
- .saveAsync (anyString (), any (Task . class ));
577
+ .saveAsync (anyString (), Matchers .< Task < Void >> any ());
581
578
String authType = "facebook" ;
582
579
Map <String , String > authData = new HashMap <>();
583
580
authData .put ("token" , "test" );
@@ -589,7 +586,7 @@ public void testLinkWithAsyncWithSaveAsyncSuccess() throws Exception {
589
586
// Make sure new authData is added
590
587
assertSame (authData , partialMockUser .getAuthData ().get ("facebook" ));
591
588
// Make sure we save the user
592
- verify (partialMockUser , times (1 )).saveAsync (eq ("sessionTokenAgain" ), any (Task . class ));
589
+ verify (partialMockUser , times (1 )).saveAsync (eq ("sessionTokenAgain" ), Matchers .< Task < Void >> any ());
593
590
// Make sure synchronizeAuthData() is called
594
591
verify (provider , times (1 )).restoreAuthentication (authData );
595
592
}
@@ -612,7 +609,7 @@ public void testLinkWithAsyncWithSaveAsyncFailure() throws Exception {
612
609
Exception saveException = new Exception ();
613
610
doReturn (Task .<Void >forError (saveException ))
614
611
.when (partialMockUser )
615
- .saveAsync (anyString (), any (Task . class ));
612
+ .saveAsync (anyString (), Matchers .< Task < Void >> any ());
616
613
String facebookAuthType = "facebook" ;
617
614
Map <String , String > facebookAuthData = new HashMap <>();
618
615
facebookAuthData .put ("facebookToken" , "facebookTest" );
@@ -624,7 +621,7 @@ public void testLinkWithAsyncWithSaveAsyncFailure() throws Exception {
624
621
// Make sure new authData is added
625
622
assertSame (facebookAuthData , partialMockUser .getAuthData ().get ("facebook" ));
626
623
// Make sure we save the user
627
- verify (partialMockUser , times (1 )).saveAsync (eq ("sessionTokenAgain" ), any (Task . class ));
624
+ verify (partialMockUser , times (1 )).saveAsync (eq ("sessionTokenAgain" ), Matchers .< Task < Void >> any ());
628
625
// Make sure old authData is restored
629
626
assertSame (anonymousAuthData , partialMockUser .getAuthData ().get (ParseAnonymousUtils .AUTH_TYPE ));
630
627
// Verify exception
@@ -843,7 +840,7 @@ public void testSaveAsyncWithLazyAndCurrentUser() throws Exception {
843
840
ParseUser partialMockUser = spy (user );
844
841
doReturn (Task .<Void >forResult (null ))
845
842
.when (partialMockUser )
846
- .resolveLazinessAsync (any (Task . class ));
843
+ .resolveLazinessAsync (Matchers .< Task < Void >> any ());
847
844
848
845
ParseTaskUtils .wait (partialMockUser .saveAsync ("sessionToken" , Task .<Void >forResult (null )));
849
846
@@ -871,7 +868,7 @@ public void testSaveAsyncWithLazyAndNotCurrentUser() throws Exception {
871
868
ParseUser partialMockUser = spy (user );
872
869
doReturn (Task .<Void >forResult (null ))
873
870
.when (partialMockUser )
874
- .resolveLazinessAsync (any (Task . class ));
871
+ .resolveLazinessAsync (Matchers .< Task < Void >> any ());
875
872
876
873
ParseTaskUtils .wait (partialMockUser .saveAsync ("sessionToken" , Task .<Void >forResult (null )));
877
874
@@ -899,7 +896,7 @@ public void testLogoutInternal() throws Exception {
899
896
// Register a mock authenticationProvider
900
897
ParseAuthenticationProvider provider = mock (ParseAuthenticationProvider .class );
901
898
when (provider .getAuthType ()).thenReturn ("facebook" );
902
- when (provider .restoreAuthentication (anyMap ())).thenReturn (true );
899
+ when (provider .restoreAuthentication (Matchers .< Map < String , String >> any ())).thenReturn (true );
903
900
ParseUser .registerAuthenticationProvider (provider );
904
901
905
902
// Set user initial state
@@ -965,8 +962,7 @@ public void testEnableRevocableSessionInBackgroundWithCurrentUser() throws Excep
965
962
when (currentUserController .getAsync (anyBoolean ())).thenReturn (Task .forResult (mockUser ));
966
963
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
967
964
968
- ParseUser user = new ParseUser ();
969
- ParseTaskUtils .wait (user .enableRevocableSessionInBackground ());
965
+ ParseTaskUtils .wait (ParseUser .enableRevocableSessionInBackground ());
970
966
971
967
verify (currentUserController , times (1 )).getAsync (false );
972
968
verify (mockUser , times (1 )).upgradeToRevocableSessionAsync ();
@@ -983,8 +979,7 @@ public void testEnableRevocableSessionInBackgroundWithNoCurrentUser() throws Exc
983
979
when (currentUserController .getAsync (anyBoolean ())).thenReturn (Task .<ParseUser >forResult (null ));
984
980
ParseCorePlugins .getInstance ().registerCurrentUserController (currentUserController );
985
981
986
- ParseUser user = new ParseUser ();
987
- ParseTaskUtils .wait (user .enableRevocableSessionInBackground ());
982
+ ParseTaskUtils .wait (ParseUser .enableRevocableSessionInBackground ());
988
983
989
984
verify (currentUserController , times (1 )).getAsync (false );
990
985
}
@@ -1078,14 +1073,14 @@ public void testUnlinkFromAsyncWithAuthType() throws Exception {
1078
1073
ParseUser partialMockUser = spy (user );
1079
1074
doReturn (Task .<Void >forResult (null ))
1080
1075
.when (partialMockUser )
1081
- .saveAsync (anyString (), any (Task . class ));
1076
+ .saveAsync (anyString (), Matchers .< Task < Void >> any ());
1082
1077
1083
1078
ParseTaskUtils .wait (partialMockUser .unlinkFromAsync ("facebook" ));
1084
1079
1085
1080
// Verify we delete authData
1086
1081
assertNull (user .getAuthData ().get ("facebook" ));
1087
1082
// Verify we save the user
1088
- verify (partialMockUser , times (1 )).saveAsync (eq ("sessionToken" ), any (Task . class ));
1083
+ verify (partialMockUser , times (1 )).saveAsync (eq ("sessionToken" ), Matchers .< Task < Void >> any ());
1089
1084
}
1090
1085
1091
1086
@ Test
@@ -1342,7 +1337,7 @@ public void testSynchronizeAuthData() throws Exception {
1342
1337
// Register a mock authenticationProvider
1343
1338
ParseAuthenticationProvider provider = mock (ParseAuthenticationProvider .class );
1344
1339
when (provider .getAuthType ()).thenReturn ("facebook" );
1345
- when (provider .restoreAuthentication (anyMap ())).thenReturn (true );
1340
+ when (provider .restoreAuthentication (Matchers .< Map < String , String >> any ())).thenReturn (true );
1346
1341
ParseUser .registerAuthenticationProvider (provider );
1347
1342
1348
1343
// Set user initial state
@@ -1370,7 +1365,7 @@ public void testSynchronizeAllAuthData() throws Exception {
1370
1365
// Register a mock authenticationProvider
1371
1366
ParseAuthenticationProvider provider = mock (ParseAuthenticationProvider .class );
1372
1367
when (provider .getAuthType ()).thenReturn ("facebook" );
1373
- when (provider .restoreAuthentication (anyMap ())).thenReturn (true );
1368
+ when (provider .restoreAuthentication (Matchers .< Map < String , String >> any ())).thenReturn (true );
1374
1369
ParseUser .registerAuthenticationProvider (provider );
1375
1370
1376
1371
// Set user initial state
@@ -1395,13 +1390,13 @@ public void testSynchronizeAllAuthData() throws Exception {
1395
1390
1396
1391
@ Test
1397
1392
public void testAutomaticUser () throws Exception {
1398
- ParseUser user = new ParseUser ();
1393
+ new ParseUser ();
1399
1394
1400
- user .disableAutomaticUser ();
1401
- assertFalse (user .isAutomaticUserEnabled ());
1395
+ ParseUser .disableAutomaticUser ();
1396
+ assertFalse (ParseUser .isAutomaticUserEnabled ());
1402
1397
1403
- user .enableAutomaticUser ();
1404
- assertTrue (user .isAutomaticUserEnabled ());
1398
+ ParseUser .enableAutomaticUser ();
1399
+ assertTrue (ParseUser .isAutomaticUserEnabled ());
1405
1400
}
1406
1401
1407
1402
//endregion
0 commit comments