1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.json;
18
19 import java.io.StringWriter;
20
21 import junit.framework.TestCase;
22
23
24
25
26 public abstract class AbstractJSONTest extends TestCase {
27 public AbstractJSONTest( String name ) {
28 super( name );
29 }
30
31 public void testIsArray() {
32 boolean isArray = ((Boolean) getIsArrayExpectations()[0]).booleanValue();
33 JSON json = (JSON) getIsArrayExpectations()[1];
34 assertEquals( isArray, json.isArray() );
35 }
36
37 public void testToString() {
38 String expected = (String) getToStringExpectations1()[0];
39 JSON json = (JSON) getToStringExpectations1()[1];
40 assertEquals( expected, json.toString() );
41 }
42
43 public void testToString_indentFactor() {
44 String expected = (String) getToStringExpectations2()[0];
45 JSON json = (JSON) getToStringExpectations2()[1];
46 assertEquals( expected, json.toString( getIndentFactor() ) );
47 }
48
49 public void testToString_indentFactor_indent() {
50 String expected = (String) getToStringExpectations3()[0];
51 JSON json = (JSON) getToStringExpectations3()[1];
52 assertEquals( expected, json.toString( getIndentFactor(), getIndent() ) );
53 }
54
55 public void testWrite() {
56 StringWriter w = new StringWriter();
57 String expected = (String) getWriteExpectations()[0];
58 JSON json = (JSON) getWriteExpectations()[1];
59 json.write( w );
60 assertEquals( expected, w.getBuffer()
61 .toString() );
62 }
63
64 protected abstract int getIndent();
65
66 protected abstract int getIndentFactor();
67
68 protected abstract Object[] getIsArrayExpectations();
69
70 protected abstract Object[] getToStringExpectations1();
71
72 protected abstract Object[] getToStringExpectations2();
73
74 protected abstract Object[] getToStringExpectations3();
75
76 protected abstract Object[] getWriteExpectations();
77 }