@@ -879,10 +879,11 @@ public void userAgent() throws Exception {
879879 public void getObjectAttributes () throws AlgoliaException {
880880 for (String id : ids ) {
881881 JSONObject object = index .getObject (id );
882- assertEquals ("The retrieved object should have two attributes." , 2 , object .names ().length ());
883- object = index .getObject (id , Collections .singletonList ("objectID" ));
884- assertEquals ("The retrieved object should have only one attribute." , 1 , object .names ().length ());
885- assertTrue ("The retrieved object should have one objectID attribute." , object .optString ("objectID" , "" ).length () > 0 );
882+ assertEquals ("The retrieved object should have 3 attributes." , 3 , object .names ().length ()); // 2 attributes + `objectID`
883+ object = index .getObject (id , Collections .singletonList ("city" ));
884+ assertEquals ("The retrieved object should have 2 attributes." , 2 , object .names ().length ()); // 1 attribute + `objectID`
885+ assertNotNull ("The retrieved object should have an `objectID` attribute." , object .optString ("objectID" , null ));
886+ assertNotNull ("The retrieved object should have a `city` attribute." , object .optString ("city" , null ));
886887 }
887888 }
888889
@@ -892,13 +893,14 @@ public void getObjectsAttributes() throws AlgoliaException {
892893 JSONArray results = index .getObjects (ids ).getJSONArray ("results" );
893894 for (int i = 0 ; i < results .length (); i ++) {
894895 JSONObject object = results .getJSONObject (i );
895- assertEquals ("The retrieved object should have two attributes." , 2 , object .names ().length ());
896+ assertEquals ("The retrieved object should have 3 attributes." , 3 , object .names ().length ()); // 2 attributes + `objectID`
896897 }
897- results = index .getObjects (ids , Collections .singletonList ("objectID " )).getJSONArray ("results" );
898+ results = index .getObjects (ids , Collections .singletonList ("city " )).getJSONArray ("results" );
898899 for (int i = 0 ; i < results .length (); i ++) {
899900 JSONObject object = results .getJSONObject (i );
900- assertEquals ("The retrieved object should have only one attribute." , 1 , object .names ().length ());
901- assertTrue ("The retrieved object should have one objectID attribute." , object .optString ("objectID" , "" ).length () > 0 );
901+ assertEquals ("The retrieved object should have 2 attributes." , 2 , object .names ().length ()); // 1 attribute + `objectID`
902+ assertNotNull ("The retrieved object should have an `objectID` attribute." , object .optString ("objectID" , null ));
903+ assertNotNull ("The retrieved object should have a `city` attribute." , object .optString ("city" , null ));
902904 }
903905 } catch (JSONException e ) {
904906 fail (e .getMessage ());
0 commit comments