Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
184 additions
and
27 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
143 changes: 143 additions & 0 deletions
143
src/test/java/com/alibaba/json/bvt/parser/deser/list/ListStringFieldTest_stream.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,143 @@ | |||
package com.alibaba.json.bvt.parser.deser.list; | |||
|
|||
import java.io.StringReader; | |||
import java.util.List; | |||
import java.util.Map; | |||
|
|||
import org.junit.Assert; | |||
|
|||
import com.alibaba.fastjson.JSONException; | |||
import com.alibaba.fastjson.JSONReader; | |||
import com.alibaba.fastjson.TypeReference; | |||
|
|||
import junit.framework.TestCase; | |||
|
|||
public class ListStringFieldTest_stream extends TestCase { | |||
|
|||
public void test_list() throws Exception { | |||
String text = "{\"values\":[\"a\",null,\"b\",\"ab\\\\c\"]}"; | |||
|
|||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
Model model = reader.readObject(Model.class); | |||
Assert.assertEquals(4, model.values.size()); | |||
Assert.assertEquals("a", model.values.get(0)); | |||
Assert.assertEquals(null, model.values.get(1)); | |||
Assert.assertEquals("b", model.values.get(2)); | |||
Assert.assertEquals("ab\\c", model.values.get(3)); | |||
} | |||
|
|||
public void test_null() throws Exception { | |||
String text = "{\"values\":null}"; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
Model model = reader.readObject(Model.class); | |||
Assert.assertNull(model.values); | |||
} | |||
|
|||
public void test_empty() throws Exception { | |||
String text = "{\"values\":[]}"; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
Model model = reader.readObject(Model.class); | |||
Assert.assertEquals(0, model.values.size()); | |||
} | |||
|
|||
public void test_map_empty() throws Exception { | |||
String text = "{\"model\":{\"values\":[]}}"; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() { | |||
}); | |||
Model model = (Model) map.get("model"); | |||
Assert.assertEquals(0, model.values.size()); | |||
} | |||
|
|||
public void test_notMatch() throws Exception { | |||
String text = "{\"value\":[]}"; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
Model model = reader.readObject(Model.class); | |||
Assert.assertNull(model.values); | |||
} | |||
|
|||
public void test_error() throws Exception { | |||
String text = "{\"values\":[1"; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
|
|||
Exception error = null; | |||
try { | |||
reader.readObject(Model.class); | |||
} catch (JSONException ex) { | |||
error = ex; | |||
} | |||
Assert.assertNotNull(error); | |||
} | |||
|
|||
public void test_error_1() throws Exception { | |||
String text = "{\"values\":[\"b\"["; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
|
|||
Exception error = null; | |||
try { | |||
reader.readObject(Model.class); | |||
} catch (JSONException ex) { | |||
error = ex; | |||
} | |||
Assert.assertNotNull(error); | |||
} | |||
|
|||
public void test_error_2() throws Exception { | |||
String text = "{\"model\":{\"values\":[]["; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
|
|||
|
|||
Exception error = null; | |||
try { | |||
reader.readObject(new TypeReference<Map<String, Model>>() { | |||
}); | |||
} catch (JSONException ex) { | |||
error = ex; | |||
} | |||
Assert.assertNotNull(error); | |||
} | |||
|
|||
public void test_error_3() throws Exception { | |||
String text = "{\"model\":{\"values\":[]}["; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
|
|||
|
|||
Exception error = null; | |||
try { | |||
reader.readObject(new TypeReference<Map<String, Model>>() { | |||
}); | |||
} catch (JSONException ex) { | |||
error = ex; | |||
} | |||
Assert.assertNotNull(error); | |||
} | |||
|
|||
public void test_error_4() throws Exception { | |||
String text = "{\"model\":{\"values\":[]}}"; | |||
JSONReader reader = new JSONReader(new StringReader(text)); | |||
|
|||
|
|||
Exception error = null; | |||
try { | |||
reader.readObject(new TypeReference<Map<String, Model>>() { | |||
}); | |||
} catch (JSONException ex) { | |||
error = ex; | |||
} | |||
Assert.assertNotNull(error); | |||
} | |||
|
|||
public static class Model { | |||
|
|||
private List<String> values; | |||
|
|||
public List<String> getValues() { | |||
return values; | |||
} | |||
|
|||
public void setValues(List<String> values) { | |||
this.values = values; | |||
} | |||
|
|||
} | |||
} |