mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 16:00:51 -07:00
Adds test cases for corrected generic constructors and put methods
This commit is contained in:
parent
1a5718dc39
commit
4a2f9b8cd3
2 changed files with 281 additions and 37 deletions
|
@ -1,10 +1,17 @@
|
|||
package org.json.junit;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
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.Map;
|
||||
|
||||
import org.json.*;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
@ -80,6 +87,112 @@ public class JSONArrayTest {
|
|||
equals(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the constructor has backwards compatability with RAW types pre-java5.
|
||||
*/
|
||||
@Test
|
||||
public void verifyConstructor() {
|
||||
|
||||
final JSONArray expected = new JSONArray("[10]");
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Collection myRawC = Collections.singleton(Integer.valueOf(10));
|
||||
JSONArray jaRaw = new JSONArray(myRawC);
|
||||
|
||||
Collection<Integer> myCInt = Collections.singleton(Integer.valueOf(10));
|
||||
JSONArray jaInt = new JSONArray(myCInt);
|
||||
|
||||
Collection<Object> myCObj = Collections.singleton((Object) Integer
|
||||
.valueOf(10));
|
||||
JSONArray jaObj = new JSONArray(myCObj);
|
||||
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaRaw));
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaInt));
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaObj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the put Collection has backwards compatability with RAW types pre-java5.
|
||||
*/
|
||||
@Test
|
||||
public void verifyPutCollection() {
|
||||
|
||||
final JSONArray expected = new JSONArray("[[10]]");
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Collection myRawC = Collections.singleton(Integer.valueOf(10));
|
||||
JSONArray jaRaw = new JSONArray();
|
||||
jaRaw.put(myRawC);
|
||||
|
||||
Collection<Object> myCObj = Collections.singleton((Object) Integer
|
||||
.valueOf(10));
|
||||
JSONArray jaObj = new JSONArray();
|
||||
jaObj.put(myCObj);
|
||||
|
||||
Collection<Integer> myCInt = Collections.singleton(Integer.valueOf(10));
|
||||
JSONArray jaInt = new JSONArray();
|
||||
jaInt.put(myCInt);
|
||||
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaRaw));
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaObj));
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaInt));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies that the put Map has backwards compatability with RAW types pre-java5.
|
||||
*/
|
||||
@Test
|
||||
public void verifyPutMap() {
|
||||
|
||||
final JSONArray expected = new JSONArray("[{\"myKey\":10}]");
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map myRawC = Collections.singletonMap("myKey", Integer.valueOf(10));
|
||||
JSONArray jaRaw = new JSONArray();
|
||||
jaRaw.put(myRawC);
|
||||
|
||||
Map<String, Object> myCStrObj = Collections.singletonMap("myKey",
|
||||
(Object) Integer.valueOf(10));
|
||||
JSONArray jaStrObj = new JSONArray();
|
||||
jaStrObj.put(myCStrObj);
|
||||
|
||||
Map<String, Integer> myCStrInt = Collections.singletonMap("myKey",
|
||||
Integer.valueOf(10));
|
||||
JSONArray jaStrInt = new JSONArray();
|
||||
jaStrInt.put(myCStrInt);
|
||||
|
||||
Map<?, ?> myCObjObj = Collections.singletonMap((Object) "myKey",
|
||||
(Object) Integer.valueOf(10));
|
||||
JSONArray jaObjObj = new JSONArray();
|
||||
jaObjObj.put(myCObjObj);
|
||||
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaRaw));
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaStrObj));
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaStrInt));
|
||||
assertTrue(
|
||||
"The RAW Collection should give me the same as the Typed Collection",
|
||||
expected.similar(jaObjObj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a JSONArray doc with a variety of different elements.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue