@Test public void createCategoryObject() throws Exception { final KVSaver.KVCategory testCategory = new KVSaver.KVCategory("cat", Arrays.asList( new KVSaver.KVEntry("k1", "v1"), new KVSaver.KVEntry("k2", "v2") )); final JSONObject category = serializer.createCategoryObject(testCategory); assertEquals("cat", category.getString(NAME_KEY)); final JSONArray entries = category.getJSONArray(ENTRIES_KEY); assertEquals(2, entries.length()); assertEquals("k1", entries.getJSONObject(0).getString(NAME_KEY)); assertEquals("v1", entries.getJSONObject(0).getString(VALUE_KEY)); assertEquals("k2", entries.getJSONObject(1).getString(NAME_KEY)); assertEquals("v2", entries.getJSONObject(1).getString(VALUE_KEY)); }
@VisibleForTesting @NonNull JSONObject createCategoryObject(KVCategory category) throws JSONException { final JSONObject categoryJsonObject = new JSONObject(); categoryJsonObject.put(NAME_KEY, category.getName()); final JSONArray entriesJsonArray = new JSONArray(); for (KVSaver.KVEntry entry : category.entries()) { final JSONObject entryJsonObject = new JSONObject(); entryJsonObject.put(NAME_KEY, entry.getName()); entryJsonObject.put(VALUE_KEY, entry.getValue()); entriesJsonArray.put(entryJsonObject); } categoryJsonObject.put(ENTRIES_KEY, entriesJsonArray); return categoryJsonObject; }
KVJsonSerializer { @VisibleForTesting @NonNull JSONObject createCategoryObject(KVCategory category) throws JSONException { final JSONObject categoryJsonObject = new JSONObject(); categoryJsonObject.put(NAME_KEY, category.getName()); final JSONArray entriesJsonArray = new JSONArray(); for (KVSaver.KVEntry entry : category.entries()) { final JSONObject entryJsonObject = new JSONObject(); entryJsonObject.put(NAME_KEY, entry.getName()); entryJsonObject.put(VALUE_KEY, entry.getValue()); entriesJsonArray.put(entryJsonObject); } categoryJsonObject.put(ENTRIES_KEY, entriesJsonArray); return categoryJsonObject; } }
KVJsonSerializer { @VisibleForTesting @NonNull JSONObject createCategoryObject(KVCategory category) throws JSONException { final JSONObject categoryJsonObject = new JSONObject(); categoryJsonObject.put(NAME_KEY, category.getName()); final JSONArray entriesJsonArray = new JSONArray(); for (KVSaver.KVEntry entry : category.entries()) { final JSONObject entryJsonObject = new JSONObject(); entryJsonObject.put(NAME_KEY, entry.getName()); entryJsonObject.put(VALUE_KEY, entry.getValue()); entriesJsonArray.put(entryJsonObject); } categoryJsonObject.put(ENTRIES_KEY, entriesJsonArray); return categoryJsonObject; }  }
KVJsonSerializer { @VisibleForTesting @NonNull JSONObject createCategoryObject(KVCategory category) throws JSONException { final JSONObject categoryJsonObject = new JSONObject(); categoryJsonObject.put(NAME_KEY, category.getName()); final JSONArray entriesJsonArray = new JSONArray(); for (KVSaver.KVEntry entry : category.entries()) { final JSONObject entryJsonObject = new JSONObject(); entryJsonObject.put(NAME_KEY, entry.getName()); entryJsonObject.put(VALUE_KEY, entry.getValue()); entriesJsonArray.put(entryJsonObject); } categoryJsonObject.put(ENTRIES_KEY, entriesJsonArray); return categoryJsonObject; }   }
KVJsonSerializer { @VisibleForTesting @NonNull JSONObject createCategoryObject(KVCategory category) throws JSONException { final JSONObject categoryJsonObject = new JSONObject(); categoryJsonObject.put(NAME_KEY, category.getName()); final JSONArray entriesJsonArray = new JSONArray(); for (KVSaver.KVEntry entry : category.entries()) { final JSONObject entryJsonObject = new JSONObject(); entryJsonObject.put(NAME_KEY, entry.getName()); entryJsonObject.put(VALUE_KEY, entry.getValue()); entriesJsonArray.put(entryJsonObject); } categoryJsonObject.put(ENTRIES_KEY, entriesJsonArray); return categoryJsonObject; }    }