@@ -463,14 +463,14 @@ public void testNewTransactionCommit() {
463
463
transaction .commit ();
464
464
fail ("Expecting a failure" );
465
465
} catch (DatastoreException expected ) {
466
- assertEquals ( "FAILED_PRECONDITION" , expected . getReason () );
466
+ assertDatastoreException ( expected , "FAILED_PRECONDITION" , 0 );
467
467
}
468
468
469
469
try {
470
470
transaction .rollback ();
471
471
fail ("Expecting a failure" );
472
472
} catch (DatastoreException expected ) {
473
- assertEquals ( "FAILED_PRECONDITION" , expected . getReason () );
473
+ assertDatastoreException ( expected , "FAILED_PRECONDITION" , 0 );
474
474
}
475
475
}
476
476
@@ -666,7 +666,7 @@ public void testNewTransactionRollback() {
666
666
transaction .commit ();
667
667
fail ("Expecting a failure" );
668
668
} catch (DatastoreException expected ) {
669
- assertEquals ( "FAILED_PRECONDITION" , expected . getReason () );
669
+ assertDatastoreException ( expected , "FAILED_PRECONDITION" , 0 );
670
670
}
671
671
672
672
List <Entity > list = datastore .fetch (KEY1 , KEY2 , KEY3 );
@@ -718,7 +718,7 @@ public void testNewBatch() {
718
718
batch .submit ();
719
719
fail ("Expecting a failure" );
720
720
} catch (DatastoreException expected ) {
721
- assertEquals ( "FAILED_PRECONDITION" , expected . getReason () );
721
+ assertDatastoreException ( expected , "FAILED_PRECONDITION" , 0 );
722
722
}
723
723
724
724
batch = datastore .newBatch ();
@@ -1430,7 +1430,7 @@ public void testGetArrayNoDeferredResults() {
1430
1430
entity3 .getString ("str" );
1431
1431
fail ("Expecting a failure" );
1432
1432
} catch (DatastoreException expected ) {
1433
- // expected - no such property
1433
+ assertDatastoreException ( expected , "FAILED_PRECONDITION" , 0 );
1434
1434
}
1435
1435
assertFalse (result .hasNext ());
1436
1436
datastore .delete (ENTITY3 .getKey ());
@@ -1447,7 +1447,7 @@ public void testAddEntity() {
1447
1447
datastore .add (ENTITY1 );
1448
1448
fail ("Expecting a failure" );
1449
1449
} catch (DatastoreException expected ) {
1450
- // expected;
1450
+ assertDatastoreException ( expected , "ALREADY_EXISTS" , 6 ) ;
1451
1451
}
1452
1452
1453
1453
List <Entity > entities = datastore .add (ENTITY3 , PARTIAL_ENTITY1 , PARTIAL_ENTITY2 );
@@ -1475,7 +1475,7 @@ public void testUpdate() {
1475
1475
datastore .update (ENTITY3 );
1476
1476
fail ("Expecting a failure" );
1477
1477
} catch (DatastoreException expected ) {
1478
- // expected;
1478
+ assertDatastoreException ( expected , "NOT_FOUND" , 5 ) ;
1479
1479
}
1480
1480
datastore .add (ENTITY3 );
1481
1481
assertEquals (ENTITY3 , datastore .get (ENTITY3 .getKey ()));
@@ -1566,7 +1566,7 @@ public Integer run(DatastoreReaderWriter transaction) {
1566
1566
datastore .runInTransaction (callable2 );
1567
1567
fail ("Expecting a failure" );
1568
1568
} catch (DatastoreException expected ) {
1569
- assertEquals ( 4 , (( DatastoreException ) expected .getCause ()). getCode () );
1569
+ assertDatastoreException (( DatastoreException ) expected .getCause (), "DEADLINE_EXCEEDED" , 4 );
1570
1570
}
1571
1571
}
1572
1572
@@ -1620,7 +1620,7 @@ public Integer run(DatastoreReaderWriter transaction) {
1620
1620
datastore .runInTransaction (callable2 , readOnlyOptions );
1621
1621
fail ("Expecting a failure" );
1622
1622
} catch (DatastoreException expected ) {
1623
- assertEquals ( 3 , (( DatastoreException ) expected .getCause ()). getCode () );
1623
+ assertDatastoreException (( DatastoreException ) expected .getCause (), "INVALID_ARGUMENT" , 3 );
1624
1624
}
1625
1625
}
1626
1626
@@ -1836,4 +1836,10 @@ private void testCountAggregationReadTimeWith(Consumer<AggregationQuery.Builder>
1836
1836
datastore .delete (entity1 .getKey (), entity2 .getKey (), entity3 .getKey ());
1837
1837
}
1838
1838
}
1839
+
1840
+ private void assertDatastoreException (
1841
+ DatastoreException expected , String reason , int statusCode ) {
1842
+ assertEquals (reason , expected .getReason ());
1843
+ assertEquals (statusCode , expected .getCode ());
1844
+ }
1839
1845
}
0 commit comments