@Test public void createCategoriesArray_returns_correct_json_object() throws Exception { final List<KVSaver.KVCategory> testCategories = Arrays.asList( new KVSaver.KVCategory("cat", Collections.singletonList( new KVSaver.KVEntry("k1", "v1"))), new KVSaver.KVCategory("cat", Collections.emptyList()) ); final JSONArray categories = serializer.createCategoriesArray(testCategories); assertEquals(1, categories.length()); assertEquals("cat", categories.getJSONObject(0).getString(NAME_KEY)); }
@VisibleForTesting @NonNull JSONArray createCategoriesArray(List<KVCategory> categories) throws JSONException { final JSONArray categoriesJsonArray = new JSONArray(); for (KVCategory category : categories) { if (category.isEmpty()) { continue; } final JSONObject categoryJsonObject = createCategoryObject(category); categoriesJsonArray.put(categoryJsonObject); } return categoriesJsonArray; }
KVJsonSerializer { @VisibleForTesting @NonNull JSONArray createCategoriesArray(List<KVCategory> categories) throws JSONException { final JSONArray categoriesJsonArray = new JSONArray(); for (KVCategory category : categories) { if (category.isEmpty()) { continue; } final JSONObject categoryJsonObject = createCategoryObject(category); categoriesJsonArray.put(categoryJsonObject); } return categoriesJsonArray; } }
KVJsonSerializer { @VisibleForTesting @NonNull JSONArray createCategoriesArray(List<KVCategory> categories) throws JSONException { final JSONArray categoriesJsonArray = new JSONArray(); for (KVCategory category : categories) { if (category.isEmpty()) { continue; } final JSONObject categoryJsonObject = createCategoryObject(category); categoriesJsonArray.put(categoryJsonObject); } return categoriesJsonArray; }  }
KVJsonSerializer { @VisibleForTesting @NonNull JSONArray createCategoriesArray(List<KVCategory> categories) throws JSONException { final JSONArray categoriesJsonArray = new JSONArray(); for (KVCategory category : categories) { if (category.isEmpty()) { continue; } final JSONObject categoryJsonObject = createCategoryObject(category); categoriesJsonArray.put(categoryJsonObject); } return categoriesJsonArray; }   }
KVJsonSerializer { @VisibleForTesting @NonNull JSONArray createCategoriesArray(List<KVCategory> categories) throws JSONException { final JSONArray categoriesJsonArray = new JSONArray(); for (KVCategory category : categories) { if (category.isEmpty()) { continue; } final JSONObject categoryJsonObject = createCategoryObject(category); categoriesJsonArray.put(categoryJsonObject); } return categoriesJsonArray; }    }