add testcase

This commit is contained in:
wenshao
2011-12-16 10:35:48 +08:00
parent ecd098b403
commit ff59cd8f0c
3 changed files with 100 additions and 1 deletions
@@ -70,7 +70,7 @@ public class ThrowableDeserializer extends JavaBeanDeserializer {
} else {
throw new JSONException("syntax error");
}
lexer.nextToken();
lexer.nextToken(JSONToken.COMMA);
} else if ("message".equals(key)) {
if (lexer.token() == JSONToken.NULL) {
message = null;
@@ -0,0 +1,29 @@
package com.alibaba.json.bvt.parser.deser;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
public class NumberDeserializerTest extends TestCase {
public void test_byte() throws Exception {
Assert.assertEquals(Byte.valueOf((byte) 123), JSON.parseObject("\"123\"", byte.class));
Assert.assertEquals(Byte.valueOf((byte) 123), JSON.parseObject("\"123\"", Byte.class));
}
public void test_byte1() throws Exception {
Assert.assertEquals(Byte.valueOf((byte) 123), JSON.parseObject("123.", byte.class));
Assert.assertEquals(Byte.valueOf((byte) 123), JSON.parseObject("123.", Byte.class));
}
public void test_short() throws Exception {
Assert.assertEquals(Short.valueOf((short) 123), JSON.parseObject("\"123\"", short.class));
Assert.assertEquals(Short.valueOf((short) 123), JSON.parseObject("\"123\"", Short.class));
}
public void test_short1() throws Exception {
Assert.assertEquals(Short.valueOf((short) 123), JSON.parseObject("123.", short.class));
Assert.assertEquals(Short.valueOf((short) 123), JSON.parseObject("123.", Short.class));
}
}
@@ -0,0 +1,70 @@
package com.alibaba.json.bvt.parser.deser;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
public class ThrowableDeserializerTest extends TestCase {
public void test_0 () throws Exception {
Assert.assertEquals(Throwable.class, JSON.parseObject("{}", Throwable.class).getClass());
Assert.assertEquals(Throwable.class, JSON.parseObject("{,,,}", Throwable.class).getClass());
Assert.assertEquals(java.lang.RuntimeException.class, JSON.parseObject("{\"@type\":\"java.lang.RuntimeException\"}", Throwable.class).getClass());
Assert.assertEquals(null, JSON.parseObject("{\"message\":null}", Throwable.class).getMessage());
Assert.assertEquals(Exception.class, JSON.parseObject("{\"cause\":{}}", Throwable.class).getCause().getClass());
}
public void test_error() throws Exception {
JSONException error = null;
try {
JSON.parseObject("{\"@type\":33}", Throwable.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error1() throws Exception {
JSONException error = null;
try {
Assert.assertEquals(null, JSON.parseObject("{\"message\":33}", Throwable.class).getMessage());
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error2() throws Exception {
Exception error = null;
try {
Assert.assertEquals(null, JSON.parseObject("{}", MyException.class).getMessage());
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public void test_error3() throws Exception {
Exception error = null;
try {
Assert.assertEquals(null, JSON.parseObject("{}", MyException2.class).getMessage());
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
public static class MyException extends Exception {
private MyException() {
}
}
public static class MyException2 extends Exception {
public MyException2() {
throw new RuntimeException();
}
}
}