@@ -171,7 +171,7 @@ public void teardown() {
171
171
public void getModel_latestModel_localExists_noUpdate () throws Exception {
172
172
when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME ))).thenReturn (customModelLoaded );
173
173
when (mockModelDownloadService .getCustomModelDetails (
174
- eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (null )))
174
+ eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (MODEL_HASH )))
175
175
.thenReturn (Tasks .forResult (CUSTOM_MODEL )); // no change found
176
176
177
177
TestOnCompleteListener <CustomModel > onCompleteListener = new TestOnCompleteListener <>();
@@ -186,11 +186,41 @@ public void getModel_latestModel_localExists_noUpdate() throws Exception {
186
186
assertEquals (customModel , customModelLoaded );
187
187
}
188
188
189
+ @ Test
190
+ public void getModel_latestModel_localExists_noUpdate_MissingFile () throws Exception {
191
+ // model with missing file.
192
+ CustomModel missingFileModel =
193
+ new CustomModel (MODEL_NAME , UPDATE_MODEL_HASH , 100 , 0 , expectedDestinationFolder + "/4" );
194
+ when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME )))
195
+ .thenReturn (missingFileModel )
196
+ .thenReturn (missingFileModel )
197
+ .thenReturn (customModelUploaded );
198
+
199
+ when (mockModelDownloadService .getCustomModelDetails (
200
+ eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (UPDATE_MODEL_HASH )))
201
+ .thenReturn (Tasks .forResult (UPDATE_CUSTOM_MODEL_URL ));
202
+ when (mockFileDownloadService .download (any (), eq (DEFAULT_DOWNLOAD_CONDITIONS )))
203
+ .thenReturn (Tasks .forResult (null ));
204
+ when (mockFileDownloadService .loadNewlyDownloadedModelFile (eq (customModelUploaded )))
205
+ .thenReturn (secondDeviceModelFile );
206
+
207
+ TestOnCompleteListener <CustomModel > onCompleteListener = new TestOnCompleteListener <>();
208
+ Task <CustomModel > task =
209
+ firebaseModelDownloader .getModel (
210
+ MODEL_NAME , DownloadType .LATEST_MODEL , DEFAULT_DOWNLOAD_CONDITIONS );
211
+ task .addOnCompleteListener (executor , onCompleteListener );
212
+ CustomModel customModel = onCompleteListener .await ();
213
+
214
+ verify (mockPrefs , times (3 )).getCustomModelDetails (eq (MODEL_NAME ));
215
+ assertThat (task .isComplete ()).isTrue ();
216
+ assertEquals (customModel , customModelUploaded );
217
+ }
218
+
189
219
@ Test
190
220
public void getModel_latestModel_localExists_sameHash () throws Exception {
191
221
when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME ))).thenReturn (customModelLoaded );
192
222
when (mockModelDownloadService .getCustomModelDetails (
193
- eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (null )))
223
+ eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (MODEL_HASH )))
194
224
.thenReturn (Tasks .forResult (CUSTOM_MODEL )); // no change found
195
225
196
226
TestOnCompleteListener <CustomModel > onCompleteListener = new TestOnCompleteListener <>();
@@ -211,8 +241,9 @@ public void getModel_latestModel_localExists_UpdateFound() throws Exception {
211
241
.thenReturn (customModelLoaded )
212
242
.thenReturn (customModelLoaded )
213
243
.thenReturn (customModelUploaded );
244
+
214
245
when (mockModelDownloadService .getCustomModelDetails (
215
- eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (null )))
246
+ eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (MODEL_HASH )))
216
247
.thenReturn (Tasks .forResult (UPDATE_CUSTOM_MODEL_URL ));
217
248
when (mockFileDownloadService .download (any (), eq (DEFAULT_DOWNLOAD_CONDITIONS )))
218
249
.thenReturn (Tasks .forResult (null ));
@@ -233,7 +264,10 @@ public void getModel_latestModel_localExists_UpdateFound() throws Exception {
233
264
234
265
@ Test
235
266
public void getModel_latestModel_noLocalModel () throws Exception {
236
- when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME ))).thenReturn (null ).thenReturn (CUSTOM_MODEL );
267
+ when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME )))
268
+ .thenReturn (null )
269
+ .thenReturn (null )
270
+ .thenReturn (CUSTOM_MODEL );
237
271
when (mockModelDownloadService .getCustomModelDetails (
238
272
eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (null )))
239
273
.thenReturn (Tasks .forResult (CUSTOM_MODEL ));
@@ -255,7 +289,10 @@ public void getModel_latestModel_noLocalModel() throws Exception {
255
289
256
290
@ Test
257
291
public void getModel_latestModel_noLocalModel_error () throws Exception {
258
- when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME ))).thenReturn (null ).thenReturn (CUSTOM_MODEL );
292
+ when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME )))
293
+ .thenReturn (null )
294
+ .thenReturn (null )
295
+ .thenReturn (CUSTOM_MODEL );
259
296
when (mockModelDownloadService .getCustomModelDetails (
260
297
eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (null )))
261
298
.thenReturn (Tasks .forResult (CUSTOM_MODEL ));
@@ -360,7 +397,10 @@ public void getModel_updateBackground_noLocalModel() throws Exception {
360
397
361
398
@ Test
362
399
public void getModel_updateBackground_noLocalModel_error () throws Exception {
363
- when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME ))).thenReturn (null ).thenReturn (CUSTOM_MODEL );
400
+ when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME )))
401
+ .thenReturn (null )
402
+ .thenReturn (null )
403
+ .thenReturn (CUSTOM_MODEL );
364
404
when (mockModelDownloadService .getCustomModelDetails (
365
405
eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (null )))
366
406
.thenReturn (Tasks .forResult (CUSTOM_MODEL ));
@@ -421,7 +461,10 @@ public void getModel_local_noLocalModel() throws Exception {
421
461
422
462
@ Test
423
463
public void getModel_local_noLocalModel_error () throws Exception {
424
- when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME ))).thenReturn (null ).thenReturn (CUSTOM_MODEL );
464
+ when (mockPrefs .getCustomModelDetails (eq (MODEL_NAME )))
465
+ .thenReturn (null )
466
+ .thenReturn (null )
467
+ .thenReturn (CUSTOM_MODEL );
425
468
when (mockModelDownloadService .getCustomModelDetails (
426
469
eq (TEST_PROJECT_ID ), eq (MODEL_NAME ), eq (null )))
427
470
.thenReturn (Tasks .forResult (CUSTOM_MODEL ));
0 commit comments