@@ -81,6 +81,39 @@ void testSetJSON_JSONInjection() {
8181 assertEquals ("<script>alert('Hacked');</script>" , items .get (0 ).optString ("title" ));
8282 }
8383
84+ /**
85+ * ✅ Should treat a lone JSONObject under "items" the same as a one‑element
86+ * array.
87+ */
88+ @ Test
89+ void testSetJSON_handlesSingleItemObject () {
90+ JSONObject input = new JSONObject ()
91+ .put ("items" , new JSONObject ()
92+ .put ("title" , "Single Entry" )
93+ .put ("uid" , "entry123" )
94+ .put ("content_type" , "blog" ))
95+ .put ("skip" , 0 )
96+ .put ("total_count" , 1 )
97+ .put ("limit" , 10 )
98+ .put ("sync_token" , "token123" );
99+
100+ syncStack .setJSON (input );
101+ List <JSONObject > items = syncStack .getItems ();
102+
103+ assertNotNull (items , "Items list should be initialised" );
104+ assertEquals (1 , items .size (), "Exactly one item expected" );
105+
106+ JSONObject item = items .get (0 );
107+ assertEquals ("Single Entry" , item .optString ("title" ));
108+ assertEquals ("entry123" , item .optString ("uid" ));
109+ assertEquals ("blog" , item .optString ("content_type" ));
110+
111+ assertEquals (0 , syncStack .getSkip ());
112+ assertEquals (1 , syncStack .getCount ());
113+ assertEquals (10 , syncStack .getLimit ());
114+ assertEquals ("token123" , syncStack .getSyncToken ());
115+ }
116+
84117 /**
85118 * ✅ Test: Invalid `items` field (should not crash)
86119 */
0 commit comments