Skip to content

Commit 4ddd6a1

Browse files
committed
Merge pull request stleary#32 from stleary/refactor-test-classes-from-JSONObjectTest
refactor test classes to their own modules
2 parents 95cf866 + 7f83a51 commit 4ddd6a1

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.
@@ -378,8 +338,8 @@ public String toString(){
378338
public void jsonObjectByObjectAndNames() {
379339
String[] keys = {"publicString", "publicInt"};
380340
// just need a class that has public data members
381-
JSONObjectTest jsonObjectTest = new JSONObjectTest();
382-
JSONObject jsonObject = new JSONObject(jsonObjectTest, keys);
341+
MyPublicClass myPublicClass = new MyPublicClass();
342+
JSONObject jsonObject = new JSONObject(myPublicClass, keys);
383343

384344
// validate JSON
385345
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
@@ -1083,10 +1043,10 @@ public void jsonObjectNames() {
10831043
/**
10841044
* A bean is also an object. But in order to test the static
10851045
* method getNames(), this particular bean needs some public
1086-
* data members, which have been added to the class.
1046+
* data members.
10871047
*/
1088-
JSONObjectTest jsonObjectTest = new JSONObjectTest();
1089-
names = JSONObject.getNames(jsonObjectTest);
1048+
MyPublicClass myPublicClass = new MyPublicClass();
1049+
names = JSONObject.getNames(myPublicClass);
10901050

10911051
// validate JSON
10921052
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)