1   /*
2    * Copyright 2002-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.json;
18  
19  import java.io.StringWriter;
20  
21  import junit.framework.TestCase;
22  
23  /**
24   * @author Andres Almiray <aalmiray@users.sourceforge.net>
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  }