Skip to content

Commit fa8ac07

Browse files
committed
Merge pull request #71 from ParsePlatform/grantland.clean_parse_user_test
Clean warnings in ParseUserTest
2 parents 44d3133 + 2afe994 commit fa8ac07

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

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

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
import org.junit.Test;
1616
import org.junit.rules.ExpectedException;
1717
import org.junit.runner.RunWith;
18+
import org.mockito.Matchers;
1819
import org.robolectric.RobolectricGradleTestRunner;
1920
import org.robolectric.annotation.Config;
2021

21-
import java.util.Arrays;
22+
import java.util.Collections;
2223
import java.util.HashMap;
2324
import java.util.Map;
2425
import java.util.concurrent.Semaphore;
@@ -34,7 +35,6 @@
3435
import static org.junit.Assert.assertTrue;
3536
import static org.mockito.Matchers.any;
3637
import static org.mockito.Matchers.anyBoolean;
37-
import static org.mockito.Matchers.anyMap;
3838
import static org.mockito.Matchers.anyString;
3939
import static org.mockito.Matchers.eq;
4040
import static org.mockito.Mockito.doReturn;
@@ -86,7 +86,7 @@ public void testImmutableKeys() {
8686
}
8787

8888
try {
89-
user.removeAll("sessionToken", Arrays.asList());
89+
user.removeAll("sessionToken", Collections.emptyList());
9090
} catch (IllegalArgumentException e) {
9191
assertTrue(e.getMessage().contains("Cannot modify"));
9292
}
@@ -165,12 +165,12 @@ public void testSignUpAsyncWithObjectIdSetAndAuthDataSet() throws Exception {
165165
ParseUser partialMockUser = spy(user);
166166
doReturn(Task.<Void>forResult(null))
167167
.when(partialMockUser)
168-
.saveAsync(anyString(), any(Task.class));
168+
.saveAsync(anyString(), Matchers.<Task<Void>>any());
169169

170170
ParseTaskUtils.wait(partialMockUser.signUpAsync(Task.<Void>forResult(null)));
171171

172172
// 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());
174174
}
175175

