From 7f83a5171837818856e21b610dc192549eb5d306 Mon Sep 17 00:00:00 2001 From: stleary Date: Tue, 29 Dec 2015 17:56:43 -0600 Subject: [PATCH] refactor test classes to their own modules --- JSONObjectTest.java | 50 +++++--------------------------------------- MyBean.java | 16 ++++++++++++++ MyBigNumberBean.java | 11 ++++++++++ MyJsonString.java | 14 +++++++++++++ MyPublicClass.java | 9 ++++++++ 5 files changed, 55 insertions(+), 45 deletions(-) create mode 100644 MyBean.java create mode 100644 MyBigNumberBean.java create mode 100644 MyJsonString.java create mode 100644 MyPublicClass.java diff --git a/JSONObjectTest.java b/JSONObjectTest.java index d420e22..80bef48 100644 --- a/JSONObjectTest.java +++ b/JSONObjectTest.java @@ -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. @@ -427,8 +387,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() @@ -1168,10 +1128,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); diff --git a/MyBean.java b/MyBean.java new file mode 100644 index 0000000..53d150a --- /dev/null +++ b/MyBean.java @@ -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(); +} \ No newline at end of file diff --git a/MyBigNumberBean.java b/MyBigNumberBean.java new file mode 100644 index 0000000..0ca1870 --- /dev/null +++ b/MyBigNumberBean.java @@ -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(); +} \ No newline at end of file diff --git a/MyJsonString.java b/MyJsonString.java new file mode 100644 index 0000000..4e63693 --- /dev/null +++ b/MyJsonString.java @@ -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"; + } +} \ No newline at end of file diff --git a/MyPublicClass.java b/MyPublicClass.java new file mode 100644 index 0000000..1f55e3e --- /dev/null +++ b/MyPublicClass.java @@ -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"; +}