|  | 
| 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. | 
| @@ -427,8 +387,8 @@ public String toString(){ | 
| 427 | 387 |     public void jsonObjectByObjectAndNames() { | 
| 428 | 388 |         String[] keys = {"publicString", "publicInt"}; | 
| 429 | 389 |         // 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); | 
| 432 | 392 | 
 | 
| 433 | 393 |         // validate JSON | 
| 434 | 394 |         Object doc = Configuration.defaultConfiguration().jsonProvider() | 
| @@ -1168,10 +1128,10 @@ public void jsonObjectNames() { | 
| 1168 | 1128 |         /** | 
| 1169 | 1129 |          * A bean is also an object. But in order to test the static | 
| 1170 | 1130 |          * method getNames(), this particular bean needs some public | 
| 1171 |  | -         * data members, which have been added to the class. | 
|  | 1131 | +         * data members. | 
| 1172 | 1132 |          */ | 
| 1173 |  | -        JSONObjectTest jsonObjectTest = new JSONObjectTest(); | 
| 1174 |  | -        names = JSONObject.getNames(jsonObjectTest); | 
|  | 1133 | +        MyPublicClass myPublicClass = new MyPublicClass(); | 
|  | 1134 | +        names = JSONObject.getNames(myPublicClass); | 
| 1175 | 1135 | 
 | 
| 1176 | 1136 |         // validate JSON | 
| 1177 | 1137 |         jsonArray = new JSONArray(names); | 
|  | 
0 commit comments