package org.luxons.sevenwonders.game.data.serializers;

import org.junit.Before;
import org.junit.Test;
import org.luxons.sevenwonders.game.resources.ResourceType;
import org.luxons.sevenwonders.game.resources.Resources;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import static org.junit.Assert.*;

public class ResourcesSerializerTest {

    private Gson gson;

    @Before
    public void setUp() {
        gson = new GsonBuilder().registerTypeAdapter(Resources.class, new ResourcesSerializer()).create();
    }

    @Test
    public void serialize_null() {
        assertEquals("null", gson.toJson(null, Resources.class));
    }

    @Test
    public void serialize_emptyResourcesToNull() {
        Resources resources = new Resources();
        assertEquals("null", gson.toJson(resources, Resources.class));
    }

    @Test
    public void serialize_singleType() {
        Resources resources = new Resources();
        resources.add(ResourceType.WOOD, 1);
        assertEquals("\"W\"", gson.toJson(resources, Resources.class));
    }

    @Test
    public void serialize_multipleTimesSameType() {
        Resources resources = new Resources();
        resources.add(ResourceType.WOOD, 3);
        assertEquals("\"WWW\"", gson.toJson(resources, Resources.class));
    }

    @Test
    public void serialize_mixedTypes() {
        Resources resources = new Resources();
        resources.add(ResourceType.WOOD, 1);
        resources.add(ResourceType.STONE, 1);
        resources.add(ResourceType.CLAY, 1);
        assertEquals("\"WSC\"", gson.toJson(resources, Resources.class));
    }

    @Test
    public void serialize_mixedTypes_unordered() {
        Resources resources = new Resources();
        resources.add(ResourceType.CLAY, 1);
        resources.add(ResourceType.WOOD, 2);
        resources.add(ResourceType.CLAY, 1);
        resources.add(ResourceType.STONE, 1);
        assertEquals("\"WWSCC\"", gson.toJson(resources, Resources.class));
    }

    @Test
    public void deserialize_null() {
        assertNull(gson.fromJson("null", Resources.class));
    }

    @Test
    public void deserialize_emptyList() {
        Resources resources = new Resources();
        assertEquals(resources, gson.fromJson("\"\"", Resources.class));
    }

    @Test
    public void deserialize_singleType() {
        Resources resources = new Resources();
        resources.add(ResourceType.WOOD, 1);
        assertEquals(resources, gson.fromJson("\"W\"", Resources.class));
    }

    @Test
    public void deserialize_multipleTimesSameType() {
        Resources resources = new Resources();
        resources.add(ResourceType.WOOD, 3);
        assertEquals(resources, gson.fromJson("\"WWW\"", Resources.class));
    }

    @Test
    public void deserialize_mixedTypes() {
        Resources resources = new Resources();
        resources.add(ResourceType.WOOD, 1);
        resources.add(ResourceType.CLAY, 1);
        resources.add(ResourceType.STONE, 1);
        assertEquals(resources, gson.fromJson("\"WCS\"", Resources.class));
    }

    @Test
    public void deserialize_mixedTypes_unordered() {
        Resources resources = new Resources();
        resources.add(ResourceType.WOOD, 1);
        resources.add(ResourceType.CLAY, 2);
        resources.add(ResourceType.STONE, 3);
        assertEquals(resources, gson.fromJson("\"SCWCSS\"", Resources.class));
    }
}
@@ -807,37 +807,20 @@
 esources
-, Resources.class
 ));%0A
+
     %7D%0A%0A 
@@ -1012,33 +1012,16 @@
 esources
-, Resources.class
 ));%0A    
@@ -1230,33 +1230,16 @@
 esources
-, Resources.class
 ));%0A    
@@ -1528,33 +1528,16 @@
 esources
-, Resources.class
 ));%0A    
@@ -1820,32 +1820,32 @@
 Type.STONE, 1);%0A
+
         assertEq
@@ -1883,33 +1883,16 @@
 esources
-, Resources.class
 ));%0A    

Remove explicit types from toJson calls