OSDN Git Service

JUnit 4.12 対応
[jovsonz/Jovsonz.git] / src / test / java / jp / sourceforge / jovsonz / JsPairTest.java
1 /*
2  * License : The MIT License
3  * Copyright(c) 2009 olyutorskii
4  */
5
6 package jp.sourceforge.jovsonz;
7
8 import org.junit.After;
9 import org.junit.AfterClass;
10 import org.junit.Before;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13
14 import static org.junit.Assert.*;
15
16 /**
17  *
18  */
19 public class JsPairTest {
20
21     public JsPairTest() {
22     }
23
24     @BeforeClass
25     public static void setUpClass() throws Exception{
26     }
27
28     @AfterClass
29     public static void tearDownClass() throws Exception{
30     }
31
32     @Before
33     public void setUp() {
34     }
35
36     @After
37     public void tearDown() {
38     }
39
40     /**
41      * Test of Constructor, of class JsPair.
42      */
43     @Test
44     public void testConstructor(){
45         System.out.println("constructor");
46
47         JsPair pair = null;
48
49         try{
50             pair = new JsPair(null, 3);
51             fail();
52         }catch(NullPointerException e){
53             // NOTHING
54         }
55
56         try{
57             pair = new JsPair("three", (String)null);
58             fail();
59         }catch(NullPointerException e){
60             // NOTHING
61         }
62
63         try{
64             pair = new JsPair(null, (String)null);
65             fail();
66         }catch(NullPointerException e){
67             // NOTHING
68         }
69
70         try{
71             pair = new JsPair("three", (JsValue)null);
72             fail();
73         }catch(NullPointerException e){
74             // NOTHING
75         }
76
77         try{
78             pair = new JsPair(null, (JsValue)null);
79             fail();
80         }catch(NullPointerException e){
81             // NOTHING
82         }
83
84         assertNull(pair);
85
86         return;
87     }
88
89     /**
90      * Test of getName method, of class JsPair.
91      */
92     @Test
93     public void testGetName(){
94         System.out.println("getName");
95
96         JsPair pair;
97
98         pair = new JsPair("", JsNull.NULL);
99         assertEquals("", pair.getName());
100
101         pair = new JsPair("a", JsNull.NULL);
102         assertEquals("a", pair.getName());
103
104         return;
105     }
106
107     /**
108      * Test of getValue method, of class JsPair.
109      */
110     @Test
111     public void testGetValue(){
112         System.out.println("getValue");
113
114         JsPair pair;
115
116         pair = new JsPair("x", JsNull.NULL);
117         assertEquals(JsNull.NULL, pair.getValue());
118
119         pair = new JsPair("x", "abc");
120         assertEquals(new JsString("abc"), pair.getValue());
121
122         pair = new JsPair("x", true);
123         assertEquals(JsBoolean.TRUE, pair.getValue());
124
125         pair = new JsPair("x", false);
126         assertEquals(JsBoolean.FALSE, pair.getValue());
127
128         pair = new JsPair("x", 999999999999L);
129         assertEquals(new JsNumber("999999999999"), pair.getValue());
130
131         pair = new JsPair("x", 1.25);
132         assertEquals(new JsNumber("1.25"), pair.getValue());
133
134         return;
135     }
136
137     /**
138      * Test of toString method, of class JsPair.
139      */
140     @Test
141     public void testToString(){
142         System.out.println("toString");
143
144         JsPair pair;
145
146         pair = new JsPair("x", JsNull.NULL);
147         assertEquals("\"x\":null", pair.toString());
148
149         pair = new JsPair("", JsNull.NULL);
150         assertEquals("\"\":null", pair.toString());
151
152         return;
153     }
154
155     /**
156      * Test of equals method, of class JsPair.
157      */
158     @Test
159     public void testEquals(){
160         System.out.println("equals");
161
162         JsPair pair1;
163         JsPair pair2;
164         JsPair nullVal = null;
165
166         pair1 = new JsPair("three", 3);
167         pair2 = new JsPair("three", 3);
168
169         assertFalse(pair1.equals(nullVal));
170         assertTrue(pair1.equals(pair1));
171         assertTrue(pair1.equals(pair2));
172         assertFalse(pair1.equals(new Object()));
173
174         pair2 = new JsPair("three", 4);
175         assertFalse(pair1.equals(pair2));
176
177         pair2 = new JsPair("two", 3);
178         assertFalse(pair1.equals(pair2));
179
180         pair2 = new JsPair("four", 4);
181         assertFalse(pair1.equals(pair2));
182
183         return;
184     }
185
186     /**
187      * Test of hashCode method, of class JsPair.
188      */
189     @Test
190     public void testHashCode(){
191         System.out.println("hashCode");
192
193         JsPair pair1;
194         JsPair pair2;
195
196         pair1 = new JsPair("three", 3);
197         pair2 = new JsPair("three", 3);
198
199         assertEquals(pair1.hashCode(), pair2.hashCode());
200
201         int hash1 = pair1.hashCode();
202         int hash2 = pair1.hashCode();
203
204         assertEquals(hash1, hash2);
205
206         return;
207     }
208
209 }