From e899a2970d1fc5df19008f96537740c7e45cceb1 Mon Sep 17 00:00:00 2001 From: stleary Date: Thu, 19 Mar 2015 17:30:44 -0500 Subject: [PATCH] PropertTest.java coverage 94.8% --- JunitTestSuite.java | 3 +- PropertyTest.java | 81 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 PropertyTest.java diff --git a/JunitTestSuite.java b/JunitTestSuite.java index 20b69f9..b9abad1 100644 --- a/JunitTestSuite.java +++ b/JunitTestSuite.java @@ -5,7 +5,8 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ CDLTest.class, - CookieTest.class + CookieTest.class, + PropertyTest.class }) public class JunitTestSuite { } \ No newline at end of file diff --git a/PropertyTest.java b/PropertyTest.java new file mode 100644 index 0000000..4354488 --- /dev/null +++ b/PropertyTest.java @@ -0,0 +1,81 @@ +package org.json.junit; + +import java.util.*; + +import static org.junit.Assert.*; + +import org.json.*; +import org.junit.Test; + + +/** + * Tests for JSON-Java Property.java + */ +public class PropertyTest { + + @Test + public void shouldHandleNullProperties() { + + Properties properties = null; + JSONObject jsonObject = Property.toJSONObject(properties); + assertTrue("jsonObject should be empty", jsonObject.length() == 0); + } + + @Test + public void shouldHandleEmptyProperties() { + + Properties properties = new Properties(); + JSONObject jsonObject = Property.toJSONObject(properties); + assertTrue("jsonObject should be empty", jsonObject.length() == 0); + } + + @Test + public void shouldHandleProperties() { + Properties properties = new Properties(); + + properties.put("Illinois", "Springfield"); + properties.put("Missouri", "Jefferson City"); + properties.put("Washington", "Olympia"); + properties.put("California", "Sacramento"); + properties.put("Indiana", "Indianapolis"); + + JSONObject jsonObject = Property.toJSONObject(properties); + + assertTrue("jsonObject should contain 5 items", jsonObject.length() == 5); + assertTrue("jsonObject should contain Illinois property", + "Springfield".equals(jsonObject.get("Illinois"))); + assertTrue("jsonObject should contain Missouri property", + "Jefferson City".equals(jsonObject.get("Missouri"))); + assertTrue("jsonObject should contain Washington property", + "Olympia".equals(jsonObject.get("Washington"))); + assertTrue("jsonObject should contain California property", + "Sacramento".equals(jsonObject.get("California"))); + assertTrue("jsonObject should contain Indiana property", + "Indianapolis".equals(jsonObject.get("Indiana"))); + } + + @Test + public void shouldHandleNullJSONProperty() { + JSONObject jsonObject= null; + Properties properties = Property.toProperties(jsonObject); + assertTrue("properties should be empty", + properties.size() == 0); + } + + @Test + public void shouldHandleJSONProperty() { + Properties properties = new Properties(); + + properties.put("Illinois", "Springfield"); + properties.put("Missouri", "Jefferson City"); + properties.put("Washington", "Olympia"); + properties.put("California", "Sacramento"); + properties.put("Indiana", "Indianapolis"); + + JSONObject jsonObject = Property.toJSONObject(properties); + Properties jsonProperties = Property.toProperties(jsonObject); + + assertTrue("property objects should match", + properties.equals(jsonProperties)); + } +} \ No newline at end of file