|
9 | 9 | import static org.junit.Assert.assertNotEquals;
|
10 | 10 | import static org.junit.Assert.assertNotNull;
|
11 | 11 | import static org.junit.Assert.assertNull;
|
| 12 | +import static org.junit.Assert.assertThrows; |
12 | 13 | import static org.junit.Assert.assertTrue;
|
13 | 14 | import static org.junit.Assert.fail;
|
14 | 15 | import static org.mockito.Mockito.mock;
|
@@ -1972,7 +1973,7 @@ public void jsonObjectToStringIndent() {
|
1972 | 1973 | @Test
|
1973 | 1974 | public void jsonObjectToStringSuppressWarningOnCastToMap() {
|
1974 | 1975 | JSONObject jsonObject = new JSONObject();
|
1975 |
| - Map<String, String> map = new HashMap(); |
| 1976 | + Map<String, String> map = new HashMap<>(); |
1976 | 1977 | map.put("abc", "def");
|
1977 | 1978 | jsonObject.put("key", map);
|
1978 | 1979 |
|
@@ -3283,7 +3284,7 @@ public void testSingletonEnumBean() {
|
3283 | 3284 | @SuppressWarnings("boxing")
|
3284 | 3285 | @Test
|
3285 | 3286 | public void testGenericBean() {
|
3286 |
| - GenericBean<Integer> bean = new GenericBean(42); |
| 3287 | + GenericBean<Integer> bean = new GenericBean<>(42); |
3287 | 3288 | final JSONObject jo = new JSONObject(bean);
|
3288 | 3289 | assertEquals(jo.keySet().toString(), 8, jo.length());
|
3289 | 3290 | assertEquals(42, jo.get("genericValue"));
|
@@ -3627,4 +3628,25 @@ public String toJSONString() {
|
3627 | 3628 | .put("b", 2);
|
3628 | 3629 | assertFalse(jo1.similar(jo3));
|
3629 | 3630 | }
|
| 3631 | + |
| 3632 | + private static final Number[] NON_FINITE_NUMBERS = { Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN, |
| 3633 | + Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NaN }; |
| 3634 | + |
| 3635 | + @Test |
| 3636 | + public void issue713MapConstructorWithNonFiniteNumbers() { |
| 3637 | + for (Number nonFinite : NON_FINITE_NUMBERS) { |
| 3638 | + Map<String, Number> map = new HashMap<>(); |
| 3639 | + map.put("a", nonFinite); |
| 3640 | + |
| 3641 | + assertThrows(JSONException.class, () -> new JSONObject(map)); |
| 3642 | + } |
| 3643 | + } |
| 3644 | + |
| 3645 | + @Test |
| 3646 | + public void issue713BeanConstructorWithNonFiniteNumbers() { |
| 3647 | + for (Number nonFinite : NON_FINITE_NUMBERS) { |
| 3648 | + GenericBean<Number> bean = new GenericBean<>(nonFinite); |
| 3649 | + assertThrows(JSONException.class, () -> new JSONObject(bean)); |
| 3650 | + } |
| 3651 | + } |
3630 | 3652 | }
|
0 commit comments