|
1 | 1 | package org.json.junit; |
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertFalse; |
| 4 | +import static org.junit.Assert.assertNull; |
4 | 5 | import static org.junit.Assert.assertTrue; |
5 | 6 | import static org.mockito.Mockito.mock; |
6 | 7 | import static org.mockito.Mockito.when; |
|
10 | 11 | import java.io.Writer; |
11 | 12 | import java.math.BigDecimal; |
12 | 13 | import java.math.BigInteger; |
13 | | -import java.util.*; |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.Collection; |
| 17 | +import java.util.Collections; |
| 18 | +import java.util.HashMap; |
| 19 | +import java.util.List; |
| 20 | +import java.util.Locale; |
| 21 | +import java.util.Map; |
14 | 22 |
|
15 | 23 | import org.json.CDL; |
16 | 24 | import org.json.JSONArray; |
17 | 25 | import org.json.JSONException; |
18 | 26 | import org.json.JSONObject; |
| 27 | +import org.json.JSONPointerException; |
19 | 28 | import org.json.XML; |
20 | 29 | import org.junit.Test; |
21 | 30 |
|
22 | | -import com.jayway.jsonpath.*; |
| 31 | +import com.jayway.jsonpath.Configuration; |
| 32 | +import com.jayway.jsonpath.JsonPath; |
23 | 33 |
|
24 | 34 | /** |
25 | 35 | * JSONObject, along with JSONArray, are the central classes of the reference app. |
@@ -1899,4 +1909,19 @@ public void jsonObjectNullOperations() { |
1899 | 1909 | String sNull = XML.toString(jsonObjectNull); |
1900 | 1910 | assertTrue("null should emit an empty string", "".equals(sNull)); |
1901 | 1911 | } |
| 1912 | + |
| 1913 | + @Test(expected = JSONPointerException.class) |
| 1914 | + public void queryWithNoResult() { |
| 1915 | + new JSONObject().query("/a/b"); |
| 1916 | + } |
| 1917 | + |
| 1918 | + @Test |
| 1919 | + public void optQueryWithNoResult() { |
| 1920 | + assertNull(new JSONObject().optQuery("/a/b")); |
| 1921 | + } |
| 1922 | + |
| 1923 | + @Test(expected = IllegalArgumentException.class) |
| 1924 | + public void optQueryWithSyntaxError() { |
| 1925 | + new JSONObject().optQuery("invalid"); |
| 1926 | + } |
1902 | 1927 | } |
0 commit comments