mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix test
This commit is contained in:
@@ -19,7 +19,7 @@ public class Issue1075Test {
|
||||
@Test
|
||||
public void testToBeanIgnoreCase() {
|
||||
// 在忽略大小写的情况下,f2、fac都匹配
|
||||
final ObjA o2 = JSONUtil.parseObj(jsonStr, JSONConfig.create().setIgnoreCase(true)).toBean(ObjA.class);
|
||||
final ObjA o2 = JSONUtil.parseObj(jsonStr, JSONConfig.of().setIgnoreCase(true)).toBean(ObjA.class);
|
||||
|
||||
Assert.assertEquals("fac", o2.getFAC());
|
||||
Assert.assertEquals("f2", o2.getF2());
|
||||
|
@@ -23,12 +23,12 @@ public class Issue2223Test {
|
||||
map1.put("m1", m1);
|
||||
|
||||
Assert.assertEquals("{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}",
|
||||
JSONUtil.toJsonStr(map1, JSONConfig.create()));
|
||||
JSONUtil.toJsonStr(map1, JSONConfig.of()));
|
||||
|
||||
final BeanDemo beanDemo = new BeanDemo();
|
||||
beanDemo.setMap1(map1);
|
||||
Assert.assertEquals("{\"map1\":{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}}",
|
||||
JSONUtil.toJsonStr(beanDemo, JSONConfig.create()));
|
||||
JSONUtil.toJsonStr(beanDemo, JSONConfig.of()));
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@@ -12,7 +12,7 @@ public class IssueI4RBZ4Test {
|
||||
public void sortTest(){
|
||||
final String jsonStr = "{\"id\":\"123\",\"array\":[1,2,3],\"outNum\":356,\"body\":{\"ava1\":\"20220108\",\"use\":1,\"ava2\":\"20230108\"},\"name\":\"John\"}";
|
||||
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, JSONConfig.create().setNatureKeyComparator());
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, JSONConfig.of().setNatureKeyComparator());
|
||||
Assert.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ public class IssueI50EGGTest {
|
||||
@Test
|
||||
public void toBeanTest(){
|
||||
final String data = "{\"return_code\": 1, \"return_msg\": \"成功\", \"return_data\" : null}";
|
||||
final ApiResult<?> apiResult = JSONUtil.toBean(data, JSONConfig.create().setIgnoreCase(true), ApiResult.class);
|
||||
final ApiResult<?> apiResult = JSONUtil.toBean(data, JSONConfig.of().setIgnoreCase(true), ApiResult.class);
|
||||
Assert.assertEquals(1, apiResult.getReturn_code());
|
||||
}
|
||||
|
||||
|
@@ -31,11 +31,11 @@ public class JSONArrayTest {
|
||||
// JSONObject实现了Iterable接口,可以转换为JSONArray
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
|
||||
JSONArray jsonArray = new JSONArray(jsonObject, JSONConfig.create());
|
||||
JSONArray jsonArray = new JSONArray(jsonObject, JSONConfig.of());
|
||||
Assert.assertEquals(new JSONArray(), jsonArray);
|
||||
|
||||
jsonObject.set("key1", "value1");
|
||||
jsonArray = new JSONArray(jsonObject, JSONConfig.create());
|
||||
jsonArray = new JSONArray(jsonObject, JSONConfig.of());
|
||||
Assert.assertEquals(1, jsonArray.size());
|
||||
Assert.assertEquals("[{\"key1\":\"value1\"}]", jsonArray.toString());
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class JSONArrayTest {
|
||||
public void addNullTest(){
|
||||
final List<String> aaa = ListUtil.view("aaa", null);
|
||||
final String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa,
|
||||
JSONConfig.create().setIgnoreNullValue(false)));
|
||||
JSONConfig.of().setIgnoreNullValue(false)));
|
||||
Assert.assertEquals("[\"aaa\",null]", jsonStr);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class JSONArrayTest {
|
||||
public void toDictListTest() {
|
||||
final String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
|
||||
|
||||
final JSONArray array = JSONUtil.parseArray(jsonArr, JSONConfig.create().setIgnoreError(false));
|
||||
final JSONArray array = JSONUtil.parseArray(jsonArr, JSONConfig.of().setIgnoreError(false));
|
||||
|
||||
final List<Dict> list = JSONUtil.toList(array, Dict.class);
|
||||
|
||||
@@ -273,7 +273,7 @@ public class JSONArrayTest {
|
||||
|
||||
@Test
|
||||
public void putNullTest(){
|
||||
final JSONArray array = JSONUtil.createArray(JSONConfig.create().setIgnoreNullValue(false));
|
||||
final JSONArray array = JSONUtil.createArray(JSONConfig.of().setIgnoreNullValue(false));
|
||||
array.set(null);
|
||||
|
||||
Assert.assertEquals("[null]", array.toString());
|
||||
|
@@ -199,7 +199,7 @@ public class JSONObjectTest {
|
||||
@Test
|
||||
public void toBeanTest() {
|
||||
final JSONObject subJson = JSONUtil.createObj().set("value1", "strValue1").set("value2", "234");
|
||||
final JSONObject json = JSONUtil.createObj().set("strValue", "strTest").set("intValue", 123)
|
||||
final JSONObject json = JSONUtil.createObj(JSONConfig.of().setIgnoreError(true)).set("strValue", "strTest").set("intValue", 123)
|
||||
// 测试空字符串转对象
|
||||
.set("doubleValue", "")
|
||||
.set("beanValue", subJson)
|
||||
@@ -453,7 +453,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void setDateFormatTest() {
|
||||
final JSONConfig jsonConfig = JSONConfig.create();
|
||||
final JSONConfig jsonConfig = JSONConfig.of();
|
||||
jsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
final JSONObject json = new JSONObject(jsonConfig);
|
||||
@@ -465,7 +465,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void setDateFormatTest2() {
|
||||
final JSONConfig jsonConfig = JSONConfig.create();
|
||||
final JSONConfig jsonConfig = JSONConfig.of();
|
||||
jsonConfig.setDateFormat("yyyy#MM#dd");
|
||||
|
||||
final Date date = DateUtil.parse("2020-06-05 11:16:11");
|
||||
@@ -485,7 +485,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void setCustomDateFormatTest() {
|
||||
final JSONConfig jsonConfig = JSONConfig.create();
|
||||
final JSONConfig jsonConfig = JSONConfig.of();
|
||||
jsonConfig.setDateFormat("#sss");
|
||||
|
||||
final Date date = DateUtil.parse("2020-06-05 11:16:11");
|
||||
@@ -599,7 +599,7 @@ public class JSONObjectTest {
|
||||
@Test(expected = JSONException.class)
|
||||
public void createJSONObjectTest() {
|
||||
// 集合类不支持转为JSONObject
|
||||
new JSONObject(new JSONArray(), JSONConfig.create());
|
||||
new JSONObject(new JSONArray(), JSONConfig.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -646,7 +646,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void filterIncludeTest() {
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.of())
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
@@ -658,7 +658,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void filterExcludeTest() {
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.of())
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
@@ -670,7 +670,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void editTest() {
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.of())
|
||||
.set("a", "value1")
|
||||
.set("b", "value2")
|
||||
.set("c", "value3")
|
||||
@@ -690,7 +690,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void toUnderLineCaseTest() {
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.of())
|
||||
.set("aKey", "value1")
|
||||
.set("bJob", "value2")
|
||||
.set("cGood", "value3")
|
||||
@@ -705,7 +705,7 @@ public class JSONObjectTest {
|
||||
|
||||
@Test
|
||||
public void nullToEmptyTest() {
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setIgnoreNullValue(false))
|
||||
final JSONObject json1 = JSONUtil.createObj(JSONConfig.of().setIgnoreNullValue(false))
|
||||
.set("a", null)
|
||||
.set("b", "value2");
|
||||
|
||||
|
@@ -191,7 +191,7 @@ public class JSONUtilTest {
|
||||
Assert.assertEquals("{\"test2\":12}", jsonObjectDefault.toString());
|
||||
|
||||
// 不去除多余的0
|
||||
final JSONObject jsonObject = JSONUtil.createObj(JSONConfig.create().setStripTrailingZeros(false))
|
||||
final JSONObject jsonObject = JSONUtil.createObj(JSONConfig.of().setStripTrailingZeros(false))
|
||||
.set("test2", 12.00D);
|
||||
Assert.assertEquals("{\"test2\":12.0}", jsonObject.toString());
|
||||
|
||||
|
@@ -20,7 +20,7 @@ public class TransientTest {
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject jsonObject = new JSONObject(detailBill,
|
||||
JSONConfig.create().setTransientSupport(false));
|
||||
JSONConfig.of().setTransientSupport(false));
|
||||
Assert.assertEquals("{\"id\":\"3243\",\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class TransientTest {
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject jsonObject = new JSONObject(detailBill,
|
||||
JSONConfig.create().setTransientSupport(true));
|
||||
JSONConfig.of().setTransientSupport(true));
|
||||
Assert.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TransientTest {
|
||||
detailBill.setBizNo("bizNo");
|
||||
|
||||
final JSONObject jsonObject = new JSONObject(detailBill,
|
||||
JSONConfig.create().setTransientSupport(false));
|
||||
JSONConfig.of().setTransientSupport(false));
|
||||
|
||||
final Bill bill = jsonObject.toBean(Bill.class);
|
||||
Assert.assertEquals("3243", bill.getId());
|
||||
@@ -57,7 +57,7 @@ public class TransientTest {
|
||||
detailBill.setBizNo("bizNo");
|
||||
|
||||
final JSONObject jsonObject = new JSONObject(detailBill,
|
||||
JSONConfig.create().setTransientSupport(true));
|
||||
JSONConfig.of().setTransientSupport(true));
|
||||
|
||||
final Bill bill = jsonObject.toBean(Bill.class);
|
||||
Assert.assertNull(bill.getId());
|
||||
|
Reference in New Issue
Block a user