@@ -879,10 +879,11 @@ public void userAgent() throws Exception {
879
879
public void getObjectAttributes () throws AlgoliaException {
880
880
for (String id : ids ) {
881
881
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 ));
886
887
}
887
888
}
888
889
@@ -892,13 +893,14 @@ public void getObjectsAttributes() throws AlgoliaException {
892
893
JSONArray results = index .getObjects (ids ).getJSONArray ("results" );
893
894
for (int i = 0 ; i < results .length (); i ++) {
894
895
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`
896
897
}
897
- results = index .getObjects (ids , Collections .singletonList ("objectID " )).getJSONArray ("results" );
898
+ results = index .getObjects (ids , Collections .singletonList ("city " )).getJSONArray ("results" );
898
899
for (int i = 0 ; i < results .length (); i ++) {
899
900
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 ));
902
904
}
903
905
} catch (JSONException e ) {
904
906
fail (e .getMessage ());
0 commit comments