@@ -121,29 +121,48 @@ public void testInstallationObjectIdCannotBeChanged() throws Exception {
121
121
}
122
122
123
123
@ Test
124
- public void testSaveAsync () throws Exception {
125
- OfflineStore lds = new OfflineStore (RuntimeEnvironment .application );
126
- Parse .setLocalDatastore (lds );
127
-
124
+ public void testMissingRequiredFieldWhenSaveAsync () throws Exception {
128
125
String sessionToken = "sessionToken" ;
129
126
Task <Void > toAwait = Task .forResult (null );
130
127
131
- ParseCurrentInstallationController controller =
132
- mock (ParseCurrentInstallationController .class );
133
- ParseInstallation currentInstallation = new ParseInstallation ();
134
- when (controller .getAsync ())
135
- .thenReturn (Task .forResult (currentInstallation ));
128
+ ParseCurrentInstallationController controller = mockCurrentInstallationController ();
129
+
130
+ ParseObjectController objController = mock (ParseObjectController .class );
131
+ // mock return task when Installation was deleted on the server
132
+ Task <ParseObject .State > taskError = Task .forError (new ParseException (ParseException .MISSING_REQUIRED_FIELD_ERROR , "" ));
133
+ // mock return task when Installation was re-saved to the server
134
+ Task <ParseObject .State > task = Task .forResult (null );
135
+ when (objController .saveAsync (
136
+ any (ParseObject .State .class ),
137
+ any (ParseOperationSet .class ),
138
+ eq (sessionToken ),
139
+ any (ParseDecoder .class )))
140
+ .thenReturn (taskError )
141
+ .thenReturn (task );
136
142
ParseCorePlugins .getInstance ()
137
- .registerCurrentInstallationController (controller );
138
- ParseObject .State state = new ParseObject .State .Builder ("_Installation" )
139
- .objectId ("oldId" )
140
- .put ("deviceToken" , "deviceToken" )
141
- .build ();
143
+ .registerObjectController (objController );
144
+
142
145
ParseInstallation installation = ParseInstallation .getCurrentInstallation ();
143
146
assertNotNull (installation );
144
- installation .setState (state );
145
147
installation .put ("key" , "value" );
148
+ installation .saveAsync (sessionToken , toAwait );
149
+ verify (controller ).getAsync ();
150
+ verify (objController , times (2 )).saveAsync (
151
+ any (ParseObject .State .class ),
152
+ any (ParseOperationSet .class ),
153
+ eq (sessionToken ),
154
+ any (ParseDecoder .class ));
155
+ }
146
156
157
+ @ Test
158
+ public void testObjectNotFoundWhenSaveAsync () throws Exception {
159
+ OfflineStore lds = new OfflineStore (RuntimeEnvironment .application );
160
+ Parse .setLocalDatastore (lds );
161
+
162
+ String sessionToken = "sessionToken" ;
163
+ Task <Void > toAwait = Task .forResult (null );
164
+
165
+ ParseCurrentInstallationController controller = mockCurrentInstallationController ();
147
166
ParseObjectController objController = mock (ParseObjectController .class );
148
167
// mock return task when Installation was deleted on the server
149
168
Task <ParseObject .State > taskError = Task .forError (new ParseException (ParseException .OBJECT_NOT_FOUND , "" ));
@@ -159,6 +178,14 @@ public void testSaveAsync() throws Exception {
159
178
ParseCorePlugins .getInstance ()
160
179
.registerObjectController (objController );
161
180
181
+ ParseObject .State state = new ParseObject .State .Builder ("_Installation" )
182
+ .objectId ("oldId" )
183
+ .put ("deviceToken" , "deviceToken" )
184
+ .build ();
185
+ ParseInstallation installation = ParseInstallation .getCurrentInstallation ();
186
+ assertNotNull (installation );
187
+ installation .setState (state );
188
+ installation .put ("key" , "value" );
162
189
installation .saveAsync (sessionToken , toAwait );
163
190
164
191
verify (controller ).getAsync ();
@@ -360,4 +387,15 @@ private static void mocksForUpdateBeforeSave() {
360
387
when (plugins .applicationContext ()).thenReturn (RuntimeEnvironment .application );
361
388
ParsePlugins .set (plugins );
362
389
}
390
+
391
+ private ParseCurrentInstallationController mockCurrentInstallationController () {
392
+ ParseCurrentInstallationController controller =
393
+ mock (ParseCurrentInstallationController .class );
394
+ ParseInstallation currentInstallation = new ParseInstallation ();
395
+ when (controller .getAsync ())
396
+ .thenReturn (Task .forResult (currentInstallation ));
397
+ ParseCorePlugins .getInstance ()
398
+ .registerCurrentInstallationController (controller );
399
+ return controller ;
400
+ }
363
401
}
0 commit comments