mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Merge pull request #32 from stleary/refactor-test-classes-from-JSONObjectTest
refactor test classes to their own modules
This commit is contained in:
commit
4ddd6a19a7
5 changed files with 55 additions and 45 deletions
|
@ -16,57 +16,17 @@ import org.json.CDL;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONString;
|
||||
import org.json.XML;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.jsonpath.*;
|
||||
|
||||
/**
|
||||
* Used in testing when a JSONString is needed
|
||||
*/
|
||||
class MyJsonString implements JSONString {
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
return "my string";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in testing when Bean behavior is needed
|
||||
*/
|
||||
interface MyBean {
|
||||
public Integer getIntKey();
|
||||
public Double getDoubleKey();
|
||||
public String getStringKey();
|
||||
public String getEscapeStringKey();
|
||||
public Boolean isTrueKey();
|
||||
public Boolean isFalseKey();
|
||||
public StringReader getStringReaderKey();
|
||||
};
|
||||
|
||||
/**
|
||||
* Used in testing when a Bean containing big numbers is needed
|
||||
*/
|
||||
interface MyBigNumberBean {
|
||||
public BigInteger getBigInteger();
|
||||
public BigDecimal getBigDecimal();
|
||||
}
|
||||
|
||||
/**
|
||||
* JSONObject, along with JSONArray, are the central classes of the reference app.
|
||||
* All of the other classes interact with them, and JSON functionality would
|
||||
* otherwise be impossible.
|
||||
*/
|
||||
public class JSONObjectTest {
|
||||
/**
|
||||
* Need a class with some public data members for testing, so
|
||||
* JSONObjectTest itself will be used for this purpose.
|
||||
* TODO: Why not use MyBigNumberBean or MyBean?
|
||||
*/
|
||||
public Integer publicInt = 42;
|
||||
public String publicString = "abc";
|
||||
|
||||
/**
|
||||
* JSONObject built from a bean, but only using a null value.
|
||||
|
@ -378,8 +338,8 @@ public class JSONObjectTest {
|
|||
public void jsonObjectByObjectAndNames() {
|
||||
String[] keys = {"publicString", "publicInt"};
|
||||
// just need a class that has public data members
|
||||
JSONObjectTest jsonObjectTest = new JSONObjectTest();
|
||||
JSONObject jsonObject = new JSONObject(jsonObjectTest, keys);
|
||||
MyPublicClass myPublicClass = new MyPublicClass();
|
||||
JSONObject jsonObject = new JSONObject(myPublicClass, keys);
|
||||
|
||||
// validate JSON
|
||||
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString());
|
||||
|
@ -1083,10 +1043,10 @@ public class JSONObjectTest {
|
|||
/**
|
||||
* A bean is also an object. But in order to test the static
|
||||
* method getNames(), this particular bean needs some public
|
||||
* data members, which have been added to the class.
|
||||
* data members.
|
||||
*/
|
||||
JSONObjectTest jsonObjectTest = new JSONObjectTest();
|
||||
names = JSONObject.getNames(jsonObjectTest);
|
||||
MyPublicClass myPublicClass = new MyPublicClass();
|
||||
names = JSONObject.getNames(myPublicClass);
|
||||
|
||||
// validate JSON
|
||||
jsonArray = new JSONArray(names);
|
||||
|
|
16
MyBean.java
Normal file
16
MyBean.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package org.json.junit;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Used in testing when Bean behavior is needed
|
||||
*/
|
||||
interface MyBean {
|
||||
public Integer getIntKey();
|
||||
public Double getDoubleKey();
|
||||
public String getStringKey();
|
||||
public String getEscapeStringKey();
|
||||
public Boolean isTrueKey();
|
||||
public Boolean isFalseKey();
|
||||
public StringReader getStringReaderKey();
|
||||
}
|
11
MyBigNumberBean.java
Normal file
11
MyBigNumberBean.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package org.json.junit;
|
||||
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* Used in testing when a Bean containing big numbers is needed
|
||||
*/
|
||||
interface MyBigNumberBean {
|
||||
public BigInteger getBigInteger();
|
||||
public BigDecimal getBigDecimal();
|
||||
}
|
14
MyJsonString.java
Normal file
14
MyJsonString.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package org.json.junit;
|
||||
|
||||
import org.json.*;
|
||||
|
||||
/**
|
||||
* Used in testing when a JSONString is needed
|
||||
*/
|
||||
class MyJsonString implements JSONString {
|
||||
|
||||
@Override
|
||||
public String toJSONString() {
|
||||
return "my string";
|
||||
}
|
||||
}
|
9
MyPublicClass.java
Normal file
9
MyPublicClass.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package org.json.junit;
|
||||
|
||||
/**
|
||||
* Need a class with some public data members for testing
|
||||
*/
|
||||
public class MyPublicClass {
|
||||
public Integer publicInt = 42;
|
||||
public String publicString = "abc";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue