package com.speedment.runtime.internal.util.json;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Emil
 */
public class JsonTest {
    
    @Test
    public void testParse_String() {
        final String json = "{\"message\":\"Hello, World!\"}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        assertNotNull(map);
        assertEquals("Check value: ", "Hello, World!", map.get("message"));
    }
    
    @Test
    public void testParse_String2() {
        final String json = "{\"title\" : \"Greetings!\", \"message\" : \"Hello, World!\"}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        assertNotNull(map);
        assertEquals("Check value: ", "Hello, World!", map.get("message"));
        assertEquals("Check value: ", "Greetings!", map.get("title"));
    }
    
    @Test
    public void testParse_Long() {
        final String json = "{\"id\" : 5678}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        assertNotNull(map);
        assertEquals("Check value: ", 5678L, map.get("id"));
    }
    
    @Test
    public void testParse_Double() {
        final String json = "{\"average\" : 0.6789}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        assertNotNull(map);
        assertEquals("Check value: ", 0.6789, map.get("average"));
    }
    
    @Test
    public void testParse_False() {
        final String json = "{\"condition\" : false}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        assertNotNull(map);
        assertEquals("Check value: ", false, map.get("condition"));
    }
    
    @Test
    public void testParse_True() {
        final String json = "{\"condition\" : true}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        assertNotNull(map);
        assertEquals("Check value: ", true, map.get("condition"));
    }
    
    @Test
    public void testParse_Null() {
        final String json = "{\"random\" : null}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        assertNotNull(map);
        assertTrue("Key exists: ", map.containsKey("random"));
        assertNull("Check value: ", map.get("random"));
    }
    
    @Test
    public void testParse_Array() {
        final String json = "{\"items\" : [\"one\", \"two\", \"three\"]}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        final List<String> expected = Arrays.asList("one", "two", "three");
        assertNotNull(map);
        assertEquals("Check value: ", expected, map.get("items"));
    }
    
    @Test
    public void testParse_ArrayOfObjects() {
        final String json = "{\"numbers\" : [{\"one\":1}, {\"two\":2}, {\"three\":3}]}";
        final Map<String, Object> map = (Map<String, Object>) Json.fromJson(json);
        
        assertNotNull(map);
        final List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("numbers");
        
        assertEquals("Check one: ", 1L, list.get(0).get("one"));
        assertEquals("Check one: ", 2L, list.get(1).get("two"));
        assertEquals("Check one: ", 3L, list.get(2).get("three"));
    }
}

@@ -330,32 +330,71 @@
 lo, World!%5C%22%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         final Ma
@@ -452,32 +452,32 @@
 fromJson(json);%0A
-
         assertNo
@@ -708,32 +708,71 @@
 lo, World!%5C%22%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         final Ma
@@ -1112,24 +1112,63 @@
 %22 : 5678%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -1435,24 +1435,63 @@
 : 0.6789%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -1764,24 +1764,63 @@
  : false%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -2092,24 +2092,63 @@
 %22 : true%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -2416,24 +2416,63 @@
 %22 : null%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -2817,24 +2817,63 @@
 three%5C%22%5D%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -3265,24 +3265,63 @@
 ee%5C%22:3%7D%5D%7D%22;%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         fina
@@ -3392,32 +3392,32 @@
 json);%0A        %0A
-
         assertNo
@@ -3420,32 +3420,71 @@
 rtNotNull(map);%0A
+        @SuppressWarnings(%22unchecked%22)%0A
         final Li

Fix warnings