package com.sailthru.client;

import java.util.ArrayList;
import java.util.HashMap;
import junit.framework.TestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Map;

/**
 *
 * @author Prajwal Tuladhar <praj@sailthru.com> <praj@sailthru.com>
 */
public class SailthruUtilTest extends TestCase {
    protected static Logger log = LoggerFactory.getLogger(SailthruUtilTest.class);
    protected Gson gson;
    public void testMd5() {
        String plainText1 = "hello_world";
        String hash1 = SailthruUtil.md5(plainText1);
        log.debug(hash1);
        String expectedHash1 = "99b1ff8f11781541f7f89f9bd41c4a17";
        assertEquals(hash1, expectedHash1);
    }
    
    public void testArrayListToCSV() {
        java.util.List<String> list1 = new ArrayList<String>();
        list1.add("windows");
        list1.add("linux");
        list1.add("BSD");
        String expectedList1 = "windows,linux,BSD";
        assertEquals(expectedList1, SailthruUtil.arrayListToCSV(list1));
        
        java.util.List<String> list2 = new ArrayList<String>();
        list2.add("one_item");
        String expectedList2 = "one_item";
        assertEquals(expectedList2, SailthruUtil.arrayListToCSV(list2));
    }

    public void testGson() {
        gson = SailthruUtil.createGson();
        java.util.Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("var1","value1");
        map1.put("var2","value2");
        String expectedmap1 = "{\"var1\":\"value1\",\"var2\":\"value2\"}";
        assertEquals(expectedmap1, gson.toJson(map1));

        java.util.Map<String, Object> map2 = new HashMap<String, Object>();
        String expectedmap2 = "{}";
        assertEquals(expectedmap2, gson.toJson(map2));

        java.util.Map<String, Object> map3 = new HashMap<String, Object>();
        map3.put("var1",null);
        map3.put("var2","value2");
        String expectedmap3 = "{\"var1\":null,\"var2\":\"value2\"}";
        assertEquals(expectedmap3, gson.toJson(map3));

        java.util.Map<String, Object> map4 = new HashMap<String, Object>();
        java.util.Map<String, Object> map5 = new HashMap<String, Object>();
        map5.put("var1",null);
        map4.put("var1",map5);
        java.util.Map<String, Object> map6 = new HashMap<String, Object>();
        map6.put("var2","value2");
        map4.put("var2",map6);
        String expectedmap4 = "{\"var1\":{\"var1\":null},\"var2\":{\"var2\":\"value2\"}}";
        assertEquals(expectedmap4, gson.toJson(map4));
    }
    
    public void testGsonNull() {
        gson = SailthruUtil.createGson();
        Map map = new HashMap();
        map.put("baz", null);
        
        String expected = "{\"baz\":null}";
        String result = gson.toJson(map);
        
        assertEquals(expected, result);
    }
}

@@ -81,39 +81,30 @@
 ap;%0A
+%0A
 import 
+org.
 junit.
-framework.TestCase
+Test
 ;%0Aim
@@ -198,57 +198,67 @@
 ort 
-com.google.gson.GsonBuilder;%0Aimport java.util.Map
+java.util.Map;%0A%0Aimport static org.junit.Assert.assertEquals
 ;%0A%0A/
@@ -369,25 +369,8 @@
 est 
-extends TestCase 
 %7B%0A  
@@ -474,16 +474,27 @@
 on gson;
+%0A%0A    @Test
 %0A    pub
@@ -750,32 +750,42 @@
 h1);%0A    %7D%0A    %0A
+    @Test%0A
     public void 
@@ -1307,16 +1307,26 @@
 %0A    %7D%0A%0A
+    @Test%0A
     publ
@@ -2609,24 +2609,34 @@
 %0A    %7D%0A    %0A
+    @Test%0A
     public v

use @Test annotation in SailthruUtilTest tests