24
24
import org .robolectric .RuntimeEnvironment ;
25
25
import org .robolectric .Shadows ;
26
26
import org .robolectric .annotation .Config ;
27
- import org .robolectric .shadows .ShadowApplication ;
28
27
29
- import java .net .URL ;
30
28
import java .util .Collections ;
31
29
import java .util .Date ;
32
30
import java .util .HashMap ;
@@ -77,9 +75,19 @@ public void setUp() throws Exception {
77
75
@ After
78
76
public void tearDown () throws Exception {
79
77
super .tearDown ();
80
- ParseObject .unregisterSubclass (ParseUser .class );
81
- ParseObject .unregisterSubclass (ParseSession .class );
82
- Parse .disableLocalDatastore ();
78
+ if (ParsePlugins .get () != null ) {
79
+ ParseCurrentInstallationController installationController =
80
+ ParseCorePlugins .getInstance ().getCurrentInstallationController ();
81
+ if (installationController != null ) {
82
+ installationController .clearFromDisk ();
83
+ }
84
+ ParseCurrentUserController userController =
85
+ ParseCorePlugins .getInstance ().getCurrentUserController ();
86
+ if (userController != null ) {
87
+ userController .clearFromDisk ();
88
+ }
89
+ }
90
+ Parse .destroy ();
83
91
}
84
92
85
93
@ Test
@@ -1551,10 +1559,10 @@ private static void setLazy(ParseUser user) {
1551
1559
user .putAuthData (ParseAnonymousUtils .AUTH_TYPE , anonymousAuthData );
1552
1560
}
1553
1561
1554
- //region testSaveEventuallyWhenSessionIsInvalid
1562
+ //region testSaveEventuallyWhenServerError
1555
1563
1556
1564
@ Test
1557
- public void testSaveEventuallyWhenSessionIsInvalid () throws Exception {
1565
+ public void testSaveEventuallyWhenServerError () throws Exception {
1558
1566
Shadows .shadowOf (RuntimeEnvironment .application )
1559
1567
.grantPermissions (Manifest .permission .ACCESS_NETWORK_STATE );
1560
1568
Parse .Configuration configuration =
@@ -1578,7 +1586,10 @@ public void testSaveEventuallyWhenSessionIsInvalid() throws Exception {
1578
1586
Parse .initialize (configuration , plugins );
1579
1587
1580
1588
ParseUser user = ParseUser .logIn ("username" , "password" );
1589
+ assertFalse (user .isDirty ());
1590
+
1581
1591
user .put ("field" , "data" );
1592
+ assertTrue (user .isDirty ());
1582
1593
1583
1594
mockResponse = new JSONObject ();
1584
1595
mockResponse .put ("updatedAt" , ParseDateFormat .getInstance ().format (new Date (3000 )));
@@ -1597,12 +1608,14 @@ public Void then(Task<Void> task) throws Exception {
1597
1608
});
1598
1609
assertTrue (saveCountDown1 .await (5 , TimeUnit .SECONDS ));
1599
1610
assertNull (exceptionCapture .get ());
1611
+ assertFalse (user .isDirty ());
1600
1612
1601
1613
user .put ("field" , "other data" );
1614
+ assertTrue (user .isDirty ());
1602
1615
1603
1616
mockResponse = new JSONObject ();
1604
- mockResponse .put ("error" , "invalid session token " );
1605
- mockResponse .put ("code" , 209 );
1617
+ mockResponse .put ("error" , "Save is not allowed " );
1618
+ mockResponse .put ("code" , 141 );
1606
1619
ParseTestUtils .updateMockParseHttpClientWithResponse (
1607
1620
restClient , mockResponse , 400 , "Bad Request" );
1608
1621
@@ -1617,14 +1630,17 @@ public Void then(Task<Void> task) throws Exception {
1617
1630
});
1618
1631
assertTrue (saveEventuallyCountDown .await (5 , TimeUnit .SECONDS ));
1619
1632
assertTrue (exceptionCapture .get () instanceof ParseException );
1620
- assertEquals (ParseException .INVALID_SESSION_TOKEN , ((ParseException )exceptionCapture .get ()).getCode ());
1621
- assertEquals ("invalid session token" , exceptionCapture .get ().getMessage ());
1633
+ assertEquals (ParseException .SCRIPT_ERROR , ((ParseException )exceptionCapture .get ()).getCode ());
1634
+ assertEquals ("Save is not allowed" , exceptionCapture .get ().getMessage ());
1635
+ assertTrue (user .isDirty ());
1622
1636
1623
1637
// Simulate reboot
1624
1638
Parse .destroy ();
1625
1639
Parse .initialize (configuration , plugins );
1626
1640
1627
1641
user = ParseUser .getCurrentUser ();
1642
+ assertTrue (user .isDirty ());
1643
+
1628
1644
assertEquals ("other data" , user .get ("field" ));
1629
1645
user .put ("field" , "another data" );
1630
1646
@@ -1642,12 +1658,10 @@ public Void then(Task<Void> task) throws Exception {
1642
1658
return null ;
1643
1659
}
1644
1660
});
1661
+
1645
1662
assertTrue (saveCountDown2 .await (5 , TimeUnit .SECONDS ));
1646
1663
assertNull (exceptionCapture .get ());
1647
-
1648
- ParseCorePlugins .getInstance ().getCurrentUserController ().clearFromDisk ();
1649
- ParseCorePlugins .getInstance ().getCurrentInstallationController ().clearFromDisk ();
1650
- Parse .destroy ();
1664
+ assertFalse (user .isDirty ());
1651
1665
}
1652
1666
1653
1667
//endregion
0 commit comments