Skip to content

Commit 7f83a51

Browse files
committed
refactor test classes to their own modules
1 parent c6204a9 commit 7f83a51

File tree

5 files changed

+55
-45
lines changed

5 files changed

+55
-45
lines changed

JSONObjectTest.java

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,17 @@
1616
import org.json.JSONArray;
1717
import org.json.JSONException;
1818
import org.json.JSONObject;
19-
import org.json.JSONString;
2019
import org.json.XML;
2120
import org.junit.Test;
2221

2322
import com.jayway.jsonpath.*;
2423

25-
/**
26-
* Used in testing when a JSONString is needed
27-
*/
28-
class MyJsonString implements JSONString {
29-
30-
@Override
31-
public String toJSONString() {
32-
return "my string";
33-
}
34-
}
35-
36-
/**
37-
* Used in testing when Bean behavior is needed
38-
*/
39-
interface MyBean {
40-
public Integer getIntKey();
41-
public Double getDoubleKey();
42-
public String getStringKey();
43-
public String getEscapeStringKey();
44-
public Boolean isTrueKey();
45-
public Boolean isFalseKey();
46-
public StringReader getStringReaderKey();
47-
};
48-
49-
/**
50-
* Used in testing when a Bean containing big numbers is needed
51-
*/
52-
interface MyBigNumberBean {
53-
public BigInteger getBigInteger();
54-
public BigDecimal getBigDecimal();
55-
}
56-
5724
/**
5825
* JSONObject, along with JSONArray, are the central classes of the reference app.
5926
* All of the other classes interact with them, and JSON functionality would
6027
* otherwise be impossible.
6128
*/
6229
public class JSONObjectTest {
63-
/**
64-
* Need a class with some public data members for testing, so
65-
* JSONObjectTest itself will be used for this purpose.
66-
* TODO: Why not use MyBigNumberBean or MyBean?
67-
*/
68-
public Integer publicInt = 42;
69-
public String publicString = "abc";
7030

7131
/**
7232
* JSONObject built from a bean, but only using a null value.
@@ -427,8 +387,8 @@ public String toString(){
427387
public void jsonObjectByObjectAndNames() {
428388
String[] keys = {"publicString", "publicInt"};
429389
// just need a class that has public data members
430-
JSONObjectTest jsonObjectTest = new JSONObjectTest();
431-
JSONObject jsonObject = new JSONObject(jsonObjectTest, keys);
390+
MyPublicClass myPublicClass = new MyPublicClass();
391+
JSONObject jsonObject = new JSONObject(myPublicClass, keys);
432392

433393
// validate JSON
434394
Object doc = Configuration.defaultConfiguration().jsonProvider()
@@ -1168,10 +1128,10 @@ public void jsonObjectNames() {
11681128
/**
11691129
* A bean is also an object. But in order to test the static
11701130
* method getNames(), this particular bean needs some public
1171-
* data members, which have been added to the class.
1131+
* data members.
11721132
*/
1173-
JSONObjectTest jsonObjectTest = new JSONObjectTest();
1174-
names = JSONObject.getNames(jsonObjectTest);
1133+
MyPublicClass myPublicClass = new MyPublicClass();
1134+
names = JSONObject.getNames(myPublicClass);
11751135

11761136
// validate JSON
11771137
jsonArray = new JSONArray(names);

MyBean.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.json.junit;
2+
3+
import java.io.*;
4+
5+
/**
6+
* Used in testing when Bean behavior is needed
7+
*/
8+
interface MyBean {
9+
public Integer getIntKey();
10+
public Double getDoubleKey();
11+
public String getStringKey();
12+
public String getEscapeStringKey();
13+
public Boolean isTrueKey();
14+
public Boolean isFalseKey();
15+
public StringReader getStringReaderKey();
16+
}

MyBigNumberBean.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.json.junit;
2+
3+
import java.math.*;
4+
5+
/**
6+
* Used in testing when a Bean containing big numbers is needed
7+
*/
8+
interface MyBigNumberBean {
9+
public BigInteger getBigInteger();
10+
public BigDecimal getBigDecimal();
11+
}

MyJsonString.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.json.junit;
2+
3+
import org.json.*;
4+
5+
/**
6+
* Used in testing when a JSONString is needed
7+
*/
8+
class MyJsonString implements JSONString {
9+
10+
@Override
11+
public String toJSONString() {
12+
return "my string";
13+
}
14+
}

MyPublicClass.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.json.junit;
2+
3+
/**
4+
* Need a class with some public data members for testing
5+
*/
6+
public class MyPublicClass {
7+
public Integer publicInt = 42;
8+
public String publicString = "abc";
9+
}

0 commit comments

Comments
 (0)