OSDN Git Service

f3ecc4a8028e6e524981674c09f9c776bb461b53
[jovsonz/Jovsonz.git] / src / test / java / jp / sourceforge / jovsonz / JsNullTest.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 JsNullTest {
20
21     public JsNullTest() {
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 etc of class JsNull.
42      */
43     @Test
44     public void testEtc(){
45         System.out.println("etc");
46         assertNotNull(JsNull.NULL);
47         assertTrue(JsNull.NULL instanceof JsNull);
48         return;
49     }
50
51     /**
52      * Test of traverse method, of class JsNull.
53      */
54     @Test
55     public void testTraverse(){
56         System.out.println("traverse");
57         try{
58             JsNull.NULL.traverse(new ValueVisitor(){
59                 int ct = 0;
60
61                 public void visitValue(JsValue value)
62                         throws JsVisitException{
63                     assertEquals(JsNull.NULL, value);
64                     assertTrue(this.ct++ <= 0);
65                 }
66
67                 public void visitPairName(String name)
68                         throws JsVisitException{
69                     throw new JsVisitException();
70                 }
71
72                 public void visitCompositionClose(JsComposition composite)
73                         throws JsVisitException{
74                     throw new JsVisitException();
75                 }
76             });
77         }catch(JsVisitException e){
78             fail();
79         }
80         return;
81     }
82
83     /**
84      * Test of compareTo method, of class JsNull.
85      */
86     @Test
87     public void testCompareTo(){
88         System.out.println("compareTo");
89         assertEquals(0, JsNull.NULL.compareTo(JsNull.NULL));
90         try{
91             JsNull.NULL.compareTo(null);
92             fail();
93         }catch(NullPointerException e){
94             // NOTHING
95         }
96         return;
97     }
98
99     /**
100      * Test of toString method, of class JsNull.
101      */
102     @Test
103     public void testToString(){
104         System.out.println("toString");
105         assertEquals("null", JsNull.NULL.toString());
106         return;
107     }
108
109     /**
110      * Test of getJsTypes method, of class JsNull.
111      */
112     @Test
113     public void testGetJsTypes() {
114         System.out.println("getJsTypes");
115
116         JsNull instance = JsNull.NULL;
117
118         assertEquals(JsTypes.NULL, instance.getJsTypes());
119
120         return;
121     }
122
123     /**
124      * Test of equals method, of class JsNull.
125      */
126     @Test
127     public void testEquals(){
128         System.out.println("equals");
129
130         assertTrue(JsNull.NULL.equals(JsNull.NULL));
131
132         JsNull nullVal = null;
133         assertFalse(JsNull.NULL.equals(nullVal));
134
135         assertFalse(JsNull.NULL.equals(""));
136
137         return;
138     }
139
140     /**
141      * Test of hashCode method, of class JsNull.
142      */
143     @Test
144     public void testHashCode(){
145         System.out.println("hashCode");
146
147         assertEquals(JsNull.NULL.hashCode(), JsNull.NULL.hashCode());
148
149         return;
150     }
151
152     /**
153      * Test of parseNull method, of class JsNull.
154      */
155     @Test
156     public void testParseNull() throws Exception{
157         System.out.println("parseNull");
158
159         JsonSource source;
160         JsNull result;
161
162         source = new JsonSource("null");
163         result = JsNull.parseNull(source);
164         assertEquals(JsNull.NULL, result);
165
166         source = new JsonSource("X");
167         result = JsNull.parseNull(source);
168         assertNull(result);
169
170         try{
171             source = new JsonSource("nX");
172             result = JsNull.parseNull(source);
173             fail();
174         }catch(JsParseException e){
175             //GOOD
176         }
177
178         try{
179             source = new JsonSource("nuX");
180             result = JsNull.parseNull(source);
181             fail();
182         }catch(JsParseException e){
183             //GOOD
184         }
185
186         try{
187             source = new JsonSource("nulX");
188             result = JsNull.parseNull(source);
189             fail();
190         }catch(JsParseException e){
191             //GOOD
192         }
193
194         return;
195     }
196
197 }