1
0
Fork 0
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:
Sean Leary 2015-12-29 18:01:35 -06:00
commit 4ddd6a19a7
5 changed files with 55 additions and 45 deletions

View file

@ -16,57 +16,17 @@ import org.json.CDL;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONString;
import org.json.XML; import org.json.XML;
import org.junit.Test; import org.junit.Test;
import com.jayway.jsonpath.*; 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. * JSONObject, along with JSONArray, are the central classes of the reference app.
* All of the other classes interact with them, and JSON functionality would * All of the other classes interact with them, and JSON functionality would
* otherwise be impossible. * otherwise be impossible.
*/ */
public class JSONObjectTest { 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. * JSONObject built from a bean, but only using a null value.
@ -378,8 +338,8 @@ public class JSONObjectTest {
public void jsonObjectByObjectAndNames() { public void jsonObjectByObjectAndNames() {
String[] keys = {"publicString", "publicInt"}; String[] keys = {"publicString", "publicInt"};
// just need a class that has public data members // just need a class that has public data members
JSONObjectTest jsonObjectTest = new JSONObjectTest(); MyPublicClass myPublicClass = new MyPublicClass();
JSONObject jsonObject = new JSONObject(jsonObjectTest, keys); JSONObject jsonObject = new JSONObject(myPublicClass, keys);
// validate JSON // validate JSON
Object doc = Configuration.defaultConfiguration().jsonProvider().parse(jsonObject.toString()); 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 * A bean is also an object. But in order to test the static
* method getNames(), this particular bean needs some public * method getNames(), this particular bean needs some public
* data members, which have been added to the class. * data members.
*/ */
JSONObjectTest jsonObjectTest = new JSONObjectTest(); MyPublicClass myPublicClass = new MyPublicClass();
names = JSONObject.getNames(jsonObjectTest); names = JSONObject.getNames(myPublicClass);
// validate JSON // validate JSON
jsonArray = new JSONArray(names); jsonArray = new JSONArray(names);

16
MyBean.java Normal file
View 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
View 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
View 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
View 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";
}