|
16 | 16 | import org.json.JSONArray; |
17 | 17 | import org.json.JSONException; |
18 | 18 | import org.json.JSONObject; |
19 | | -import org.json.JSONString; |
20 | 19 | import org.json.XML; |
21 | 20 | import org.junit.Test; |
22 | 21 |
|
23 | 22 | import com.jayway.jsonpath.*; |
24 | 23 |
|
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 | | - |
57 | 24 | /** |
58 | 25 | * JSONObject, along with JSONArray, are the central classes of the reference app. |
59 | 26 | * All of the other classes interact with them, and JSON functionality would |
60 | 27 | * otherwise be impossible. |
61 | 28 | */ |
62 | 29 | 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"; |
70 | 30 |
|
71 | 31 | /** |
72 | 32 | * JSONObject built from a bean, but only using a null value. |
@@ -378,8 +338,8 @@ public String toString(){ |
378 | 338 | public void jsonObjectByObjectAndNames() { |
379 | 339 | String[] keys = {"publicString", "publicInt"}; |
380 | 340 | // 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); |
383 | 343 |
|
384 | 344 | // validate JSON |
385 | 345 | Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); |
@@ -1083,10 +1043,10 @@ public void jsonObjectNames() { |
1083 | 1043 | /** |
1084 | 1044 | * A bean is also an object. But in order to test the static |
1085 | 1045 | * method getNames(), this particular bean needs some public |
1086 | | - * data members, which have been added to the class. |
| 1046 | + * data members. |
1087 | 1047 | */ |
1088 | | - JSONObjectTest jsonObjectTest = new JSONObjectTest(); |
1089 | | - names = JSONObject.getNames(jsonObjectTest); |
| 1048 | + MyPublicClass myPublicClass = new MyPublicClass(); |
| 1049 | + names = JSONObject.getNames(myPublicClass); |
1090 | 1050 |
|
1091 | 1051 | // validate JSON |
1092 | 1052 | jsonArray = new JSONArray(names); |
|
0 commit comments