### Question:
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; }    }### Answer:
@Test public void createCategoriesArray_returns_empty_array_for_empty_collection() throws Exception { final JSONArray array = serializer.createCategoriesArray(Collections.emptyList()); assertEquals(0, array.length()); }
@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)); }