21
21
import static org .junit .Assert .assertTrue ;
22
22
import static org .junit .Assert .fail ;
23
23
24
+ import android .util .Log ;
24
25
import androidx .annotation .NonNull ;
25
26
import androidx .test .ext .junit .runners .AndroidJUnit4 ;
26
-
27
27
import com .google .android .gms .tasks .Continuation ;
28
28
import com .google .android .gms .tasks .OnCompleteListener ;
29
29
import com .google .android .gms .tasks .Task ;
@@ -3409,15 +3409,16 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
3409
3409
@ Test
3410
3410
public void emptyQueryGet () throws DatabaseException , InterruptedException {
3411
3411
DatabaseReference node = IntegrationTestHelpers .getRandomNode ();
3412
+ DatabaseConfig cfg = IntegrationTestHelpers .newTestConfig ();
3412
3413
final Semaphore semaphore = new Semaphore (0 );
3413
3414
node .get ()
3414
3415
.addOnCompleteListener (
3415
3416
new OnCompleteListener <DataSnapshot >() {
3416
3417
@ Override
3417
3418
public void onComplete (@ NonNull Task <DataSnapshot > task ) {
3418
3419
assertTrue (task .isSuccessful ());
3419
- assertNotNull (task .getResult ());
3420
- assertFalse (task .getResult ().exists () );
3420
+ assertNotNull (task .getException ());
3421
+ assertEquals (task .getException ().getMessage (), "Client offline with empty cache!" );
3421
3422
semaphore .release ();
3422
3423
}
3423
3424
});
@@ -3430,60 +3431,67 @@ public void offlineQueryGet() throws DatabaseException {
3430
3431
IntegrationTestHelpers .goOffline (cfg );
3431
3432
DatabaseReference node = IntegrationTestHelpers .getRandomNode ();
3432
3433
node .get ()
3433
- .addOnCompleteListener (new OnCompleteListener <DataSnapshot >() {
3434
- @ Override
3435
- public void onComplete (@ NonNull Task <DataSnapshot > task ) {
3436
- assertFalse (task .isSuccessful ());
3437
- assertTrue (task .isCanceled ());
3438
- assertNotNull (task .getException ());
3439
- assertEquals (task .getException ().getMessage (), "Client offline with empty cache!" );
3440
- }
3441
- });
3434
+ .addOnCompleteListener (
3435
+ new OnCompleteListener <DataSnapshot >() {
3436
+ @ Override
3437
+ public void onComplete (@ NonNull Task <DataSnapshot > task ) {
3438
+ Log .d ("QueryTest" , "offlineQueryGet onCompleteListener running." );
3439
+ assertFalse (task .isSuccessful ());
3440
+ assertNotNull (task .getException ());
3441
+ assertEquals (task .getException ().getMessage (), "Client offline with empty cache!" );
3442
+ }
3443
+ });
3442
3444
}
3443
3445
3444
3446
@ Test
3445
3447
public void getQueryBasic () throws DatabaseException , InterruptedException {
3446
3448
DatabaseReference ref = IntegrationTestHelpers .getRandomNode ();
3447
3449
final Semaphore semaphore = new Semaphore (0 );
3448
- ref .setValue (42 ).continueWithTask (new Continuation <Void , Task <DataSnapshot >>() {
3449
- @ Override
3450
- public Task <DataSnapshot > then (@ NonNull Task <Void > task ) throws Exception {
3451
- assertTrue (task .isSuccessful ());
3452
- return ref .get ()
3453
- .addOnCompleteListener (new OnCompleteListener <DataSnapshot >() {
3454
- @ Override
3455
- public void onComplete (@ NonNull Task <DataSnapshot > task ) {
3456
- assertTrue (task .isSuccessful ());
3457
- DataSnapshot snap = task .getResult ();
3458
- assertNotNull (snap );
3459
- assertEquals (42 , snap .getValue ());
3460
- semaphore .release ();
3461
- }
3462
- });
3463
- }
3464
- });
3450
+ ref .setValue (42 )
3451
+ .continueWithTask (
3452
+ new Continuation <Void , Task <DataSnapshot >>() {
3453
+ @ Override
3454
+ public Task <DataSnapshot > then (@ NonNull Task <Void > task ) throws Exception {
3455
+ assertTrue (task .isSuccessful ());
3456
+ return ref .get ()
3457
+ .addOnCompleteListener (
3458
+ new OnCompleteListener <DataSnapshot >() {
3459
+ @ Override
3460
+ public void onComplete (@ NonNull Task <DataSnapshot > task ) {
3461
+ assertTrue (task .isSuccessful ());
3462
+ DataSnapshot snap = task .getResult ();
3463
+ assertNotNull (snap );
3464
+ assertEquals (42 , snap .getValue ());
3465
+ semaphore .release ();
3466
+ }
3467
+ });
3468
+ }
3469
+ });
3465
3470
IntegrationTestHelpers .waitFor (semaphore );
3466
3471
}
3467
3472
3468
3473
@ Test
3469
- public void getQueryCached () throws DatabaseException , InterruptedException , TimeoutException , TestFailure {
3474
+ public void getQueryCached ()
3475
+ throws DatabaseException , InterruptedException , TimeoutException , TestFailure {
3470
3476
DatabaseReference ref = IntegrationTestHelpers .getRandomNode ();
3471
3477
DatabaseConfig cfg = IntegrationTestHelpers .newTestConfig ();
3472
3478
ReadFuture future = ReadFuture .untilNonNull (ref );
3473
3479
ref .setValue (42 );
3474
3480
assertEquals (42 , future .waitForLastValue ());
3475
3481
IntegrationTestHelpers .goOffline (cfg );
3476
3482
final Semaphore semaphore = new Semaphore (0 );
3477
- ref .get ().addOnCompleteListener (new OnCompleteListener <DataSnapshot >() {
3478
- @ Override
3479
- public void onComplete (@ NonNull Task <DataSnapshot > task ) {
3480
- assertTrue (task .isSuccessful ());
3481
- DataSnapshot snapshot = task .getResult ();
3482
- assertNotNull (snapshot );
3483
- assertEquals (42 , snapshot .getValue ());
3484
- semaphore .release ();
3485
- }
3486
- });
3483
+ ref .get ()
3484
+ .addOnCompleteListener (
3485
+ new OnCompleteListener <DataSnapshot >() {
3486
+ @ Override
3487
+ public void onComplete (@ NonNull Task <DataSnapshot > task ) {
3488
+ assertTrue (task .isSuccessful ());
3489
+ DataSnapshot snapshot = task .getResult ();
3490
+ assertNotNull (snapshot );
3491
+ assertEquals (42 , snapshot .getValue ());
3492
+ semaphore .release ();
3493
+ }
3494
+ });
3487
3495
IntegrationTestHelpers .waitFor (semaphore );
3488
3496
}
3489
3497
0 commit comments