This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from alibaba/master
merge
- Loading branch information
Showing
14 changed files
with
297 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.alibaba.json.bvt; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSONArray; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class JSONArrayTest3 extends TestCase { | ||
public void test_0() throws Exception { | ||
JSONArray array = new JSONArray(); | ||
array.set(1, "1001"); | ||
Assert.assertEquals(2, array.size()); | ||
Assert.assertNull(array.get(0)); | ||
Assert.assertEquals("1001", array.get(1)); | ||
|
||
array.clear(); | ||
Assert.assertEquals(0, array.size()); | ||
|
||
array.set(-1, "1001"); | ||
Assert.assertEquals(1, array.size()); | ||
Assert.assertEquals("1001", array.get(0)); | ||
|
||
array.fluentAdd("1002").fluentClear(); | ||
Assert.assertEquals(0, array.size()); | ||
|
||
array.fluentAdd("1002").fluentRemove("1002"); | ||
Assert.assertEquals(0, array.size()); | ||
|
||
array.fluentAdd("1002").fluentRemove(0); | ||
Assert.assertEquals(0, array.size()); | ||
|
||
array.fluentSet(1, "1001"); | ||
Assert.assertEquals(2, array.size()); | ||
Assert.assertNull(array.get(0)); | ||
Assert.assertEquals("1001", array.get(1)); | ||
|
||
array.fluentRemoveAll(Arrays.asList(null, "1001")); | ||
Assert.assertEquals(0, array.size()); | ||
|
||
array.fluentAddAll(Arrays.asList("1001", "1002", "1003")); | ||
Assert.assertEquals(3, array.size()); | ||
|
||
array.retainAll(Arrays.asList("1002", "1004")); | ||
Assert.assertEquals(1, array.size()); | ||
Assert.assertEquals("1002", array.get(0)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/com/alibaba/json/bvt/parser/ReadOnlyCollectionTest_final_field.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.alibaba.json.bvt.parser; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class ReadOnlyCollectionTest_final_field extends TestCase { | ||
|
||
public void test_readOnlyNullList() throws Exception { | ||
String text = "{\"list\":[1,2,3]}"; | ||
Entity entity = JSON.parseObject(text, Entity.class); | ||
Assert.assertNull(entity.list); | ||
} | ||
|
||
public static class Entity { | ||
|
||
public final List<Object> list = null; | ||
|
||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/java/com/alibaba/json/bvt/parser/ReadOnlyCollectionTest_final_field_null.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.alibaba.json.bvt.parser; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class ReadOnlyCollectionTest_final_field_null extends TestCase { | ||
|
||
public void test_readOnlyNullList() throws Exception { | ||
String text = "{\"list\":[1,2,3]}"; | ||
Entity entity = JSON.parseObject(text, Entity.class); | ||
Assert.assertNotNull(entity); | ||
Assert.assertEquals(3, entity.list.size()); | ||
} | ||
|
||
public static class Entity { | ||
|
||
public final List<Object> list = new ArrayList<Object>(); | ||
|
||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/com/alibaba/json/bvt/parser/ReadOnlyMapTest2_final_field.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.alibaba.json.bvt.parser; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class ReadOnlyMapTest2_final_field extends TestCase { | ||
|
||
public void test_readOnlyNullList() throws Exception { | ||
String text = "{\"values\":{\"a\":{}}}"; | ||
Entity entity = JSON.parseObject(text, Entity.class); | ||
Assert.assertNotNull(entity); | ||
Assert.assertNull(entity.values); | ||
} | ||
|
||
public static class Entity { | ||
|
||
public final Map<String, A> values = null; | ||
|
||
|
||
} | ||
|
||
public static class A { | ||
|
||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/alibaba/json/bvt/parser/ReadOnlyMapTest_final_field.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.alibaba.json.bvt.parser; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
|
||
public class ReadOnlyMapTest_final_field extends TestCase { | ||
|
||
public void test_readOnlyNullList() throws Exception { | ||
String text = "{\"values\":{\"a\":{}}}"; | ||
Entity entity = JSON.parseObject(text, Entity.class); | ||
Assert.assertNotNull(entity); | ||
Assert.assertNotNull(entity.values.get("a")); | ||
Assert.assertTrue(entity.values.get("a") instanceof A); | ||
} | ||
|
||
public static class Entity { | ||
|
||
public final Map<String, A> values = new HashMap<String, A>(); | ||
|
||
} | ||
|
||
public static class A { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/java/com/alibaba/json/bvt/path/JSONPath_list_size_1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.alibaba.json.bvt.path; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSONPath; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class JSONPath_list_size_1 extends TestCase { | ||
public void test_obj_array() throws Exception { | ||
Object[] array = new Object[] {1, 2, 3}; | ||
JSONPath path = new JSONPath("$.size()"); | ||
Integer result = (Integer) path.eval(array); | ||
Assert.assertEquals(array.length, result.intValue()); | ||
} | ||
|
||
public void test_int_array() throws Exception { | ||
int[] array = new int[] {1, 2, 3}; | ||
JSONPath path = new JSONPath("$.size()"); | ||
Integer result = (Integer) path.eval(array); | ||
Assert.assertEquals(array.length, result.intValue()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/alibaba/json/bvt/path/JSONPath_list_size_2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.alibaba.json.bvt.path; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSONPath; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class JSONPath_list_size_2 extends TestCase { | ||
public void test_map() throws Exception { | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("1001", 1001); | ||
map.put("1002", 1002); | ||
JSONPath path = new JSONPath("$.size()"); | ||
Integer result = (Integer) path.eval(map); | ||
Assert.assertEquals(map.size(), result.intValue()); | ||
} | ||
|
||
public void test_map_null() throws Exception { | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("1001", 1001); | ||
map.put("1002", 1002); | ||
map.put("1003", null); | ||
JSONPath path = new JSONPath("$.size()"); | ||
Integer result = (Integer) path.eval(map); | ||
Assert.assertEquals(2, result.intValue()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/com/alibaba/json/bvt/path/JSONPath_list_size_3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.alibaba.json.bvt.path; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSONPath; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class JSONPath_list_size_3 extends TestCase { | ||
public void test_java_bean() throws Exception { | ||
Model model = new Model(); | ||
model.id = 1001; | ||
model.name = "wenshao"; | ||
JSONPath path = new JSONPath("$.size()"); | ||
Integer result = (Integer) path.eval(model); | ||
Assert.assertEquals(2, result.intValue()); | ||
} | ||
|
||
public void test_java_bean_field_null() throws Exception { | ||
Model model = new Model(); | ||
model.id = 1001; | ||
model.name = null; | ||
JSONPath path = new JSONPath("$.size()"); | ||
Integer result = (Integer) path.eval(model); | ||
Assert.assertEquals(1, result.intValue()); | ||
} | ||
|
||
public static class Model { | ||
public int id; | ||
public String name; | ||
} | ||
} |