14
14
15
15
package com .google .api .client .json .jackson2 ;
16
16
17
+ import static org .junit .Assert .assertEquals ;
18
+ import static org .junit .Assert .assertNotNull ;
19
+ import static org .junit .Assert .fail ;
20
+
17
21
import com .google .api .client .json .JsonFactory ;
18
22
import com .google .api .client .json .JsonParser ;
19
23
import com .google .api .client .test .json .AbstractJsonFactoryTest ;
20
24
import com .google .api .client .util .StringUtils ;
21
25
import java .io .IOException ;
22
26
import java .util .ArrayList ;
27
+ import org .junit .Test ;
23
28
24
29
/**
25
30
* Tests {@link JacksonFactory}.
28
33
*/
29
34
public class JacksonFactoryTest extends AbstractJsonFactoryTest {
30
35
31
- private static final String JSON_ENTRY_PRETTY =
32
- "{" + StringUtils .LINE_SEPARATOR + " \" title\" : \" foo\" " + StringUtils .LINE_SEPARATOR + "}" ;
33
- private static final String JSON_FEED_PRETTY =
34
- "{"
35
- + StringUtils .LINE_SEPARATOR
36
- + " \" entries\" : [ {"
37
- + StringUtils .LINE_SEPARATOR
38
- + " \" title\" : \" foo\" "
39
- + StringUtils .LINE_SEPARATOR
40
- + " }, {"
41
- + StringUtils .LINE_SEPARATOR
42
- + " \" title\" : \" bar\" "
43
- + StringUtils .LINE_SEPARATOR
44
- + " } ]"
45
- + StringUtils .LINE_SEPARATOR
46
- + "}" ;
36
+ private static final String JSON_ENTRY_PRETTY ;
37
+ private static final String JSON_FEED_PRETTY ;
47
38
48
- public JacksonFactoryTest (String name ) {
49
- super (name );
39
+ static {
40
+ JSON_ENTRY_PRETTY =
41
+ "{" + StringUtils .LINE_SEPARATOR + " \" title\" : \" foo\" " + StringUtils .LINE_SEPARATOR + "}" ;
42
+ JSON_FEED_PRETTY =
43
+ "{"
44
+ + StringUtils .LINE_SEPARATOR
45
+ + " \" entries\" : [ {"
46
+ + StringUtils .LINE_SEPARATOR
47
+ + " \" title\" : \" foo\" "
48
+ + StringUtils .LINE_SEPARATOR
49
+ + " }, {"
50
+ + StringUtils .LINE_SEPARATOR
51
+ + " \" title\" : \" bar\" "
52
+ + StringUtils .LINE_SEPARATOR
53
+ + " } ]"
54
+ + StringUtils .LINE_SEPARATOR
55
+ + "}" ;
50
56
}
51
57
52
58
@ Override
53
59
protected JsonFactory newFactory () {
54
60
return new JacksonFactory ();
55
61
}
56
62
63
+ @ Test
57
64
public final void testToPrettyString_entry () throws Exception {
58
65
Entry entry = new Entry ();
59
66
entry .title = "foo" ;
60
67
assertEquals (JSON_ENTRY_PRETTY , newFactory ().toPrettyString (entry ));
61
68
}
62
69
70
+ @ Test
63
71
public final void testToPrettyString_Feed () throws Exception {
64
72
Feed feed = new Feed ();
65
73
Entry entryFoo = new Entry ();
@@ -72,11 +80,13 @@ public final void testToPrettyString_Feed() throws Exception {
72
80
assertEquals (JSON_FEED_PRETTY , newFactory ().toPrettyString (feed ));
73
81
}
74
82
83
+ @ Test
75
84
public final void testParse_directValue () throws Exception {
76
85
JsonParser parser = newFactory ().createJsonParser ("123" );
77
86
assertEquals (123 , parser .parse (Integer .class , true ));
78
87
}
79
88
89
+ @ Test
80
90
public final void testGetByteValue () throws IOException {
81
91
JsonParser parser = newFactory ().createJsonParser ("123" );
82
92
0 commit comments