@@ -688,9 +688,12 @@ public void testAllocateId() {
688688 assertNotEquals (key1 , key2 );
689689 assertEquals (Key .newBuilder (pk1 , key2 .getId ()).build (), key2 );
690690
691- Key key3 = datastore .allocateId (key1 );
692- assertNotEquals (key1 , key3 );
693- assertEquals (Key .newBuilder (pk1 , key3 .getId ()).build (), key3 );
691+ try {
692+ datastore .allocateId (key1 );
693+ fail ("Expecting a failure" );
694+ } catch (IllegalArgumentException expected ) {
695+ assertEquals (expected .getMessage (), "keys must be IncompleteKey instances" );
696+ }
694697 }
695698
696699 @ Test
@@ -700,16 +703,20 @@ public void testAllocateIdArray() {
700703 IncompleteKey incompleteKey2 =
701704 keyFactory .setKind (KIND2 ).addAncestor (PathElement .of (KIND1 , 10 )).newKey ();
702705 Key key3 = keyFactory .newKey ("name" );
703- Key key4 = keyFactory .newKey (1 );
704- List <Key > result =
705- datastore .allocateId (incompleteKey1 , incompleteKey2 , key3 , key4 , incompleteKey1 , key3 );
706- assertEquals (6 , result .size ());
707- assertEquals (Key .newBuilder (incompleteKey1 , result .get (0 ).getId ()).build (), result .get (0 ));
708- assertEquals (Key .newBuilder (incompleteKey1 , result .get (4 ).getId ()).build (), result .get (4 ));
709- assertEquals (Key .newBuilder (incompleteKey2 , result .get (1 ).getId ()).build (), result .get (1 ));
710- assertEquals (Key .newBuilder (key3 ).setId (result .get (2 ).getId ()).build (), result .get (2 ));
711- assertEquals (Key .newBuilder (key3 ).setId (result .get (5 ).getId ()).build (), result .get (5 ));
712- assertEquals (Key .newBuilder (key4 ).setId (result .get (3 ).getId ()).build (), result .get (3 ));
706+ List <Key > result1 =
707+ datastore .allocateId (incompleteKey1 , incompleteKey2 , incompleteKey1 );
708+ assertEquals (3 , result1 .size ());
709+ assertEquals (Key .newBuilder (incompleteKey1 , result1 .get (0 ).getId ()).build (), result1 .get (0 ));
710+ assertEquals (Key .newBuilder (incompleteKey1 , result1 .get (2 ).getId ()).build (), result1 .get (2 ));
711+ assertEquals (Key .newBuilder (incompleteKey2 , result1 .get (1 ).getId ()).build (), result1 .get (1 ));
712+
713+ try {
714+ datastore .allocateId (incompleteKey1 , incompleteKey2 , key3 );
715+ fail ("expecting a failure" );
716+ } catch (IllegalArgumentException expected ) {
717+ assertEquals (expected .getMessage (), "keys must be IncompleteKey instances" );
718+
719+ }
713720 }
714721
715722 @ Test
0 commit comments