PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/com/google/ie/common/util/GsonUtilityTest.java

http://thoughtsite.googlecode.com/
Java | 66 lines | 31 code | 11 blank | 24 comment | 0 complexity | 78fe71a23576db71b67dd4a02d45b1ea MD5 | raw file
 1// Copyright 2009 Google Inc. All Rights Reserved.
 2/**
 3 * 
 4 */
 5package com.google.ie.common.util;
 6
 7import static org.junit.Assert.assertEquals;
 8
 9import com.google.ie.business.domain.IdeaCategory;
10import com.google.ie.test.ServiceTest;
11
12import org.junit.Before;
13import org.junit.Test;
14
15import java.util.HashMap;
16
17/**
18 * Test class for GsonUtility class
19 * 
20 * @author ssbains
21 * 
22 */
23public class GsonUtilityTest extends ServiceTest {
24
25    /**
26     */
27    @Before
28    public void setUp() {
29        super.setUp();
30    }
31
32    /**
33     * Test method for
34     * {@link com.google.ie.common.util.GsonUtility#convertToJson(java.lang.Object)}
35     * .
36     */
37    @Test
38    public void convertToJson() {
39        HashMap<String, String> hashMap = new HashMap<String, String>();
40        hashMap.put("Education", "key1");
41        hashMap.put("Sports", "key123");
42
43        String expected = "{" + "\"Education\":\"key1\",\"Sports\":\"key123\"" + "}";
44        String actual = GsonUtility.convertToJson(hashMap);
45
46        assertEquals(expected, actual);
47    }
48
49    @Test
50    /**
51     * Test method for
52     * {@link com.google.ie.common.util.GsonUtility#convertFromJson(java.lang.String,Class<T>)}
53     * .
54     */
55    public void convertFromJson() {
56        IdeaCategory expectedCategory = new IdeaCategory();
57        expectedCategory.setKey("jsonTestCategory");
58        expectedCategory.setName("testGsonUtility");
59        /* Convert to json */
60        String jsonString = GsonUtility.convertToJson(expectedCategory);
61        /* Convert back from json */
62        IdeaCategory actualCategory = GsonUtility.convertFromJson(jsonString, IdeaCategory.class);
63        assertEquals(expectedCategory.getKey(), actualCategory.getKey());
64    }
65
66}