mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -3,8 +3,6 @@ package cn.hutool.json;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class IssueI6LBZATest {
|
||||
@Test
|
||||
public void parseJSONStringTest() {
|
||||
@@ -31,6 +29,6 @@ public class IssueI6LBZATest {
|
||||
public void parseJSONNumberTest() {
|
||||
final String a = "123";
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(BigDecimal.class, parse.getClass());
|
||||
Assert.assertEquals(Integer.class, parse.getClass());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,13 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JSONTokenerTest {
|
||||
@Test
|
||||
public void parseTest() {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.getUtf8Reader("issue1200.json"));
|
||||
Assert.assertNotNull(jsonObject);
|
||||
}
|
||||
}
|
@@ -17,6 +17,42 @@ import java.util.*;
|
||||
|
||||
public class JSONUtilTest {
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void parseInvalid() {
|
||||
JSONUtil.parse("abc");
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void parseInvalid2() {
|
||||
JSONUtil.parse("'abc");
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void parseInvalid3() {
|
||||
JSONUtil.parse("\"abc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValueTest() {
|
||||
Object parse = JSONUtil.parse(123);
|
||||
Assert.assertEquals(123, parse);
|
||||
|
||||
parse = JSONUtil.parse("\"abc\"");
|
||||
Assert.assertEquals("abc", parse);
|
||||
|
||||
parse = JSONUtil.parse("true");
|
||||
Assert.assertEquals(true, parse);
|
||||
|
||||
parse = JSONUtil.parse("False");
|
||||
Assert.assertEquals(false, parse);
|
||||
|
||||
parse = JSONUtil.parse("null");
|
||||
Assert.assertNull(parse);
|
||||
|
||||
parse = JSONUtil.parse("");
|
||||
Assert.assertNull(parse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 出现语法错误时报错,检查解析\x字符时是否会导致死循环异常
|
||||
*/
|
||||
@@ -29,20 +65,39 @@ public class JSONUtilTest {
|
||||
* 数字解析为JSONArray报错
|
||||
*/
|
||||
@Test(expected = JSONException.class)
|
||||
public void parseNumberTest() {
|
||||
public void parseNumberToJSONArrayTest() {
|
||||
final JSONArray json = JSONUtil.parseArray(123L);
|
||||
Assert.assertNotNull(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字解析为JSONArray报错
|
||||
*/
|
||||
@Test
|
||||
public void parseNumberToJSONArrayTest2() {
|
||||
final JSONArray json = JSONUtil.parseArray(123L,
|
||||
JSONConfig.of().setIgnoreError(true));
|
||||
Assert.assertNotNull(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字解析为JSONArray报错
|
||||
*/
|
||||
@Test(expected = JSONException.class)
|
||||
public void parseNumberTest2() {
|
||||
public void parseNumberToJSONObjectTest() {
|
||||
final JSONObject json = JSONUtil.parseObj(123L);
|
||||
Assert.assertNotNull(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字解析为JSONObject,忽略错误
|
||||
*/
|
||||
@Test
|
||||
public void parseNumberToJSONObjectTest2() {
|
||||
final JSONObject json = JSONUtil.parseObj(123L, JSONConfig.of().setIgnoreError(true));
|
||||
Assert.assertEquals(new JSONObject(), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJsonStrTest() {
|
||||
final UserA a1 = new UserA();
|
||||
|
Reference in New Issue
Block a user