176176
@Test
@@ -220,7 +220,7 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUser() throws Exception {
220220
when(currentUser.isLinked(ParseAnonymousUtils.AUTH_TYPE)).thenReturn(true);
221221
when(currentUser.getSessionToken()).thenReturn("oldSessionToken");
222222
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()))
224224
.thenReturn(Task.<Void>forResult(null));
225225
ParseUser.State state = new ParseUser.State.Builder()
226226
.put("oldKey", "oldValue")
@@ -248,7 +248,7 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUser() throws Exception {
248248
verify(currentUser, times(1)).setUsername("userName");
249249
verify(currentUser, times(1)).setPassword("password");
250250
// 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());
252252
// Make sure we merge currentUser with user after save
253253
assertEquals("oldValue", user.get("oldKey"));
254254
// Make sure set currentUser
@@ -269,7 +269,7 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUserSaveFailure() throws Exce
269269
ParseException saveException = new ParseException(ParseException.OTHER_CAUSE, "");
270270
doReturn(Task.<Void>forError(saveException))
271271
.when(partialMockCurrentUser)
272-
.saveAsync(anyString(), any(Task.class));
272+
.saveAsync(anyString(), Matchers.<Task<Void>>any());
273273
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
274274
when(currentUserController.getAsync(anyBoolean()))
275275
.thenReturn(Task.forResult(partialMockCurrentUser));
@@ -293,7 +293,8 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUserSaveFailure() throws Exce
293293
// Make sure we sync user with currentUser
294294
verify(partialMockCurrentUser, times(1)).copyChangesFrom(eq(user));
295295
// 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());
297298
// Make sure we restore old username and password after save fails
298299
verify(partialMockCurrentUser, times(1)).setUsername("oldUserName");
299300
verify(partialMockCurrentUser, times(1)).setPassword("oldPassword");
@@ -388,23 +389,22 @@ public void testLoginWithAsyncWithLinkedLazyUser() throws Exception {
388389
when(partialMockCurrentUser.getSessionToken()).thenReturn("oldSessionToken");
389390
doReturn(Task.<ParseUser>forResult(null))
390391
.when(partialMockCurrentUser)
391-
.resolveLazinessAsync(any(Task.class));
392+
.resolveLazinessAsync(Matchers.<Task<Void>>any());
392393
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
393394
when(currentUserController.getAsync()).thenReturn(Task.forResult(partialMockCurrentUser));
394395
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
395396

396-
ParseUser user = new ParseUser();
397397
String authType = "facebook";
398398
Map<String, String> authData = new HashMap<>();
399399
authData.put("token", "123");
400-
ParseUser userAfterLogin = ParseTaskUtils.wait(user.logInWithAsync(authType, authData));
400+
ParseUser userAfterLogin = ParseTaskUtils.wait(ParseUser.logInWithAsync(authType, authData));
401401

402402
// Make sure we stripAnonymity
403403
assertNull(userAfterLogin.getAuthData().get(ParseAnonymousUtils.AUTH_TYPE));
404404
// Make sure we update authData
405405
assertEquals(authData, userAfterLogin.getAuthData().get("facebook"));
406406
// Make sure we resolveLaziness
407-
verify(partialMockCurrentUser, times(1)).resolveLazinessAsync(any(Task.class));
407+
verify(partialMockCurrentUser, times(1)).resolveLazinessAsync(Matchers.<Task<Void>>any());
408408
}
409409

410410
@Test
@@ -418,21 +418,20 @@ public void testLoginWithAsyncWithLinkedLazyUseAndResolveLazinessFailure() throw
418418
when(partialMockCurrentUser.getSessionToken()).thenReturn("oldSessionToken");
419419
doReturn(Task.<ParseUser>forError(new Exception()))
420420
.when(partialMockCurrentUser)
421-
.resolveLazinessAsync(any(Task.class));
421+
.resolveLazinessAsync(Matchers.<Task<Void>>any());
422422
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
423423
when(currentUserController.getAsync()).thenReturn(Task.forResult(partialMockCurrentUser));
424424
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
425425

426-
ParseUser user = new ParseUser();
427426
String authType = "facebook";
428427
Map<String, String> authData = new HashMap<>();
429428
authData.put("token", "123");
430429

431-
Task<ParseUser> loginTask = user.logInWithAsync(authType, authData);
430+
Task<ParseUser> loginTask = ParseUser.logInWithAsync(authType, authData);
432431
loginTask.waitForCompletion();
433432

434433
// 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());
436435
// Make sure we do not save new authData
437436
assertNull(partialMockCurrentUser.getAuthData().get("facebook"));
438437
// Make sure we restore anonymity after resolve laziness failure
@@ -452,17 +451,16 @@ public void testLoginWithAsyncWithLinkedNotLazyUser() throws Exception {
452451
when(partialMockCurrentUser.getSessionToken()).thenReturn("sessionToken");
453452
doReturn(Task.<Void>forResult(null))
454453
.when(partialMockCurrentUser)
455-
.linkWithAsync(anyString(), anyMap(), anyString());
454+
.linkWithAsync(anyString(), Matchers.<Map<String, String>>any(), anyString());
456455
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
457456
when(currentUserController.getAsync()).thenReturn(Task.forResult(partialMockCurrentUser));
458457
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
459458

460-
ParseUser user = new ParseUser();
461459
String authType = "facebook";
462460
Map<String, String> authData = new HashMap<>();
463461
authData.put("token", "123");
464462

465-
ParseUser userAfterLogin = ParseTaskUtils.wait(user.logInWithAsync(authType, authData));
463+
ParseUser userAfterLogin = ParseTaskUtils.wait(ParseUser.logInWithAsync(authType, authData));
466464

467465
// Make sure we link authData
468466
verify(partialMockCurrentUser, times(1)).linkWithAsync(
@@ -478,7 +476,8 @@ public void testLoginWithAsyncWithLinkedNotLazyUserLinkFailure() throws Exceptio
478476
.put("newKey", "newValue")
479477
.sessionToken("newSessionToken")
480478
.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));
482481
ParseCorePlugins.getInstance().registerUserController(userController);
483482
// Register a mock currentUserController to make getCurrentUser work
484483
ParseUser currentUser = new ParseUser();
@@ -490,19 +489,18 @@ public void testLoginWithAsyncWithLinkedNotLazyUserLinkFailure() throws Exceptio
490489
new ParseException(ParseException.ACCOUNT_ALREADY_LINKED, "Account already linked");
491490
doReturn(Task.<Void>forError(linkException))
492491
.when(partialMockCurrentUser)
493-
.linkWithAsync(anyString(), anyMap(), anyString());
492+
.linkWithAsync(anyString(), Matchers.<Map<String, String>>any(), anyString());
494493
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
495494
when(currentUserController.getAsync()).thenReturn(Task.forResult(partialMockCurrentUser));
496495
when(currentUserController.setAsync(any(ParseUser.class)))
497496
.thenReturn(Task.<Void>forResult(null));
498497
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
499498

500499

501-
ParseUser user = new ParseUser();
502500
String authType = "facebook";
503501
Map<String, String> authData = new HashMap<>();
504502
authData.put("token", "123");
505-
ParseUser userAfterLogin = ParseTaskUtils.wait(user.logInWithAsync(authType, authData));
503+
ParseUser userAfterLogin = ParseTaskUtils.wait(ParseUser.logInWithAsync(authType, authData));
506504

507505
// Make sure we link authData
508506
verify(partialMockCurrentUser, times(1)).linkWithAsync(
@@ -524,22 +522,21 @@ public void testLoginWithAsyncWithNoCurrentUser() throws Exception {
524522
.put("newKey", "newValue")
525523
.sessionToken("newSessionToken")
526524
.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));
528527
ParseCorePlugins.getInstance().registerUserController(userController);
529528
// Register a mock currentUserController to make getCurrentUser work
530-
ParseUser currentUser = new ParseUser();
531529
ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
532530
when(currentUserController.getAsync()).thenReturn(Task.<ParseUser>forResult(null));
533531
when(currentUserController.setAsync(any(ParseUser.class)))
534532
.thenReturn(Task.<Void>forResult(null));
535533
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
536534

537-
ParseUser user = new ParseUser();
538535
String authType = "facebook";
539536
Map<String, String> authData = new HashMap<>();
540537
authData.put("token", "123");
541538

542-
ParseUser userAfterLogin = ParseTaskUtils.wait(user.logInWithAsync(authType, authData));
539+
ParseUser userAfterLogin = ParseTaskUtils.wait(ParseUser.logInWithAsync(authType, authData));
543540

544541
// Make sure we login authData
545542
verify(userController, times(1)).logInAsync("facebook", authData);
@@ -565,7 +562,7 @@ public void testLinkWithAsyncWithSaveAsyncSuccess() throws Exception {
565562
// Register a mock authenticationProvider
566563
ParseAuthenticationProvider provider = mock(ParseAuthenticationProvider.class);
567564
when(provider.getAuthType()).thenReturn("facebook");
568-
when(provider.restoreAuthentication(anyMap())).thenReturn(true);
565+
when(provider.restoreAuthentication(Matchers.<Map<String, String>>any())).thenReturn(true);
569566
ParseUser.registerAuthenticationProvider(provider);
570567

571568
ParseUser user = new ParseUser();
@@ -577,7 +574,7 @@ public void testLinkWithAsyncWithSaveAsyncSuccess() throws Exception {
577574
ParseUser partialMockUser = spy(user);
578575
doReturn(Task.<Void>forResult(null))
579576
.when(partialMockUser)
580-
.saveAsync(anyString(), any(Task.class));
577+
.saveAsync(anyString(), Matchers.<Task<Void>>any());
581578
String authType = "facebook";
582579
Map<String, String> authData = new HashMap<>();
583580
authData.put("token", "test");
@@ -589,7 +586,7 @@ public void testLinkWithAsyncWithSaveAsyncSuccess() throws Exception {
589586
// Make sure new authData is added
590587
assertSame(authData, partialMockUser.getAuthData().get("facebook"));
591588
// 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());
593590
// Make sure synchronizeAuthData() is called
594591
verify(provider, times(1)).restoreAuthentication(authData);
595592
}
@@ -612,7 +609,7 @@ public void testLinkWithAsyncWithSaveAsyncFailure() throws Exception {
612609
Exception saveException = new Exception();
613610
doReturn(Task.<Void>forError(saveException))
614611
.when(partialMockUser)
615-
.saveAsync(anyString(), any(Task.class));
612+
.saveAsync(anyString(), Matchers.<Task<Void>>any());
616613
String facebookAuthType = "facebook";
617614
Map<String, String> facebookAuthData = new HashMap<>();
618615
facebookAuthData.put("facebookToken", "facebookTest");
@@ -624,7 +621,7 @@ public void testLinkWithAsyncWithSaveAsyncFailure() throws Exception {
624621
// Make sure new authData is added
625622
assertSame(facebookAuthData, partialMockUser.getAuthData().get("facebook"));
626623
// 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());
628625
// Make sure old authData is restored
629626
assertSame(anonymousAuthData, partialMockUser.getAuthData().get(ParseAnonymousUtils.AUTH_TYPE));
630627
// Verify exception
@@ -843,7 +840,7 @@ public void testSaveAsyncWithLazyAndCurrentUser() throws Exception {
843840
ParseUser partialMockUser = spy(user);
844841
doReturn(Task.<Void>forResult(null))
845842
.when(partialMockUser)
846-
.resolveLazinessAsync(any(Task.class));
843+
.resolveLazinessAsync(Matchers.<Task<Void>>any());
847844

848845
ParseTaskUtils.wait(partialMockUser.saveAsync("sessionToken", Task.<Void>forResult(null)));
849846

@@ -871,7 +868,7 @@ public void testSaveAsyncWithLazyAndNotCurrentUser() throws Exception {
871868
ParseUser partialMockUser = spy(user);
872869
doReturn(Task.<Void>forResult(null))
873870
.when(partialMockUser)
874-
.resolveLazinessAsync(any(Task.class));
871+
.resolveLazinessAsync(Matchers.<Task<Void>>any());
875872

876873
ParseTaskUtils.wait(partialMockUser.saveAsync("sessionToken", Task.<Void>forResult(null)));
877874

@@ -899,7 +896,7 @@ public void testLogoutInternal() throws Exception {
899896
// Register a mock authenticationProvider
900897
ParseAuthenticationProvider provider = mock(ParseAuthenticationProvider.class);
901898
when(provider.getAuthType()).thenReturn("facebook");
902-
when(provider.restoreAuthentication(anyMap())).thenReturn(true);
899+
when(provider.restoreAuthentication(Matchers.<Map<String, String>>any())).thenReturn(true);
903900
ParseUser.registerAuthenticationProvider(provider);
904901

905902
// Set user initial state
@@ -965,8 +962,7 @@ public void testEnableRevocableSessionInBackgroundWithCurrentUser() throws Excep
965962
when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.forResult(mockUser));
966963
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
967964

968-
ParseUser user = new ParseUser();
969-
ParseTaskUtils.wait(user.enableRevocableSessionInBackground());
965+
ParseTaskUtils.wait(ParseUser.enableRevocableSessionInBackground());
970966

971967
verify(currentUserController, times(1)).getAsync(false);
972968
verify(mockUser, times(1)).upgradeToRevocableSessionAsync();
@@ -983,8 +979,7 @@ public void testEnableRevocableSessionInBackgroundWithNoCurrentUser() throws Exc
983979
when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.<ParseUser>forResult(null));
984980
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
985981

986-
ParseUser user = new ParseUser();
987-
ParseTaskUtils.wait(user.enableRevocableSessionInBackground());
982+
ParseTaskUtils.wait(ParseUser.enableRevocableSessionInBackground());
988983

989984
verify(currentUserController, times(1)).getAsync(false);
990985
}
@@ -1078,14 +1073,14 @@ public void testUnlinkFromAsyncWithAuthType() throws Exception {
10781073
ParseUser partialMockUser = spy(user);
10791074
doReturn(Task.<Void>forResult(null))
10801075
.when(partialMockUser)
1081-
.saveAsync(anyString(), any(Task.class));
1076+
.saveAsync(anyString(), Matchers.<Task<Void>>any());
10821077

10831078
ParseTaskUtils.wait(partialMockUser.unlinkFromAsync("facebook"));
10841079

10851080
// Verify we delete authData
10861081
assertNull(user.getAuthData().get("facebook"));
10871082
// 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());
10891084
}
10901085

10911086
@Test
@@ -1342,7 +1337,7 @@ public void testSynchronizeAuthData() throws Exception {
13421337
// Register a mock authenticationProvider
13431338
ParseAuthenticationProvider provider = mock(ParseAuthenticationProvider.class);
13441339
when(provider.getAuthType()).thenReturn("facebook");
1345-
when(provider.restoreAuthentication(anyMap())).thenReturn(true);
1340+
when(provider.restoreAuthentication(Matchers.<Map<String, String>>any())).thenReturn(true);
13461341
ParseUser.registerAuthenticationProvider(provider);
13471342

13481343
// Set user initial state
@@ -1370,7 +1365,7 @@ public void testSynchronizeAllAuthData() throws Exception {
13701365
// Register a mock authenticationProvider
13711366
ParseAuthenticationProvider provider = mock(ParseAuthenticationProvider.class);
13721367
when(provider.getAuthType()).thenReturn("facebook");
1373-
when(provider.restoreAuthentication(anyMap())).thenReturn(true);
1368+
when(provider.restoreAuthentication(Matchers.<Map<String, String>>any())).thenReturn(true);
13741369
ParseUser.registerAuthenticationProvider(provider);
13751370

13761371
// Set user initial state
@@ -1395,13 +1390,13 @@ public void testSynchronizeAllAuthData() throws Exception {
13951390

13961391
@Test
13971392
public void testAutomaticUser() throws Exception {
1398-
ParseUser user = new ParseUser();
1393+
new ParseUser();
13991394

1400-
user.disableAutomaticUser();
1401-
assertFalse(user.isAutomaticUserEnabled());
1395+
ParseUser.disableAutomaticUser();
1396+
assertFalse(ParseUser.isAutomaticUserEnabled());
14021397

1403-
user.enableAutomaticUser();
1404-
assertTrue(user.isAutomaticUserEnabled());
1398+
ParseUser.enableAutomaticUser();
1399+
assertTrue(ParseUser.isAutomaticUserEnabled());
14051400
}
14061401

14071402
//endregion

0 commit comments

Comments
 (0)