OSDN Git Service

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