mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
unittests for stlear/JSON-Java#233
This commit is contained in:
parent
adb3118d31
commit
a1893ebc02
2 changed files with 53 additions and 4 deletions
|
@ -1,15 +1,24 @@
|
||||||
package org.json.junit;
|
package org.json.junit;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
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.JSONPointerException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.jayway.jsonpath.*;
|
import com.jayway.jsonpath.Configuration;
|
||||||
|
import com.jayway.jsonpath.JsonPath;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -686,4 +695,19 @@ public class JSONArrayTest {
|
||||||
new Long(-1).equals(Long.parseLong((String) it.next())));
|
new Long(-1).equals(Long.parseLong((String) it.next())));
|
||||||
assertTrue("should be at end of array", !it.hasNext());
|
assertTrue("should be at end of array", !it.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = JSONPointerException.class)
|
||||||
|
public void queryWithNoResult() {
|
||||||
|
new JSONArray().query("/a/b");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void optQueryWithNoResult() {
|
||||||
|
assertNull(new JSONArray().optQuery("/a/b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void optQueryWithSyntaxError() {
|
||||||
|
new JSONArray().optQuery("invalid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.json.junit;
|
package org.json.junit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -10,16 +11,25 @@ import java.io.StringWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.CDL;
|
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.JSONPointerException;
|
||||||
import org.json.XML;
|
import org.json.XML;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.jayway.jsonpath.*;
|
import com.jayway.jsonpath.Configuration;
|
||||||
|
import com.jayway.jsonpath.JsonPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSONObject, along with JSONArray, are the central classes of the reference app.
|
* JSONObject, along with JSONArray, are the central classes of the reference app.
|
||||||
|
@ -1899,4 +1909,19 @@ public class JSONObjectTest {
|
||||||
String sNull = XML.toString(jsonObjectNull);
|
String sNull = XML.toString(jsonObjectNull);
|
||||||
assertTrue("null should emit an empty string", "".equals(sNull));
|
assertTrue("null should emit an empty string", "".equals(sNull));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = JSONPointerException.class)
|
||||||
|
public void queryWithNoResult() {
|
||||||
|
new JSONObject().query("/a/b");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void optQueryWithNoResult() {
|
||||||
|
assertNull(new JSONObject().optQuery("/a/b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void optQueryWithSyntaxError() {
|
||||||
|
new JSONObject().optQuery("invalid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue