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