// Path: phial-overlay/src/main/java/com/mindcoders/phial/internal/keyvalue/KVJsonSerializer.java
// @VisibleForTesting
// static final String ENTRIES_KEY = "entries";
// 
// Path: phial-overlay/src/main/java/com/mindcoders/phial/internal/keyvalue/KVJsonSerializer.java
// @VisibleForTesting
// static final String NAME_KEY = "name";
// 
// Path: phial-overlay/src/main/java/com/mindcoders/phial/internal/keyvalue/KVJsonSerializer.java
// @VisibleForTesting
// static final String VALUE_KEY = "value";


import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.mindcoders.phial.internal.keyvalue.KVJsonSerializer.ENTRIES_KEY;
import static com.mindcoders.phial.internal.keyvalue.KVJsonSerializer.NAME_KEY;
import static com.mindcoders.phial.internal.keyvalue.KVJsonSerializer.VALUE_KEY;
import static org.junit.Assert.assertEquals;
package com.mindcoders.phial.internal.keyvalue;




/**
 * Created by rost on 11/14/17.
 */
// need to work with jsonObject
@RunWith(RobolectricTestRunner.class)
public class KVJsonSerializerTest {
    private KVJsonSerializer serializer;

    @Before
    public void setUp() throws Exception {
        serializer = new KVJsonSerializer();
    }

    @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));
// Path: phial-overlay/src/main/java/com/mindcoders/phial/internal/keyvalue/KVJsonSerializer.java
// @VisibleForTesting
// static final String ENTRIES_KEY = "entries";
// 
// Path: phial-overlay/src/main/java/com/mindcoders/phial/internal/keyvalue/KVJsonSerializer.java
// @VisibleForTesting
// static final String NAME_KEY = "name";
// 
// Path: phial-overlay/src/main/java/com/mindcoders/phial/internal/keyvalue/KVJsonSerializer.java
// @VisibleForTesting
// static final String VALUE_KEY = "value";


// Path: phial-overlay/src/test/java/com/mindcoders/phial/internal/keyvalue/KVJsonSerializerTest.java
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.mindcoders.phial.internal.keyvalue.KVJsonSerializer.ENTRIES_KEY;
import static com.mindcoders.phial.internal.keyvalue.KVJsonSerializer.NAME_KEY;
import static com.mindcoders.phial.internal.keyvalue.KVJsonSerializer.VALUE_KEY;
import static org.junit.Assert.assertEquals;

package com.mindcoders.phial.internal.keyvalue;




/**
 * Created by rost on 11/14/17.
 */
// need to work with jsonObject
@RunWith(RobolectricTestRunner.class)
public class KVJsonSerializerTest {
    private KVJsonSerializer serializer;

    @Before
    public void setUp() throws Exception {
        serializer = new KVJsonSerializer();
    }

    @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));