bug fixed & add testcase

This commit is contained in:
wenshao
2013-07-18 18:20:43 +08:00
parent 44b945b2ba
commit 35b27c9df3
4 changed files with 79 additions and 0 deletions
@@ -0,0 +1,12 @@
package com.alibaba.json.bvt.bug;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
public class Bug_for_zengjie extends TestCase {
public void test_0 () throws Exception {
JSON.parse("{123:'abc','value':{123:'abc'}}");
}
}
@@ -0,0 +1,30 @@
package com.alibaba.json.bvt.serializer;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.PropertyPreFilter;
public class PrePropertyFilterTest extends TestCase {
public void test_0() throws Exception {
class VO {
public int getId() { throw new RuntimeException(); }
}
PropertyPreFilter filter = new PropertyPreFilter () {
public boolean apply(JSONSerializer serializer, Object source, String name) {
return false;
}
};
VO vo = new VO();
String text = JSON.toJSONString(vo, filter);
Assert.assertEquals("{}", text);
}
}
@@ -0,0 +1,33 @@
package com.alibaba.json.bvt.serializer;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.PropertyFilter;
public class PropertyFilterTest2 extends TestCase {
public void test_0() throws Exception {
class VO {
public int id;
public String name;
}
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
return "id".equals(name);
}
};
VO vo = new VO();
vo.id = 123;
vo.name = "gaotie";
String text = JSON.toJSONString(vo, filter);
Assert.assertEquals("{\"id\":123}", text);
}
}