mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
update to junit5
This commit is contained in:
@@ -2,15 +2,15 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.json.serialize.JSONObjectSerializer;
|
||||
import lombok.ToString;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class CustomSerializeTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init(){
|
||||
JSONUtil.putSerializer(CustomBean.class, (JSONObjectSerializer<CustomBean>) (json, bean) -> json.set("customName", bean.name));
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class CustomSerializeTest {
|
||||
customBean.name = "testName";
|
||||
|
||||
final JSONObject obj = JSONUtil.parseObj(customBean);
|
||||
Assert.assertEquals("testName", obj.getStr("customName"));
|
||||
Assertions.assertEquals("testName", obj.getStr("customName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -30,7 +30,7 @@ public class CustomSerializeTest {
|
||||
customBean.name = "testName";
|
||||
|
||||
final JSONObject obj = JSONUtil.ofObj().set("customBean", customBean);
|
||||
Assert.assertEquals("testName", obj.getJSONObject("customBean").getStr("customName"));
|
||||
Assertions.assertEquals("testName", obj.getJSONObject("customBean").getStr("customName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +43,7 @@ public class CustomSerializeTest {
|
||||
|
||||
final String jsonStr = "{\"customName\":\"testName\"}";
|
||||
final CustomBean bean = JSONUtil.parseObj(jsonStr).toBean(CustomBean.class);
|
||||
Assert.assertEquals("testName", bean.name);
|
||||
Assertions.assertEquals("testName", bean.name);
|
||||
}
|
||||
|
||||
@ToString
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue1075Test {
|
||||
|
||||
@@ -12,8 +12,8 @@ public class Issue1075Test {
|
||||
public void testToBean() {
|
||||
// 在不忽略大小写的情况下,f2、fac都不匹配
|
||||
final ObjA o2 = JSONUtil.toBean(jsonStr, ObjA.class);
|
||||
Assert.assertNull(o2.getFAC());
|
||||
Assert.assertNull(o2.getF2());
|
||||
Assertions.assertNull(o2.getFAC());
|
||||
Assertions.assertNull(o2.getF2());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -21,8 +21,8 @@ public class Issue1075Test {
|
||||
// 在忽略大小写的情况下,f2、fac都匹配
|
||||
final ObjA o2 = JSONUtil.parseObj(jsonStr, JSONConfig.of().setIgnoreCase(true)).toBean(ObjA.class);
|
||||
|
||||
Assert.assertEquals("fac", o2.getFAC());
|
||||
Assert.assertEquals("f2", o2.getF2());
|
||||
Assertions.assertEquals("fac", o2.getFAC());
|
||||
Assertions.assertEquals("f2", o2.getF2());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.TreeSet;
|
||||
@@ -21,7 +21,7 @@ public class Issue1101Test {
|
||||
final JSONArray objects = JSONUtil.parseArray(json);
|
||||
final TreeSet<TreeNodeDto> convert = Convert.convert(new TypeReference<TreeSet<TreeNodeDto>>() {
|
||||
}, objects);
|
||||
Assert.assertEquals(2, convert.size());
|
||||
Assertions.assertEquals(2, convert.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,11 +58,11 @@ public class Issue1101Test {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
|
||||
final TreeNode treeNode = JSONUtil.toBean(jsonObject, TreeNode.class);
|
||||
Assert.assertEquals(2, treeNode.getChildren().size());
|
||||
Assertions.assertEquals(2, treeNode.getChildren().size());
|
||||
|
||||
final TreeNodeDto dto = new TreeNodeDto();
|
||||
BeanUtil.copyProperties(treeNode, dto, true);
|
||||
Assert.assertEquals(2, dto.getChildren().size());
|
||||
Assertions.assertEquals(2, dto.getChildren().size());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -3,8 +3,8 @@ package cn.hutool.json;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.json.test.bean.ResultBean;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 测试在bean转换时使用BeanConverter,默认忽略转换失败的字段。
|
||||
@@ -16,7 +16,7 @@ import org.junit.Test;
|
||||
public class Issue1200Test {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void toBeanTest(){
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issue1200.json"));
|
||||
Console.log(jsonObject);
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -23,14 +23,14 @@ public class Issue2090Test {
|
||||
final JSONObject json = JSONUtil.parseObj(test);
|
||||
Console.log(json);
|
||||
final TestBean test1 = json.toBean(TestBean.class);
|
||||
Assert.assertEquals(test, test1);
|
||||
Assertions.assertEquals(test, test1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLocalDateTest(){
|
||||
final LocalDate localDate = LocalDate.now();
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(localDate);
|
||||
Assert.assertNotNull(jsonObject.toString());
|
||||
Assertions.assertNotNull(jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -38,7 +38,7 @@ public class Issue2090Test {
|
||||
final LocalDate d = LocalDate.now();
|
||||
final JSONObject obj = JSONUtil.parseObj(d);
|
||||
final LocalDate d2 = obj.toBean(LocalDate.class);
|
||||
Assert.assertEquals(d, d2);
|
||||
Assertions.assertEquals(d, d2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +46,7 @@ public class Issue2090Test {
|
||||
final LocalDateTime d = LocalDateTime.now();
|
||||
final JSONObject obj = JSONUtil.parseObj(d);
|
||||
final LocalDateTime d2 = obj.toBean(LocalDateTime.class);
|
||||
Assert.assertEquals(d, d2);
|
||||
Assertions.assertEquals(d, d2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,14 +54,14 @@ public class Issue2090Test {
|
||||
final LocalTime d = LocalTime.now();
|
||||
final JSONObject obj = JSONUtil.parseObj(d);
|
||||
final LocalTime d2 = obj.toBean(LocalTime.class);
|
||||
Assert.assertEquals(d, d2);
|
||||
Assertions.assertEquals(d, d2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void monthTest(){
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.set("month", Month.JANUARY);
|
||||
Assert.assertEquals("{\"month\":1}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"month\":1}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.core.collection.ListUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.beans.Transient;
|
||||
import java.util.List;
|
||||
@@ -29,7 +29,7 @@ public class Issue2131Test {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
||||
|
||||
final GoodsResponse result = jsonObject.toBean(GoodsResponse.class);
|
||||
Assert.assertEquals(0, result.getCollections().size());
|
||||
Assertions.assertEquals(0, result.getCollections().size());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -17,17 +17,17 @@ public class Issue2223Test {
|
||||
m1.put("2022/" + i, i);
|
||||
}
|
||||
|
||||
Assert.assertEquals("{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}", JSONUtil.toJsonStr(m1));
|
||||
Assertions.assertEquals("{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}", JSONUtil.toJsonStr(m1));
|
||||
|
||||
final Map<String, Map<String, Long>> map1 = new HashMap<>();
|
||||
map1.put("m1", m1);
|
||||
|
||||
Assert.assertEquals("{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}",
|
||||
Assertions.assertEquals("{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}",
|
||||
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}}}",
|
||||
Assertions.assertEquals("{\"map1\":{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}}",
|
||||
JSONUtil.toJsonStr(beanDemo, JSONConfig.of()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,14 +10,14 @@ public class Issue2377Test {
|
||||
public void bytesTest() {
|
||||
final Object[] paramArray = new Object[]{1, new byte[]{10, 11}, "报表.xlsx"};
|
||||
final String paramsStr = JSONUtil.toJsonStr(paramArray);
|
||||
Assert.assertEquals("[1,[10,11],\"报表.xlsx\"]", paramsStr);
|
||||
Assertions.assertEquals("[1,[10,11],\"报表.xlsx\"]", paramsStr);
|
||||
|
||||
final List<Object> paramList = JSONUtil.toList(paramsStr, Object.class);
|
||||
|
||||
final String paramBytesStr = JSONUtil.toJsonStr(paramList.get(1));
|
||||
Assert.assertEquals("[10,11]", paramBytesStr);
|
||||
Assertions.assertEquals("[10,11]", paramBytesStr);
|
||||
|
||||
final byte[] paramBytes = JSONUtil.toBean(paramBytesStr, byte[].class);
|
||||
Assert.assertArrayEquals((byte[]) paramArray[1], paramBytes);
|
||||
Assertions.assertArrayEquals((byte[]) paramArray[1], paramBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -13,8 +13,8 @@ public class Issue2447Test {
|
||||
Time time = new Time();
|
||||
time.setTime(LocalDateTime.of(1970, 1, 2, 10, 0, 1, 0));
|
||||
String timeStr = JSONUtil.toJsonStr(time);
|
||||
Assert.assertEquals(timeStr, "{\"time\":93601000}");
|
||||
Assert.assertEquals(JSONUtil.toBean(timeStr, Time.class).getTime(), time.getTime());
|
||||
Assertions.assertEquals(timeStr, "{\"time\":93601000}");
|
||||
Assertions.assertEquals(JSONUtil.toBean(timeStr, Time.class).getTime(), time.getTime());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue2507Test {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void xmlToJsonTest(){
|
||||
String xml = "<MsgInfo> <Msg> <![CDATA[<msg><body><row action=\"select\"><DIET>低盐饮食[嘱托]]><![CDATA[]</DIET></row></body></msg>]]> </Msg> <Msg> <![CDATA[<msg><body><row action=\"select\"><DIET>流质饮食</DIET></row></body></msg>]]> </Msg> </MsgInfo>";
|
||||
JSONObject jsonObject = JSONUtil.xmlToJson(xml);
|
||||
|
||||
@@ -3,8 +3,8 @@ package cn.hutool.json;
|
||||
import cn.hutool.json.serialize.JSONDeserializer;
|
||||
import cn.hutool.json.serialize.JSONObjectSerializer;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue2555Test {
|
||||
@Test
|
||||
@@ -18,11 +18,11 @@ public class Issue2555Test {
|
||||
simpleObj.setMyType(child);
|
||||
|
||||
final String json = JSONUtil.toJsonStr(simpleObj);
|
||||
Assert.assertEquals("{\"myType\":{\"addr\":\"addrValue1\"}}", json);
|
||||
Assertions.assertEquals("{\"myType\":{\"addr\":\"addrValue1\"}}", json);
|
||||
|
||||
//MyDeserializer不会被调用
|
||||
final SimpleObj simpleObj2 = JSONUtil.toBean(json, SimpleObj.class);
|
||||
Assert.assertEquals("addrValue1", simpleObj2.getMyType().getAddress());
|
||||
Assertions.assertEquals("addrValue1", simpleObj2.getMyType().getAddress());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue2564Test {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Issue2564Test {
|
||||
public void emptyToBeanTest(){
|
||||
final String x = "{}";
|
||||
final A a = JSONUtil.toBean(x, JSONConfig.of().setIgnoreError(true), A.class);
|
||||
Assert.assertNull(a);
|
||||
Assertions.assertNull(a);
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Month;
|
||||
@@ -18,11 +18,11 @@ public class Issue2572Test {
|
||||
weeks.add(DayOfWeek.MONDAY);
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("weeks", weeks);
|
||||
Assert.assertEquals("{\"weeks\":[1]}", obj.toString());
|
||||
Assertions.assertEquals("{\"weeks\":[1]}", obj.toString());
|
||||
|
||||
final Map<String, Set<DayOfWeek>> monthDays1 = obj.toBean(new TypeReference<Map<String, Set<DayOfWeek>>>() {
|
||||
});
|
||||
Assert.assertEquals("{weeks=[MONDAY]}", monthDays1.toString());
|
||||
Assertions.assertEquals("{weeks=[MONDAY]}", monthDays1.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -31,11 +31,11 @@ public class Issue2572Test {
|
||||
months.add(Month.DECEMBER);
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("months", months);
|
||||
Assert.assertEquals("{\"months\":[12]}", obj.toString());
|
||||
Assertions.assertEquals("{\"months\":[12]}", obj.toString());
|
||||
|
||||
final Map<String, Set<Month>> monthDays1 = obj.toBean(new TypeReference<Map<String, Set<Month>>>() {
|
||||
});
|
||||
Assert.assertEquals("{months=[DECEMBER]}", monthDays1.toString());
|
||||
Assertions.assertEquals("{months=[DECEMBER]}", monthDays1.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,10 +44,10 @@ public class Issue2572Test {
|
||||
monthDays.add(MonthDay.of(Month.DECEMBER, 1));
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("monthDays", monthDays);
|
||||
Assert.assertEquals("{\"monthDays\":[\"--12-01\"]}", obj.toString());
|
||||
Assertions.assertEquals("{\"monthDays\":[\"--12-01\"]}", obj.toString());
|
||||
|
||||
final Map<String, Set<MonthDay>> monthDays1 = obj.toBean(new TypeReference<Map<String, Set<MonthDay>>>() {
|
||||
});
|
||||
Assert.assertEquals("{monthDays=[--12-01]}", monthDays1.toString());
|
||||
Assertions.assertEquals("{monthDays=[--12-01]}", monthDays1.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue2746Test {
|
||||
|
||||
@@ -12,13 +12,15 @@ public class Issue2746Test {
|
||||
try{
|
||||
JSONUtil.parseObj(str);
|
||||
} catch (final JSONException e){
|
||||
Assert.assertTrue(e.getMessage().startsWith("A JSONObject can not directly nest another JSONObject or JSONArray"));
|
||||
Assertions.assertTrue(e.getMessage().startsWith("A JSONObject can not directly nest another JSONObject or JSONArray"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseTest() {
|
||||
final String str = StrUtil.repeat("[", 1500) + StrUtil.repeat("]", 1500);
|
||||
JSONUtil.parseArray(str);
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final String str = StrUtil.repeat("[", 1500) + StrUtil.repeat("]", 1500);
|
||||
JSONUtil.parseArray(str);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -16,7 +16,7 @@ public class Issue2749Test {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void jsonObjectTest() {
|
||||
final Map<String, Object> map = new HashMap<>(1, 1f);
|
||||
Map<String, Object> node = map;
|
||||
@@ -28,7 +28,7 @@ public class Issue2749Test {
|
||||
|
||||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
||||
final JSONObject jsonObject = new JSONObject(jsonStr);
|
||||
Assert.assertNotNull(jsonObject);
|
||||
Assertions.assertNotNull(jsonObject);
|
||||
|
||||
// 栈溢出
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue2801Test {
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
final JSONObject recordObj = new JSONObject(JSONConfig.of().setIgnoreNullValue(false));
|
||||
recordObj.put("m_reportId", null);
|
||||
Assert.assertEquals("{\"m_reportId\":null}", recordObj.toString());
|
||||
Assertions.assertEquals("{\"m_reportId\":null}", recordObj.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,6 +11,6 @@ public class Issue2924Test {
|
||||
public void toListTest(){
|
||||
final String idsJsonString = "[1174,137,1172,210,1173,627,628]";
|
||||
final List<Integer> idList = JSONUtil.toList(idsJsonString,Integer.class);
|
||||
Assert.assertEquals("[1174, 137, 1172, 210, 1173, 627, 628]", idList.toString());
|
||||
Assertions.assertEquals("[1174, 137, 1172, 210, 1173, 627, 628]", idList.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue2953Test {
|
||||
@Test
|
||||
public void parseObjWithBigNumberTest() {
|
||||
final String a = "{\"a\": 114793903847679990000000000000000000000}";
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(a, JSONConfig.of());
|
||||
Assert.assertEquals("{\"a\":\"114793903847679990000000000000000000000\"}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"a\":\"114793903847679990000000000000000000000\"}", jsonObject.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package cn.hutool.json;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,17 +17,17 @@ public class Issue488Test {
|
||||
final ResultSuccess<List<EmailAddress>> result = JSONUtil.toBean(jsonStr, JSONConfig.of(),
|
||||
new TypeReference<ResultSuccess<List<EmailAddress>>>() {});
|
||||
|
||||
Assert.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext());
|
||||
Assertions.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext());
|
||||
|
||||
final List<EmailAddress> adds = result.getValue();
|
||||
Assert.assertEquals("会议室101", adds.get(0).getName());
|
||||
Assert.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress());
|
||||
Assert.assertEquals("会议室102", adds.get(1).getName());
|
||||
Assert.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress());
|
||||
Assert.assertEquals("会议室103", adds.get(2).getName());
|
||||
Assert.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress());
|
||||
Assert.assertEquals("会议室219", adds.get(3).getName());
|
||||
Assert.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress());
|
||||
Assertions.assertEquals("会议室101", adds.get(0).getName());
|
||||
Assertions.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress());
|
||||
Assertions.assertEquals("会议室102", adds.get(1).getName());
|
||||
Assertions.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress());
|
||||
Assertions.assertEquals("会议室103", adds.get(2).getName());
|
||||
Assertions.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress());
|
||||
Assertions.assertEquals("会议室219", adds.get(3).getName());
|
||||
Assertions.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,17 +39,17 @@ public class Issue488Test {
|
||||
|
||||
final ResultSuccess<List<EmailAddress>> result = resultList.get(0);
|
||||
|
||||
Assert.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext());
|
||||
Assertions.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext());
|
||||
|
||||
final List<EmailAddress> adds = result.getValue();
|
||||
Assert.assertEquals("会议室101", adds.get(0).getName());
|
||||
Assert.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress());
|
||||
Assert.assertEquals("会议室102", adds.get(1).getName());
|
||||
Assert.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress());
|
||||
Assert.assertEquals("会议室103", adds.get(2).getName());
|
||||
Assert.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress());
|
||||
Assert.assertEquals("会议室219", adds.get(3).getName());
|
||||
Assert.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress());
|
||||
Assertions.assertEquals("会议室101", adds.get(0).getName());
|
||||
Assertions.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress());
|
||||
Assertions.assertEquals("会议室102", adds.get(1).getName());
|
||||
Assertions.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress());
|
||||
Assertions.assertEquals("会议室103", adds.get(2).getName());
|
||||
Assertions.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress());
|
||||
Assertions.assertEquals("会议室219", adds.get(3).getName());
|
||||
Assertions.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.date.TimeUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -20,11 +20,11 @@ public class Issue644Test {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(beanWithDate);
|
||||
|
||||
BeanWithDate beanWithDate2 = JSONUtil.toBean(jsonObject, BeanWithDate.class);
|
||||
Assert.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()),
|
||||
Assertions.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()),
|
||||
TimeUtil.formatNormal(beanWithDate2.getDate()));
|
||||
|
||||
beanWithDate2 = JSONUtil.toBean(jsonObject.toString(), BeanWithDate.class);
|
||||
Assert.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()),
|
||||
Assertions.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()),
|
||||
TimeUtil.formatNormal(beanWithDate2.getDate()));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class Issue677Test {
|
||||
|
||||
final String jsonStr = JSONUtil.toJsonStr(dto);
|
||||
final AuditResultDto auditResultDto = JSONUtil.toBean(jsonStr, AuditResultDto.class);
|
||||
Assert.assertEquals("Mon Dec 15 00:00:00 CST 1969", auditResultDto.getDate().toString().replace("GMT+08:00", "CST"));
|
||||
Assertions.assertEquals("Mon Dec 15 00:00:00 CST 1969", auditResultDto.getDate().toString().replace("GMT+08:00", "CST"));
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Issue867Test {
|
||||
|
||||
@@ -11,9 +11,9 @@ public class Issue867Test {
|
||||
public void toBeanTest(){
|
||||
final String json = "{\"abc_1d\":\"123\",\"abc_d\":\"456\",\"abc_de\":\"789\"}";
|
||||
final Test02 bean = JSONUtil.toBean(JSONUtil.parseObj(json),Test02.class);
|
||||
Assert.assertEquals("123", bean.getAbc1d());
|
||||
Assert.assertEquals("456", bean.getAbcD());
|
||||
Assert.assertEquals("789", bean.getAbcDe());
|
||||
Assertions.assertEquals("123", bean.getAbc1d());
|
||||
Assertions.assertEquals("456", bean.getAbcD());
|
||||
Assertions.assertEquals("789", bean.getAbcDe());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
@@ -32,7 +32,7 @@ public class IssueI1AU86Test {
|
||||
|
||||
final List<Vcc> vccs = jsonArray.toList(Vcc.class);
|
||||
for (final Vcc vcc : vccs) {
|
||||
Assert.assertNotNull(vcc);
|
||||
Assertions.assertNotNull(vcc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -14,8 +14,8 @@ public class IssueI1F8M2Test {
|
||||
public void toBeanTest() {
|
||||
final String jsonStr = "{\"eventType\":\"fee\",\"fwdAlertingTime\":\"2020-04-22 16:34:13\",\"fwdAnswerTime\":\"\"}";
|
||||
final Param param = JSONUtil.toBean(jsonStr, Param.class);
|
||||
Assert.assertEquals("2020-04-22T16:34:13", param.getFwdAlertingTime().toString());
|
||||
Assert.assertNull(param.getFwdAnswerTime());
|
||||
Assertions.assertEquals("2020-04-22T16:34:13", param.getFwdAlertingTime().toString());
|
||||
Assertions.assertNull(param.getFwdAnswerTime());
|
||||
}
|
||||
|
||||
// Param类的字段
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,11 +18,11 @@ public class IssueI1H2VNTest {
|
||||
final String jsonStr = "{'conditionsVo':[{'column':'StockNo','value':'abc','type':'='},{'column':'CheckIncoming','value':'1','type':'='}]," +
|
||||
"'queryVo':{'conditionsVo':[{'column':'StockNo','value':'abc','type':'='},{'column':'CheckIncoming','value':'1','type':'='}],'queryVo':null}}";
|
||||
final QueryVo vo = JSONUtil.toBean(jsonStr, QueryVo.class);
|
||||
Assert.assertEquals(2, vo.getConditionsVo().size());
|
||||
Assertions.assertEquals(2, vo.getConditionsVo().size());
|
||||
final QueryVo subVo = vo.getQueryVo();
|
||||
Assert.assertNotNull(subVo);
|
||||
Assert.assertEquals(2, subVo.getConditionsVo().size());
|
||||
Assert.assertNull(subVo.getQueryVo());
|
||||
Assertions.assertNotNull(subVo);
|
||||
Assertions.assertEquals(2, subVo.getConditionsVo().size());
|
||||
Assertions.assertNull(subVo.getQueryVo());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class IssueI3BS4STest {
|
||||
final String jsonStr = "{date: '2021-03-17T06:31:33.99'}";
|
||||
final Bean1 bean1 = new Bean1();
|
||||
BeanUtil.copyProperties(JSONUtil.parseObj(jsonStr), bean1);
|
||||
Assert.assertEquals("2021-03-17T06:31:33.099", bean1.getDate().toString());
|
||||
Assertions.assertEquals("2021-03-17T06:31:33.099", bean1.getDate().toString());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI3EGJPTest {
|
||||
|
||||
@@ -14,8 +14,8 @@ public class IssueI3EGJPTest {
|
||||
paramJson.set("is_booleanb", true);
|
||||
final ConvertDO convertDO = BeanUtil.toBean(paramJson, ConvertDO.class);
|
||||
|
||||
Assert.assertTrue(convertDO.isBooleana());
|
||||
Assert.assertTrue(convertDO.getIsBooleanb());
|
||||
Assertions.assertTrue(convertDO.isBooleana());
|
||||
Assertions.assertTrue(convertDO.getIsBooleanb());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -3,8 +3,8 @@ package cn.hutool.json;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -65,12 +65,12 @@ public class IssueI49VZBTest {
|
||||
public void toBeanTest(){
|
||||
final String str = "{type: \"password\"}";
|
||||
final UPOpendoor upOpendoor = JSONUtil.toBean(str, UPOpendoor.class);
|
||||
Assert.assertEquals(NBCloudKeyType.password, upOpendoor.getType());
|
||||
Assertions.assertEquals(NBCloudKeyType.password, upOpendoor.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumConvertTest(){
|
||||
final NBCloudKeyType type = Convert.toEnum(NBCloudKeyType.class, "snapKey");
|
||||
Assert.assertEquals(NBCloudKeyType.snapKey, type);
|
||||
Assertions.assertEquals(NBCloudKeyType.snapKey, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/I4RBZ4
|
||||
@@ -13,6 +13,6 @@ public class IssueI4RBZ4Test {
|
||||
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.of().setNatureKeyComparator());
|
||||
Assert.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,10 +27,10 @@ public class IssueI4XFMWTest {
|
||||
entityList.add(entityB);
|
||||
|
||||
final String jsonStr = JSONUtil.toJsonStr(entityList);
|
||||
Assert.assertEquals("[{\"uid\":\"123\",\"password\":\"456\"},{\"uid\":\"789\",\"password\":\"098\"}]", jsonStr);
|
||||
Assertions.assertEquals("[{\"uid\":\"123\",\"password\":\"456\"},{\"uid\":\"789\",\"password\":\"098\"}]", jsonStr);
|
||||
final List<TestEntity> testEntities = JSONUtil.toList(jsonStr, TestEntity.class);
|
||||
Assert.assertEquals("123", testEntities.get(0).getId());
|
||||
Assert.assertEquals("789", testEntities.get(1).getId());
|
||||
Assertions.assertEquals("123", testEntities.get(0).getId());
|
||||
Assertions.assertEquals("789", testEntities.get(1).getId());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI50EGGTest {
|
||||
|
||||
@@ -11,7 +11,7 @@ public class IssueI50EGGTest {
|
||||
public void toBeanTest(){
|
||||
final String data = "{\"return_code\": 1, \"return_msg\": \"成功\", \"return_data\" : null}";
|
||||
final ApiResult<?> apiResult = JSONUtil.toBean(data, JSONConfig.of().setIgnoreCase(true), ApiResult.class);
|
||||
Assert.assertEquals(1, apiResult.getReturn_code());
|
||||
Assertions.assertEquals(1, apiResult.getReturn_code());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI59LW4Test {
|
||||
@Test
|
||||
public void bytesTest(){
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().set("bytes", new byte[]{1});
|
||||
Assert.assertEquals("{\"bytes\":[1]}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"bytes\":[1]}", jsonObject.toString());
|
||||
|
||||
final byte[] bytes = jsonObject.getBytes("bytes");
|
||||
Assert.assertArrayEquals(new byte[]{1}, bytes);
|
||||
Assertions.assertArrayEquals(new byte[]{1}, bytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bytesInJSONArrayTest(){
|
||||
final JSONArray jsonArray = JSONUtil.ofArray().set(new byte[]{1});
|
||||
Assert.assertEquals("[[1]]", jsonArray.toString());
|
||||
Assertions.assertEquals("[[1]]", jsonArray.toString());
|
||||
|
||||
final byte[] bytes = jsonArray.getBytes(0);
|
||||
Assert.assertArrayEquals(new byte[]{1}, bytes);
|
||||
Assertions.assertArrayEquals(new byte[]{1}, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI5DHK2Test {
|
||||
|
||||
@@ -25,11 +25,11 @@ public class IssueI5DHK2Test {
|
||||
.getJSONObject("properties")
|
||||
.getJSONArray("employment_informations")
|
||||
.getJSONObject(0).getStr("employer_name");
|
||||
Assert.assertEquals("张三皮包公司", exployerName);
|
||||
Assertions.assertEquals("张三皮包公司", exployerName);
|
||||
|
||||
|
||||
final Punished punished = JSONUtil.toBean(json, Punished.class);
|
||||
Assert.assertEquals("张三皮包公司", punished.getPunished_parties()[0].getProperties().getEmployment_informations()[0].getEmployer_name());
|
||||
Assertions.assertEquals("张三皮包公司", punished.getPunished_parties()[0].getProperties().getEmployment_informations()[0].getEmployer_name());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Predicate多层过滤
|
||||
@@ -21,6 +21,6 @@ public class IssueI5OMSCTest {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals("{\"store\":{\"bicycle\":{\"color\":\"red\"},\"book\":[{\"author\":\"Evelyn Waugh\"},{\"author\":\"Evelyn Waugh02\"}]}}", s);
|
||||
Assertions.assertEquals("{\"store\":{\"bicycle\":{\"color\":\"red\"},\"book\":[{\"author\":\"Evelyn Waugh\"},{\"author\":\"Evelyn Waugh02\"}]}}", s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package cn.hutool.json;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.json.xml.JSONXMLSerializer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
|
||||
@@ -14,6 +14,6 @@ public class IssueI676ITTest {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json"));
|
||||
final String xmlStr = JSONXMLSerializer.toXml(jsonObject, null, (String) null);
|
||||
final String content = String.valueOf(XmlUtil.getByXPath("/page/orderItems[1]/content", XmlUtil.readXML(xmlStr), XPathConstants.STRING));
|
||||
Assert.assertEquals(content, "bar1");
|
||||
Assertions.assertEquals(content, "bar1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI6H0XFTest {
|
||||
|
||||
@Test
|
||||
public void toBeanTest(){
|
||||
final Demo demo = JSONUtil.toBean("{\"biz\":\"A\",\"isBiz\":true}", Demo.class);
|
||||
Assert.assertEquals("A", demo.getBiz());
|
||||
Assert.assertEquals("{\"biz\":\"A\"}", JSONUtil.toJsonStr(demo));
|
||||
Assertions.assertEquals("A", demo.getBiz());
|
||||
Assertions.assertEquals("{\"biz\":\"A\"}", JSONUtil.toJsonStr(demo));
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,34 +1,36 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI6LBZATest {
|
||||
@Test
|
||||
public void parseJSONStringTest() {
|
||||
final String a = "\"a\"";
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(String.class, parse.getClass());
|
||||
Assertions.assertEquals(String.class, parse.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseJSONStringTest2() {
|
||||
final String a = "'a'";
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(String.class, parse.getClass());
|
||||
Assertions.assertEquals(String.class, parse.getClass());
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseJSONErrorTest() {
|
||||
final String a = "a";
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(String.class, parse.getClass());
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final String a = "a";
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assertions.assertEquals(String.class, parse.getClass());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseJSONNumberTest() {
|
||||
final String a = "123";
|
||||
final Object parse = JSONUtil.parse(a);
|
||||
Assert.assertEquals(Integer.class, parse.getClass());
|
||||
Assertions.assertEquals(Integer.class, parse.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -31,6 +31,6 @@ public class Issues1881Test {
|
||||
holderContactVOList.add(new ThingsHolderContactVO().setId(1L).setName("1"));
|
||||
holderContactVOList.add(new ThingsHolderContactVO().setId(2L).setName("2"));
|
||||
|
||||
Assert.assertEquals("[{\"id\":1,\"name\":\"1\"},{\"id\":2,\"name\":\"2\"}]", JSONUtil.parseArray(holderContactVOList).toString());
|
||||
Assertions.assertEquals("[{\"id\":1,\"name\":\"1\"},{\"id\":2,\"name\":\"2\"}]", JSONUtil.parseArray(holderContactVOList).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import cn.hutool.json.serialize.JSONDeserializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 测试自定义反序列化
|
||||
@@ -23,7 +23,7 @@ public class IssuesI44E4HTest {
|
||||
|
||||
final String jsonStr = "{\"md\":\"value1\"}";
|
||||
final TestDto testDto = JSONUtil.toBean(jsonStr, TestDto.class);
|
||||
Assert.assertEquals("value1", testDto.getMd().getValue());
|
||||
Assertions.assertEquals("value1", testDto.getMd().getValue());
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -12,9 +12,9 @@ public class IssuesI4V14NTest {
|
||||
public void parseTest(){
|
||||
final String str = "{\"A\" : \"A\\nb\"}";
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(str);
|
||||
Assert.assertEquals("A\nb", jsonObject.getStr("A"));
|
||||
Assertions.assertEquals("A\nb", jsonObject.getStr("A"));
|
||||
|
||||
final Map<String, String> map = jsonObject.toBean(new TypeReference<Map<String, String>>() {});
|
||||
Assert.assertEquals("A\nb", map.get("A"));
|
||||
Assertions.assertEquals("A\nb", map.get("A"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import cn.hutool.json.test.bean.Exam;
|
||||
import cn.hutool.json.test.bean.JsonNode;
|
||||
import cn.hutool.json.test.bean.KeyBean;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -31,19 +31,19 @@ public class JSONArrayTest {
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
|
||||
JSONArray jsonArray = new JSONArray(jsonObject, JSONConfig.of());
|
||||
Assert.assertEquals(new JSONArray(), jsonArray);
|
||||
Assertions.assertEquals(new JSONArray(), jsonArray);
|
||||
|
||||
jsonObject.set("key1", "value1");
|
||||
jsonArray = new JSONArray(jsonObject, JSONConfig.of());
|
||||
Assert.assertEquals(1, jsonArray.size());
|
||||
Assert.assertEquals("[{\"key1\":\"value1\"}]", jsonArray.toString());
|
||||
Assertions.assertEquals(1, jsonArray.size());
|
||||
Assertions.assertEquals("[{\"key1\":\"value1\"}]", jsonArray.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNullTest() {
|
||||
final List<String> aaa = ListUtil.view("aaa", null);
|
||||
final String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa, JSONConfig.of().setIgnoreNullValue(false)));
|
||||
Assert.assertEquals("[\"aaa\",null]", jsonStr);
|
||||
Assertions.assertEquals("[\"aaa\",null]", jsonStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,25 +56,25 @@ public class JSONArrayTest {
|
||||
array.add("value2");
|
||||
array.add("value3");
|
||||
|
||||
Assert.assertEquals(array.get(0), "value1");
|
||||
Assertions.assertEquals(array.get(0), "value1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTest() {
|
||||
final String jsonStr = "[\"value1\", \"value2\", \"value3\"]";
|
||||
final JSONArray array = JSONUtil.parseArray(jsonStr);
|
||||
Assert.assertEquals(array.get(0), "value1");
|
||||
Assertions.assertEquals(array.get(0), "value1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithNullTest() {
|
||||
final String jsonStr = "[{\"grep\":\"4.8\",\"result\":\"右\"},{\"grep\":\"4.8\",\"result\":null}]";
|
||||
JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
|
||||
Assert.assertFalse(jsonArray.getJSONObject(1).containsKey("result"));
|
||||
Assertions.assertFalse(jsonArray.getJSONObject(1).containsKey("result"));
|
||||
|
||||
// 不忽略null,则null的键值对被保留
|
||||
jsonArray = JSONUtil.parseArray(jsonStr, JSONConfig.of().setIgnoreNullValue(false));
|
||||
Assert.assertTrue(jsonArray.getJSONObject(1).containsKey("result"));
|
||||
Assertions.assertTrue(jsonArray.getJSONObject(1).containsKey("result"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +83,7 @@ public class JSONArrayTest {
|
||||
|
||||
final JSONObject obj0 = array.getJSONObject(0);
|
||||
final Exam exam = JSONUtil.toBean(obj0, Exam.class);
|
||||
Assert.assertEquals("0", exam.getAnswerArray()[0].getSeq());
|
||||
Assertions.assertEquals("0", exam.getAnswerArray()[0].getSeq());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,8 +98,8 @@ public class JSONArrayTest {
|
||||
final ArrayList<KeyBean> list = ListUtil.of(b1, b2);
|
||||
|
||||
final JSONArray jsonArray = JSONUtil.parseArray(list);
|
||||
Assert.assertEquals("aValue1", jsonArray.getJSONObject(0).getStr("akey"));
|
||||
Assert.assertEquals("bValue2", jsonArray.getJSONObject(1).getStr("bkey"));
|
||||
Assertions.assertEquals("aValue1", jsonArray.getJSONObject(0).getStr("akey"));
|
||||
Assertions.assertEquals("bValue2", jsonArray.getJSONObject(1).getStr("bkey"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,8 +108,8 @@ public class JSONArrayTest {
|
||||
final JSONArray array = JSONUtil.parseArray(jsonStr);
|
||||
|
||||
final List<Exam> list = array.toList(Exam.class);
|
||||
Assert.assertFalse(list.isEmpty());
|
||||
Assert.assertSame(Exam.class, list.get(0).getClass());
|
||||
Assertions.assertFalse(list.isEmpty());
|
||||
Assertions.assertSame(Exam.class, list.get(0).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,14 +119,14 @@ public class JSONArrayTest {
|
||||
final JSONArray array = JSONUtil.parseArray(jsonArr);
|
||||
final List<User> userList = JSONUtil.toList(array, User.class);
|
||||
|
||||
Assert.assertFalse(userList.isEmpty());
|
||||
Assert.assertSame(User.class, userList.get(0).getClass());
|
||||
Assertions.assertFalse(userList.isEmpty());
|
||||
Assertions.assertSame(User.class, userList.get(0).getClass());
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(111), userList.get(0).getId());
|
||||
Assert.assertEquals(Integer.valueOf(112), userList.get(1).getId());
|
||||
Assertions.assertEquals(Integer.valueOf(111), userList.get(0).getId());
|
||||
Assertions.assertEquals(Integer.valueOf(112), userList.get(1).getId());
|
||||
|
||||
Assert.assertEquals("test1", userList.get(0).getName());
|
||||
Assert.assertEquals("test2", userList.get(1).getName());
|
||||
Assertions.assertEquals("test1", userList.get(0).getName());
|
||||
Assertions.assertEquals("test2", userList.get(1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,14 +137,14 @@ public class JSONArrayTest {
|
||||
|
||||
final List<Dict> list = JSONUtil.toList(array, Dict.class);
|
||||
|
||||
Assert.assertFalse(list.isEmpty());
|
||||
Assert.assertSame(Dict.class, list.get(0).getClass());
|
||||
Assertions.assertFalse(list.isEmpty());
|
||||
Assertions.assertSame(Dict.class, list.get(0).getClass());
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(111), list.get(0).getInt("id"));
|
||||
Assert.assertEquals(Integer.valueOf(112), list.get(1).getInt("id"));
|
||||
Assertions.assertEquals(Integer.valueOf(111), list.get(0).getInt("id"));
|
||||
Assertions.assertEquals(Integer.valueOf(112), list.get(1).getInt("id"));
|
||||
|
||||
Assert.assertEquals("test1", list.get(0).getStr("name"));
|
||||
Assert.assertEquals("test2", list.get(1).getStr("name"));
|
||||
Assertions.assertEquals("test1", list.get(0).getStr("name"));
|
||||
Assertions.assertEquals("test2", list.get(1).getStr("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,8 +154,8 @@ public class JSONArrayTest {
|
||||
|
||||
//noinspection SuspiciousToArrayCall
|
||||
final Exam[] list = array.toArray(new Exam[0]);
|
||||
Assert.assertNotEquals(0, list.length);
|
||||
Assert.assertSame(Exam.class, list[0].getClass());
|
||||
Assertions.assertNotEquals(0, list.length);
|
||||
Assertions.assertSame(Exam.class, list[0].getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,17 +167,19 @@ public class JSONArrayTest {
|
||||
final JSONArray ja = JSONUtil.parseArray(json, JSONConfig.of().setIgnoreNullValue(false));
|
||||
|
||||
final List<KeyBean> list = ja.toList(KeyBean.class);
|
||||
Assert.assertNull(list.get(0));
|
||||
Assert.assertEquals("avalue", list.get(1).getAkey());
|
||||
Assert.assertEquals("bvalue", list.get(1).getBkey());
|
||||
Assertions.assertNull(list.get(0));
|
||||
Assertions.assertEquals("avalue", list.get(1).getAkey());
|
||||
Assertions.assertEquals("bvalue", list.get(1).getBkey());
|
||||
}
|
||||
|
||||
@Test(expected = ConvertException.class)
|
||||
@Test
|
||||
public void toListWithErrorTest() {
|
||||
final String json = "[['aaa',{'akey':'avalue','bkey':'bvalue'}]]";
|
||||
final JSONArray ja = JSONUtil.parseArray(json);
|
||||
Assertions.assertThrows(ConvertException.class, ()->{
|
||||
final String json = "[['aaa',{'akey':'avalue','bkey':'bvalue'}]]";
|
||||
final JSONArray ja = JSONUtil.parseArray(json);
|
||||
|
||||
ja.toBean(new TypeReference<List<List<KeyBean>>>() {
|
||||
ja.toBean(new TypeReference<List<List<KeyBean>>>() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -191,28 +193,28 @@ public class JSONArrayTest {
|
||||
final JSONArray jsonArray = JSONUtil.parseArray(mapList);
|
||||
final List<JsonNode> nodeList = jsonArray.toList(JsonNode.class);
|
||||
|
||||
Assert.assertEquals(Long.valueOf(0L), nodeList.get(0).getId());
|
||||
Assert.assertEquals(Long.valueOf(1L), nodeList.get(1).getId());
|
||||
Assert.assertEquals(Long.valueOf(0L), nodeList.get(2).getId());
|
||||
Assert.assertEquals(Long.valueOf(0L), nodeList.get(3).getId());
|
||||
Assertions.assertEquals(Long.valueOf(0L), nodeList.get(0).getId());
|
||||
Assertions.assertEquals(Long.valueOf(1L), nodeList.get(1).getId());
|
||||
Assertions.assertEquals(Long.valueOf(0L), nodeList.get(2).getId());
|
||||
Assertions.assertEquals(Long.valueOf(0L), nodeList.get(3).getId());
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(0), nodeList.get(0).getParentId());
|
||||
Assert.assertEquals(Integer.valueOf(1), nodeList.get(1).getParentId());
|
||||
Assert.assertEquals(Integer.valueOf(0), nodeList.get(2).getParentId());
|
||||
Assert.assertEquals(Integer.valueOf(0), nodeList.get(3).getParentId());
|
||||
Assertions.assertEquals(Integer.valueOf(0), nodeList.get(0).getParentId());
|
||||
Assertions.assertEquals(Integer.valueOf(1), nodeList.get(1).getParentId());
|
||||
Assertions.assertEquals(Integer.valueOf(0), nodeList.get(2).getParentId());
|
||||
Assertions.assertEquals(Integer.valueOf(0), nodeList.get(3).getParentId());
|
||||
|
||||
Assert.assertEquals("0", nodeList.get(0).getName());
|
||||
Assert.assertEquals("1", nodeList.get(1).getName());
|
||||
Assert.assertEquals("+0", nodeList.get(2).getName());
|
||||
Assert.assertEquals("-0", nodeList.get(3).getName());
|
||||
Assertions.assertEquals("0", nodeList.get(0).getName());
|
||||
Assertions.assertEquals("1", nodeList.get(1).getName());
|
||||
Assertions.assertEquals("+0", nodeList.get(2).getName());
|
||||
Assertions.assertEquals("-0", nodeList.get(3).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getByPathTest() {
|
||||
final String jsonStr = "[{\"id\": \"1\",\"name\": \"a\"},{\"id\": \"2\",\"name\": \"b\"}]";
|
||||
final JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
|
||||
Assert.assertEquals("b", jsonArray.getByPath("[1].name"));
|
||||
Assert.assertEquals("b", JSONUtil.getByPath(jsonArray, "[1].name"));
|
||||
Assertions.assertEquals("b", jsonArray.getByPath("[1].name"));
|
||||
Assertions.assertEquals("b", JSONUtil.getByPath(jsonArray, "[1].name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,12 +222,12 @@ public class JSONArrayTest {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.set(3, "test");
|
||||
// 默认忽略null值,因此空位无值,只有一个值
|
||||
Assert.assertEquals(1, jsonArray.size());
|
||||
Assertions.assertEquals(1, jsonArray.size());
|
||||
|
||||
jsonArray = new JSONArray(JSONConfig.of().setIgnoreNullValue(false));
|
||||
jsonArray.set(3, "test");
|
||||
// 第三个位置插入值,0~2都是null
|
||||
Assert.assertEquals(4, jsonArray.size());
|
||||
Assertions.assertEquals(4, jsonArray.size());
|
||||
}
|
||||
|
||||
// https://github.com/dromara/hutool/issues/1858
|
||||
@@ -233,8 +235,8 @@ public class JSONArrayTest {
|
||||
public void putTest2() {
|
||||
final JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.put(0, 1);
|
||||
Assert.assertEquals(1, jsonArray.size());
|
||||
Assert.assertEquals(1, jsonArray.get(0));
|
||||
Assertions.assertEquals(1, jsonArray.size());
|
||||
Assertions.assertEquals(1, jsonArray.get(0));
|
||||
}
|
||||
|
||||
private static Map<String, String> buildMap(final String id, final String parentId, final String name) {
|
||||
@@ -260,7 +262,7 @@ public class JSONArrayTest {
|
||||
.set(true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> pair.getValue().equals("value2"));
|
||||
Assert.assertEquals("[\"value2\"]", s);
|
||||
Assertions.assertEquals("[\"value2\"]", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,7 +274,7 @@ public class JSONArrayTest {
|
||||
.set(true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> false == pair.getValue().equals("value2"));
|
||||
Assert.assertEquals("[\"value1\",\"value3\",true]", s);
|
||||
Assertions.assertEquals("[\"value1\",\"value3\",true]", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -280,7 +282,7 @@ public class JSONArrayTest {
|
||||
final JSONArray array = JSONUtil.ofArray(JSONConfig.of().setIgnoreNullValue(false));
|
||||
array.set(null);
|
||||
|
||||
Assert.assertEquals("[null]", array.toString());
|
||||
Assertions.assertEquals("[null]", array.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,8 +290,8 @@ public class JSONArrayTest {
|
||||
final String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONArray array = new JSONArray(jsonArr, null, (mutable) -> mutable.get().toString().contains("111"));
|
||||
Assert.assertEquals(1, array.size());
|
||||
Assert.assertTrue(array.getJSONObject(0).containsKey("id"));
|
||||
Assertions.assertEquals(1, array.size());
|
||||
Assertions.assertTrue(array.getJSONObject(0).containsKey("id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -304,8 +306,8 @@ public class JSONArrayTest {
|
||||
mutable.set(o);
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals(2, array.size());
|
||||
Assert.assertTrue(array.getJSONObject(0).containsKey("id"));
|
||||
Assert.assertEquals("test1_edit", array.getJSONObject(0).get("name"));
|
||||
Assertions.assertEquals(2, array.size());
|
||||
Assertions.assertTrue(array.getJSONObject(0).containsKey("id"));
|
||||
Assertions.assertEquals("test1_edit", array.getJSONObject(0).get("name"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.json.test.bean.ExamInfoDict;
|
||||
import cn.hutool.json.test.bean.PerfectEvaluationProductResVo;
|
||||
import cn.hutool.json.test.bean.UserInfoDict;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -55,14 +55,14 @@ public class JSONConvertTest {
|
||||
tempMap.put("toSendManIdCard", 1);
|
||||
|
||||
final JSONObject obj = JSONUtil.parseObj(tempMap);
|
||||
Assert.assertEquals(new Integer(1), obj.getInt("toSendManIdCard"));
|
||||
Assertions.assertEquals(new Integer(1), obj.getInt("toSendManIdCard"));
|
||||
|
||||
final JSONObject examInfoDictsJson = obj.getJSONObject("userInfoDict");
|
||||
Assert.assertEquals(new Integer(1), examInfoDictsJson.getInt("id"));
|
||||
Assert.assertEquals("质量过关", examInfoDictsJson.getStr("realName"));
|
||||
Assertions.assertEquals(new Integer(1), examInfoDictsJson.getInt("id"));
|
||||
Assertions.assertEquals("质量过关", examInfoDictsJson.getStr("realName"));
|
||||
|
||||
final Object id = JSONUtil.getByPath(obj, "userInfoDict.examInfoDict[0].id");
|
||||
Assert.assertEquals(1, id);
|
||||
Assertions.assertEquals(1, id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,15 +77,15 @@ public class JSONConvertTest {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(examJson).getJSONObject("examInfoDicts");
|
||||
final UserInfoDict userInfoDict = jsonObject.toBean(UserInfoDict.class);
|
||||
|
||||
Assert.assertEquals(userInfoDict.getId(), new Integer(1));
|
||||
Assert.assertEquals(userInfoDict.getRealName(), "质量过关");
|
||||
Assertions.assertEquals(userInfoDict.getId(), new Integer(1));
|
||||
Assertions.assertEquals(userInfoDict.getRealName(), "质量过关");
|
||||
|
||||
//============
|
||||
|
||||
final String jsonStr = "{\"id\":null,\"examInfoDict\":[{\"answerIs\":1, \"id\":null}]}";//JSONUtil.toJsonStr(userInfoDict1);
|
||||
final JSONObject jsonObject2 = JSONUtil.parseObj(jsonStr);//.getJSONObject("examInfoDicts");
|
||||
final UserInfoDict userInfoDict2 = jsonObject2.toBean(UserInfoDict.class);
|
||||
Assert.assertNull(userInfoDict2.getId());
|
||||
Assertions.assertNull(userInfoDict2.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@ public class JSONConvertTest {
|
||||
final JSONObject obj = JSONUtil.parseObj(jsonStr);
|
||||
final PerfectEvaluationProductResVo vo = obj.toBean(PerfectEvaluationProductResVo.class);
|
||||
|
||||
Assert.assertEquals(obj.getStr("HA001"), vo.getHA001());
|
||||
Assert.assertEquals(obj.getInt("costTotal"), vo.getCostTotal());
|
||||
Assertions.assertEquals(obj.getStr("HA001"), vo.getHA001());
|
||||
Assertions.assertEquals(obj.getInt("costTotal"), vo.getCostTotal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import cn.hutool.json.serialize.JSONDeserializer;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JSONDeserializerTest {
|
||||
|
||||
@@ -11,9 +11,9 @@ public class JSONDeserializerTest {
|
||||
public void parseTest(){
|
||||
final String jsonStr = "{\"customName\": \"customValue\", \"customAddress\": \"customAddressValue\"}";
|
||||
final TestBean testBean = JSONUtil.toBean(jsonStr, TestBean.class);
|
||||
Assert.assertNotNull(testBean);
|
||||
Assert.assertEquals("customValue", testBean.getName());
|
||||
Assert.assertEquals("customAddressValue", testBean.getAddress());
|
||||
Assertions.assertNotNull(testBean);
|
||||
Assertions.assertEquals("customValue", testBean.getName());
|
||||
Assertions.assertEquals("customAddressValue", testBean.getAddress());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JSONNullTest {
|
||||
|
||||
@@ -12,12 +12,12 @@ public class JSONNullTest {
|
||||
" \"device_status_date\": null,\n" +
|
||||
" \"imsi\": null,\n" +
|
||||
" \"act_date\": \"2021-07-23T06:23:26.000+00:00\"}");
|
||||
Assert.assertNull(bodyjson.get("device_model"));
|
||||
Assert.assertNull(bodyjson.get("device_status_date"));
|
||||
Assert.assertNull(bodyjson.get("imsi"));
|
||||
Assertions.assertNull(bodyjson.get("device_model"));
|
||||
Assertions.assertNull(bodyjson.get("device_status_date"));
|
||||
Assertions.assertNull(bodyjson.get("imsi"));
|
||||
|
||||
bodyjson.getConfig().setIgnoreNullValue(true);
|
||||
Assert.assertEquals("{\"act_date\":\"2021-07-23T06:23:26.000+00:00\"}", bodyjson.toString());
|
||||
Assertions.assertEquals("{\"act_date\":\"2021-07-23T06:23:26.000+00:00\"}", bodyjson.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -27,30 +27,30 @@ public class JSONNullTest {
|
||||
" \"device_status_date\": null,\n" +
|
||||
" \"imsi\": null,\n" +
|
||||
" \"act_date\": \"2021-07-23T06:23:26.000+00:00\"}", true);
|
||||
Assert.assertFalse(bodyjson.containsKey("device_model"));
|
||||
Assert.assertFalse(bodyjson.containsKey("device_status_date"));
|
||||
Assert.assertFalse(bodyjson.containsKey("imsi"));
|
||||
Assertions.assertFalse(bodyjson.containsKey("device_model"));
|
||||
Assertions.assertFalse(bodyjson.containsKey("device_status_date"));
|
||||
Assertions.assertFalse(bodyjson.containsKey("imsi"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNullTest(){
|
||||
// 忽略null
|
||||
String json1 = JSONUtil.ofObj().set("key1", null).toString();
|
||||
Assert.assertEquals("{}", json1);
|
||||
Assertions.assertEquals("{}", json1);
|
||||
|
||||
// 不忽略null
|
||||
json1 = JSONUtil.ofObj(JSONConfig.of().setIgnoreNullValue(false)).set("key1", null).toString();
|
||||
Assert.assertEquals("{\"key1\":null}", json1);
|
||||
Assertions.assertEquals("{\"key1\":null}", json1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNullOfJSONArrayTest(){
|
||||
// 忽略null
|
||||
String json1 = JSONUtil.ofArray().set(null).toString();
|
||||
Assert.assertEquals("[]", json1);
|
||||
Assertions.assertEquals("[]", json1);
|
||||
|
||||
// 不忽略null
|
||||
json1 = JSONUtil.ofArray(JSONConfig.of().setIgnoreNullValue(false)).set(null).toString();
|
||||
Assert.assertEquals("[null]", json1);
|
||||
Assertions.assertEquals("[null]", json1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import cn.hutool.json.test.bean.report.CaseReport;
|
||||
import cn.hutool.json.test.bean.report.StepReport;
|
||||
import cn.hutool.json.test.bean.report.SuiteReport;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringReader;
|
||||
@@ -48,9 +48,9 @@ public class JSONObjectTest {
|
||||
final String str = "{\"code\": 500, \"data\":null}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject jsonObject = new JSONObject(str);
|
||||
Assert.assertEquals("{\"code\":500,\"data\":null}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"code\":500,\"data\":null}", jsonObject.toString());
|
||||
jsonObject.getConfig().setIgnoreNullValue(true);
|
||||
Assert.assertEquals("{\"code\":500}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"code\":500}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +58,7 @@ public class JSONObjectTest {
|
||||
final String str = "{\"test\":\"关于开展2018年度“文明集体”、“文明职工”评选表彰活动的通知\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(str);
|
||||
Assert.assertEquals(str, json.toString());
|
||||
Assertions.assertEquals(str, json.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,17 +69,17 @@ public class JSONObjectTest {
|
||||
final JSONObject json = Objects.requireNonNull(JSONUtil.ofObj()//
|
||||
.set("dateTime", DateUtil.parse("2019-05-02 22:12:01")))//
|
||||
.setDateFormat(DatePattern.NORM_DATE_PATTERN);
|
||||
Assert.assertEquals("{\"dateTime\":\"2019-05-02\"}", json.toString());
|
||||
Assertions.assertEquals("{\"dateTime\":\"2019-05-02\"}", json.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWithDateTest() {
|
||||
JSONObject json = JSONUtil.ofObj().set("date", DateUtil.parse("2019-05-08 19:18:21"));
|
||||
assert json != null;
|
||||
Assert.assertEquals("{\"date\":1557314301000}", json.toString());
|
||||
Assertions.assertEquals("{\"date\":1557314301000}", json.toString());
|
||||
|
||||
json = Objects.requireNonNull(JSONUtil.ofObj().set("date", DateUtil.parse("2019-05-08 19:18:21"))).setDateFormat(DatePattern.NORM_DATE_PATTERN);
|
||||
Assert.assertEquals("{\"date\":\"2019-05-08\"}", json.toString());
|
||||
Assertions.assertEquals("{\"date\":\"2019-05-08\"}", json.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -98,22 +98,22 @@ public class JSONObjectTest {
|
||||
// putAll操作会覆盖相同key的值,因此a,b两个key的值改变,c的值不变
|
||||
json1.putAll(json2);
|
||||
|
||||
Assert.assertEquals(json1.get("a"), "value21");
|
||||
Assert.assertEquals(json1.get("b"), "value22");
|
||||
Assert.assertEquals(json1.get("c"), "value3");
|
||||
Assertions.assertEquals(json1.get("a"), "value21");
|
||||
Assertions.assertEquals(json1.get("b"), "value22");
|
||||
Assertions.assertEquals(json1.get("c"), "value3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseStringTest() {
|
||||
final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
||||
Assert.assertEquals(jsonObject.get("a"), "value1");
|
||||
Assert.assertEquals(jsonObject.get("b"), "value2");
|
||||
Assert.assertEquals(jsonObject.get("c"), "value3");
|
||||
Assert.assertEquals(jsonObject.get("d"), true);
|
||||
Assertions.assertEquals(jsonObject.get("a"), "value1");
|
||||
Assertions.assertEquals(jsonObject.get("b"), "value2");
|
||||
Assertions.assertEquals(jsonObject.get("c"), "value3");
|
||||
Assertions.assertEquals(jsonObject.get("d"), true);
|
||||
|
||||
Assert.assertTrue(jsonObject.containsKey("e"));
|
||||
Assert.assertNull(jsonObject.get("e"));
|
||||
Assertions.assertTrue(jsonObject.containsKey("e"));
|
||||
Assertions.assertNull(jsonObject.get("e"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,8 +121,8 @@ public class JSONObjectTest {
|
||||
final String jsonStr = "{\"file_name\":\"RMM20180127009_731.000\",\"error_data\":\"201121151350701001252500000032 18973908335 18973908335 13601893517 201711211700152017112115135420171121 6594000000010100000000000000000000000043190101701001910072 100001100 \",\"error_code\":\"F140\",\"error_info\":\"最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”\",\"app_name\":\"inter-pre-check\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(jsonStr);
|
||||
Assert.assertEquals("F140", json.getStr("error_code"));
|
||||
Assert.assertEquals("最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”", json.getStr("error_info"));
|
||||
Assertions.assertEquals("F140", json.getStr("error_code"));
|
||||
Assertions.assertEquals("最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”", json.getStr("error_info"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,7 +130,7 @@ public class JSONObjectTest {
|
||||
final String jsonStr = "{\"test\":\"体”、“文\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(jsonStr);
|
||||
Assert.assertEquals("体”、“文", json.getStr("test"));
|
||||
Assertions.assertEquals("体”、“文", json.getStr("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,8 +138,8 @@ public class JSONObjectTest {
|
||||
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(jsonStr);
|
||||
Assert.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,8 +147,8 @@ public class JSONObjectTest {
|
||||
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||
Assert.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,8 +158,8 @@ public class JSONObjectTest {
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(stringReader);
|
||||
Assert.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,8 +169,8 @@ public class JSONObjectTest {
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(in);
|
||||
Assert.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
Assertions.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,8 +179,8 @@ public class JSONObjectTest {
|
||||
final String jsonStr = "{\"a\":\"<div>aaa</div>\"}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject json = new JSONObject(jsonStr);
|
||||
Assert.assertEquals("<div>aaa</div>", json.get("a"));
|
||||
Assert.assertEquals(jsonStr, json.toString());
|
||||
Assertions.assertEquals("<div>aaa</div>", json.get("a"));
|
||||
Assertions.assertEquals(jsonStr, json.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,14 +193,14 @@ public class JSONObjectTest {
|
||||
.set("list", JSONUtil.ofArray().set("a").set("b")).set("testEnum", "TYPE_A");
|
||||
|
||||
final TestBean bean = json.toBean(TestBean.class);
|
||||
Assert.assertEquals("a", bean.getList().get(0));
|
||||
Assert.assertEquals("b", bean.getList().get(1));
|
||||
Assertions.assertEquals("a", bean.getList().get(0));
|
||||
Assertions.assertEquals("b", bean.getList().get(1));
|
||||
|
||||
Assert.assertEquals("strValue1", bean.getBeanValue().getValue1());
|
||||
Assertions.assertEquals("strValue1", bean.getBeanValue().getValue1());
|
||||
// BigDecimal转换检查
|
||||
Assert.assertEquals(new BigDecimal("234"), bean.getBeanValue().getValue2());
|
||||
Assertions.assertEquals(new BigDecimal("234"), bean.getBeanValue().getValue2());
|
||||
// 枚举转换检查
|
||||
Assert.assertEquals(TestEnum.TYPE_A, bean.getTestEnum());
|
||||
Assertions.assertEquals(TestEnum.TYPE_A, bean.getTestEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,9 +214,9 @@ public class JSONObjectTest {
|
||||
|
||||
final TestBean bean = json.toBean(TestBean.class);
|
||||
// 当JSON中为字符串"null"时应被当作字符串处理
|
||||
Assert.assertEquals("null", bean.getStrValue());
|
||||
Assertions.assertEquals("null", bean.getStrValue());
|
||||
// 当JSON中为字符串"null"时Bean中的字段类型不匹配应在ignoreError模式下忽略注入
|
||||
Assert.assertNull(bean.getBeanValue());
|
||||
Assertions.assertNull(bean.getBeanValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,16 +230,16 @@ public class JSONObjectTest {
|
||||
final JSONObject json = JSONUtil.parseObj(userA);
|
||||
final UserA userA2 = json.toBean(UserA.class);
|
||||
// 测试数组
|
||||
Assert.assertEquals("seq1", userA2.getSqs().get(0).getSeq());
|
||||
Assertions.assertEquals("seq1", userA2.getSqs().get(0).getSeq());
|
||||
// 测试带换行符等特殊字符转换是否成功
|
||||
Assert.assertTrue(StrUtil.isNotBlank(userA2.getName()));
|
||||
Assertions.assertTrue(StrUtil.isNotBlank(userA2.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBeanWithNullTest() {
|
||||
final String jsonStr = "{'data':{'userName':'ak','password': null}}";
|
||||
final UserWithMap user = JSONUtil.toBean(JSONUtil.parseObj(jsonStr), UserWithMap.class);
|
||||
Assert.assertTrue(user.getData().containsKey("password"));
|
||||
Assertions.assertTrue(user.getData().containsKey("password"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,7 +247,7 @@ public class JSONObjectTest {
|
||||
final String json = "{\"data\":{\"b\": \"c\"}}";
|
||||
|
||||
final UserWithMap map = JSONUtil.toBean(json, UserWithMap.class);
|
||||
Assert.assertEquals("c", map.getData().get("b"));
|
||||
Assertions.assertEquals("c", map.getData().get("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,12 +259,12 @@ public class JSONObjectTest {
|
||||
// 第一层
|
||||
final List<CaseReport> caseReports = bean.getCaseReports();
|
||||
final CaseReport caseReport = caseReports.get(0);
|
||||
Assert.assertNotNull(caseReport);
|
||||
Assertions.assertNotNull(caseReport);
|
||||
|
||||
// 第二层
|
||||
final List<StepReport> stepReports = caseReports.get(0).getStepReports();
|
||||
final StepReport stepReport = stepReports.get(0);
|
||||
Assert.assertNotNull(stepReport);
|
||||
Assertions.assertNotNull(stepReport);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,13 +280,13 @@ public class JSONObjectTest {
|
||||
.set("userId", "测试用户1"));
|
||||
|
||||
final TokenAuthWarp2 bean = json.toBean(TokenAuthWarp2.class);
|
||||
Assert.assertEquals("http://test.com", bean.getTargetUrl());
|
||||
Assert.assertEquals("true", bean.getSuccess());
|
||||
Assertions.assertEquals("http://test.com", bean.getTargetUrl());
|
||||
Assertions.assertEquals("true", bean.getSuccess());
|
||||
|
||||
final TokenAuthResponse result = bean.getResult();
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals("tokenTest", result.getToken());
|
||||
Assert.assertEquals("测试用户1", result.getUserId());
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals("tokenTest", result.getToken());
|
||||
Assertions.assertEquals("测试用户1", result.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +299,7 @@ public class JSONObjectTest {
|
||||
"\"secret\":\"dsadadqwdqs121d1e2\",\"message\":\"hello world\"},\"code\":100,\"" +
|
||||
"message\":\"validate message\"}";
|
||||
final ResultDto<?> dto = JSONUtil.toBean(jsonStr, ResultDto.class);
|
||||
Assert.assertEquals("validate message", dto.getMessage());
|
||||
Assertions.assertEquals("validate message", dto.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,8 +311,8 @@ public class JSONObjectTest {
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(userA, false);
|
||||
|
||||
Assert.assertTrue(json.containsKey("a"));
|
||||
Assert.assertTrue(json.getJSONArray("sqs").getJSONObject(0).containsKey("seq"));
|
||||
Assertions.assertTrue(json.containsKey("a"));
|
||||
Assertions.assertTrue(json.getJSONArray("sqs").getJSONObject(0).containsKey("seq"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -326,10 +326,10 @@ public class JSONObjectTest {
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(bean, false);
|
||||
// 枚举转换检查
|
||||
Assert.assertEquals("TYPE_B", json.get("testEnum"));
|
||||
Assertions.assertEquals("TYPE_B", json.get("testEnum"));
|
||||
|
||||
final TestBean bean2 = json.toBean(TestBean.class);
|
||||
Assert.assertEquals(bean.toString(), bean2.toString());
|
||||
Assertions.assertEquals(bean.toString(), bean2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -339,9 +339,9 @@ public class JSONObjectTest {
|
||||
.set("data", "{\"jobId\": \"abc\", \"videoUrl\": \"http://a.com/a.mp4\"}");
|
||||
|
||||
final JSONBean bean = json.toBean(JSONBean.class);
|
||||
Assert.assertEquals(22, bean.getCode());
|
||||
Assert.assertEquals("abc", bean.getData().getObj("jobId"));
|
||||
Assert.assertEquals("http://a.com/a.mp4", bean.getData().getObj("videoUrl"));
|
||||
Assertions.assertEquals(22, bean.getCode());
|
||||
Assertions.assertEquals("abc", bean.getData().getObj("jobId"));
|
||||
Assertions.assertEquals("http://a.com/a.mp4", bean.getData().getObj("videoUrl"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -354,8 +354,8 @@ public class JSONObjectTest {
|
||||
final JSONObject userAJson = JSONUtil.parseObj(userA);
|
||||
final UserB userB = JSONUtil.toBean(userAJson, UserB.class);
|
||||
|
||||
Assert.assertEquals(userA.getName(), userB.getName());
|
||||
Assert.assertEquals(userA.getDate(), userB.getDate());
|
||||
Assertions.assertEquals(userA.getName(), userB.getName());
|
||||
Assertions.assertEquals(userA.getDate(), userB.getDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -370,7 +370,7 @@ public class JSONObjectTest {
|
||||
userAJson.setDateFormat("yyyy-MM-dd");
|
||||
|
||||
final UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class);
|
||||
Assert.assertEquals(DateUtil.parse("2018-10-25"), bean.getDate());
|
||||
Assertions.assertEquals(DateUtil.parse("2018-10-25"), bean.getDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,7 +380,7 @@ public class JSONObjectTest {
|
||||
.set("name", "nameValue")
|
||||
.set("date", "08:00:00");
|
||||
final UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class);
|
||||
Assert.assertEquals(DateUtil.formatToday() + " 08:00:00", DateUtil.date(bean.getDate()).toString());
|
||||
Assertions.assertEquals(DateUtil.formatToday() + " 08:00:00", DateUtil.date(bean.getDate()).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -391,19 +391,19 @@ public class JSONObjectTest {
|
||||
userA.setDate(new Date());
|
||||
|
||||
final JSONObject userAJson = JSONUtil.parseObj(userA);
|
||||
Assert.assertFalse(userAJson.containsKey("a"));
|
||||
Assertions.assertFalse(userAJson.containsKey("a"));
|
||||
|
||||
final JSONObject userAJsonWithNullValue = JSONUtil.parseObj(userA, false);
|
||||
Assert.assertTrue(userAJsonWithNullValue.containsKey("a"));
|
||||
Assert.assertTrue(userAJsonWithNullValue.containsKey("sqs"));
|
||||
Assertions.assertTrue(userAJsonWithNullValue.containsKey("a"));
|
||||
Assertions.assertTrue(userAJsonWithNullValue.containsKey("sqs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specialCharTest() {
|
||||
final String json = "{\"pattern\": \"[abc]\b\u2001\", \"pattern2Json\": {\"patternText\": \"[ab]\\b\"}}";
|
||||
final JSONObject obj = JSONUtil.parseObj(json);
|
||||
Assert.assertEquals("[abc]\\b\\u2001", obj.getStrEscaped("pattern"));
|
||||
Assert.assertEquals("{\"patternText\":\"[ab]\\b\"}", obj.getStrEscaped("pattern2Json"));
|
||||
Assertions.assertEquals("[abc]\\b\\u2001", obj.getStrEscaped("pattern"));
|
||||
Assertions.assertEquals("{\"patternText\":\"[ab]\\b\"}", obj.getStrEscaped("pattern2Json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -412,12 +412,12 @@ public class JSONObjectTest {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
|
||||
// 没有转义按照默认规则显示
|
||||
Assert.assertEquals("yyb\nbbb", jsonObject.getStr("name"));
|
||||
Assertions.assertEquals("yyb\nbbb", jsonObject.getStr("name"));
|
||||
// 转义按照字符串显示
|
||||
Assert.assertEquals("yyb\\nbbb", jsonObject.getStrEscaped("name"));
|
||||
Assertions.assertEquals("yyb\\nbbb", jsonObject.getStrEscaped("name"));
|
||||
|
||||
final String bbb = jsonObject.getStr("bbb", "defaultBBB");
|
||||
Assert.assertEquals("defaultBBB", bbb);
|
||||
Assertions.assertEquals("defaultBBB", bbb);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -427,15 +427,15 @@ public class JSONObjectTest {
|
||||
beanWithAlias.setValue2(35);
|
||||
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(beanWithAlias);
|
||||
Assert.assertEquals("张三", jsonObject.getStr("name"));
|
||||
Assert.assertEquals(new Integer(35), jsonObject.getInt("age"));
|
||||
Assertions.assertEquals("张三", jsonObject.getStr("name"));
|
||||
Assertions.assertEquals(new Integer(35), jsonObject.getInt("age"));
|
||||
|
||||
final JSONObject json = JSONUtil.ofObj()
|
||||
.set("name", "张三")
|
||||
.set("age", 35);
|
||||
final BeanWithAlias bean = JSONUtil.toBean(Objects.requireNonNull(json).toString(), BeanWithAlias.class);
|
||||
Assert.assertEquals("张三", bean.getValue1());
|
||||
Assert.assertEquals(new Integer(35), bean.getValue2());
|
||||
Assertions.assertEquals("张三", bean.getValue1());
|
||||
Assertions.assertEquals(new Integer(35), bean.getValue2());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -447,7 +447,7 @@ public class JSONObjectTest {
|
||||
json.append("date", DateUtil.parse("2020-06-05 11:16:11"));
|
||||
json.append("bbb", "222");
|
||||
json.append("aaa", "123");
|
||||
Assert.assertEquals("{\"date\":\"2020-06-05 11:16:11\",\"bbb\":\"222\",\"aaa\":\"123\"}", json.toString());
|
||||
Assertions.assertEquals("{\"date\":\"2020-06-05 11:16:11\",\"bbb\":\"222\",\"aaa\":\"123\"}", json.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,11 +463,11 @@ public class JSONObjectTest {
|
||||
|
||||
final String jsonStr = "{\"date\":\"2020#06#05\",\"bbb\":\"222\",\"aaa\":\"123\"}";
|
||||
|
||||
Assert.assertEquals(jsonStr, json.toString());
|
||||
Assertions.assertEquals(jsonStr, json.toString());
|
||||
|
||||
// 解析测试
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig);
|
||||
Assert.assertEquals(DateUtil.beginOfDay(date), parse.getDate("date"));
|
||||
Assertions.assertEquals(DateUtil.beginOfDay(date), parse.getDate("date"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -479,11 +479,11 @@ public class JSONObjectTest {
|
||||
final JSONObject json = new JSONObject(jsonConfig);
|
||||
json.set("date", date);
|
||||
|
||||
Assert.assertEquals("{\"date\":1591326971}", json.toString());
|
||||
Assertions.assertEquals("{\"date\":1591326971}", json.toString());
|
||||
|
||||
// 解析测试
|
||||
final JSONObject parse = JSONUtil.parseObj(json.toString(), jsonConfig);
|
||||
Assert.assertEquals(date, DateUtil.date(parse.getDate("date")));
|
||||
Assertions.assertEquals(date, DateUtil.date(parse.getDate("date")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -499,11 +499,11 @@ public class JSONObjectTest {
|
||||
|
||||
final String jsonStr = "{\"date\":1591326971,\"bbb\":\"222\",\"aaa\":\"123\"}";
|
||||
|
||||
Assert.assertEquals(jsonStr, json.toString());
|
||||
Assertions.assertEquals(jsonStr, json.toString());
|
||||
|
||||
// 解析测试
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig);
|
||||
Assert.assertEquals(date, parse.getDate("date"));
|
||||
Assertions.assertEquals(date, parse.getDate("date"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -511,7 +511,7 @@ public class JSONObjectTest {
|
||||
final String timeStr = "1970-01-01 00:00:00";
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().set("time", timeStr);
|
||||
final Timestamp time = jsonObject.get("time", Timestamp.class);
|
||||
Assert.assertEquals("1970-01-01 00:00:00.0", time.toString());
|
||||
Assertions.assertEquals("1970-01-01 00:00:00.0", time.toString());
|
||||
}
|
||||
|
||||
public enum TestEnum {
|
||||
@@ -556,11 +556,11 @@ public class JSONObjectTest {
|
||||
public void parseBeanSameNameTest() {
|
||||
final SameNameBean sameNameBean = new SameNameBean();
|
||||
final JSONObject parse = JSONUtil.parseObj(sameNameBean);
|
||||
Assert.assertEquals("123", parse.getStr("username"));
|
||||
Assert.assertEquals("abc", parse.getStr("userName"));
|
||||
Assertions.assertEquals("123", parse.getStr("username"));
|
||||
Assertions.assertEquals("abc", parse.getStr("userName"));
|
||||
|
||||
// 测试ignore注解是否有效
|
||||
Assert.assertNull(parse.getStr("fieldToIgnore"));
|
||||
Assertions.assertNull(parse.getStr("fieldToIgnore"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -596,13 +596,15 @@ public class JSONObjectTest {
|
||||
final Map.Entry<String, String> next = entries.iterator().next();
|
||||
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(next);
|
||||
Assert.assertEquals("{\"test\":\"testValue\"}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"test\":\"testValue\"}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void createJSONObjectTest() {
|
||||
// 集合类不支持转为JSONObject
|
||||
new JSONObject(new JSONArray(), JSONConfig.of());
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
// 集合类不支持转为JSONObject
|
||||
new JSONObject(new JSONArray(), JSONConfig.of());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -611,26 +613,26 @@ public class JSONObjectTest {
|
||||
map.put("c", 2.0F);
|
||||
|
||||
final String s = JSONUtil.toJsonStr(map);
|
||||
Assert.assertEquals("{\"c\":2}", s);
|
||||
Assertions.assertEquals("{\"c\":2}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendTest() {
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().append("key1", "value1");
|
||||
Assert.assertEquals("{\"key1\":\"value1\"}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"key1\":\"value1\"}", jsonObject.toString());
|
||||
|
||||
jsonObject.append("key1", "value2");
|
||||
Assert.assertEquals("{\"key1\":[\"value1\",\"value2\"]}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"key1\":[\"value1\",\"value2\"]}", jsonObject.toString());
|
||||
|
||||
jsonObject.append("key1", "value3");
|
||||
Assert.assertEquals("{\"key1\":[\"value1\",\"value2\",\"value3\"]}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"key1\":[\"value1\",\"value2\",\"value3\"]}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putByPathTest() {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.putByPath("aa.bb", "BB");
|
||||
Assert.assertEquals("{\"aa\":{\"bb\":\"BB\"}}", json.toString());
|
||||
Assertions.assertEquals("{\"aa\":{\"bb\":\"BB\"}}", json.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -638,7 +640,7 @@ public class JSONObjectTest {
|
||||
public void bigDecimalTest() {
|
||||
final String jsonStr = "{\"orderId\":\"1704747698891333662002277\"}";
|
||||
final BigDecimalBean bigDecimalBean = JSONUtil.toBean(jsonStr, BigDecimalBean.class);
|
||||
Assert.assertEquals("{\"orderId\":1704747698891333662002277}", JSONUtil.toJsonStr(bigDecimalBean));
|
||||
Assertions.assertEquals("{\"orderId\":1704747698891333662002277}", JSONUtil.toJsonStr(bigDecimalBean));
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -656,7 +658,7 @@ public class JSONObjectTest {
|
||||
.set("d", true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> pair.getKey().equals("b"));
|
||||
Assert.assertEquals("{\"b\":\"value2\"}", s);
|
||||
Assertions.assertEquals("{\"b\":\"value2\"}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -668,7 +670,7 @@ public class JSONObjectTest {
|
||||
.set("d", true);
|
||||
|
||||
final String s = json1.toJSONString(0, (pair) -> false == pair.getKey().equals("b"));
|
||||
Assert.assertEquals("{\"a\":\"value1\",\"c\":\"value3\",\"d\":true}", s);
|
||||
Assertions.assertEquals("{\"a\":\"value1\",\"c\":\"value3\",\"d\":true}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -688,7 +690,7 @@ public class JSONObjectTest {
|
||||
// 除了"b",其他都去掉
|
||||
return false;
|
||||
});
|
||||
Assert.assertEquals("{\"b\":\"value2_edit\"}", s);
|
||||
Assertions.assertEquals("{\"b\":\"value2_edit\"}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -703,7 +705,7 @@ public class JSONObjectTest {
|
||||
pair.setKey(StrUtil.toUnderlineCase((String)pair.getKey()));
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals("{\"a_key\":\"value1\",\"b_job\":\"value2\",\"c_good\":\"value3\",\"d\":true}", s);
|
||||
Assertions.assertEquals("{\"a_key\":\"value1\",\"b_job\":\"value2\",\"c_good\":\"value3\",\"d\":true}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -716,7 +718,7 @@ public class JSONObjectTest {
|
||||
pair.setValue(ObjUtil.defaultIfNull(pair.getValue(), StrUtil.EMPTY));
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals("{\"a\":\"\",\"b\":\"value2\"}", s);
|
||||
Assertions.assertEquals("{\"a\":\"\",\"b\":\"value2\"}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -724,8 +726,8 @@ public class JSONObjectTest {
|
||||
final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject jsonObject = new JSONObject(jsonStr, null, (pair)-> "b".equals(pair.getKey()));
|
||||
Assert.assertEquals(1, jsonObject.size());
|
||||
Assert.assertEquals("value2", jsonObject.get("b"));
|
||||
Assertions.assertEquals(1, jsonObject.size());
|
||||
Assertions.assertEquals("value2", jsonObject.get("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -738,6 +740,6 @@ public class JSONObjectTest {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
Assert.assertEquals("value2_edit", jsonObject.get("b"));
|
||||
Assertions.assertEquals("value2_edit", jsonObject.get("b"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JSON路径单元测试
|
||||
@@ -15,9 +15,9 @@ public class JSONPathTest {
|
||||
public void getByPathTest() {
|
||||
final String json = "[{\"id\":\"1\",\"name\":\"xingming\"},{\"id\":\"2\",\"name\":\"mingzi\"}]";
|
||||
Object value = JSONUtil.parseArray(json).getByPath("[0].name");
|
||||
Assert.assertEquals("xingming", value);
|
||||
Assertions.assertEquals("xingming", value);
|
||||
value = JSONUtil.parseArray(json).getByPath("[1].name");
|
||||
Assert.assertEquals("mingzi", value);
|
||||
Assertions.assertEquals("mingzi", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -25,6 +25,6 @@ public class JSONPathTest {
|
||||
final String str = "{'accountId':111}";
|
||||
final JSON json = (JSON) JSONUtil.parse(str);
|
||||
final Long accountId = JSONUtil.getByPath(json, "$.accountId", 0L);
|
||||
Assert.assertEquals(111L, accountId.longValue());
|
||||
Assertions.assertEquals(111L, accountId.longValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* JSON字符串格式化单元测试
|
||||
@@ -16,25 +16,25 @@ public class JSONStrFormatterTest {
|
||||
public void formatTest() {
|
||||
final String json = "{'age':23,'aihao':['pashan','movies'],'name':{'firstName':'zhang','lastName':'san','aihao':['pashan','movies','name':{'firstName':'zhang','lastName':'san','aihao':['pashan','movies']}]}}";
|
||||
final String result = JSONStrFormatter.format(json);
|
||||
Assert.assertNotNull(result);
|
||||
Assertions.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatTest2() {
|
||||
final String json = "{\"abc\":{\"def\":\"\\\"[ghi]\"}}";
|
||||
final String result = JSONStrFormatter.format(json);
|
||||
Assert.assertNotNull(result);
|
||||
Assertions.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatTest3() {
|
||||
final String json = "{\"id\":13,\"title\":\"《标题》\",\"subtitle\":\"副标题z'c'z'xv'c'xv\",\"user_id\":6,\"type\":0}";
|
||||
final String result = JSONStrFormatter.format(json);
|
||||
Assert.assertNotNull(result);
|
||||
Assertions.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void formatTest4(){
|
||||
final String jsonStr = "{\"employees\":[{\"firstName\":\"Bill\",\"lastName\":\"Gates\"},{\"firstName\":\"George\",\"lastName\":\"Bush\"},{\"firstName\":\"Thomas\",\"lastName\":\"Carter\"}]}";
|
||||
Console.log(JSONUtil.formatJsonStr(jsonStr));
|
||||
|
||||
@@ -2,8 +2,8 @@ package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JSONSupportTest {
|
||||
|
||||
@@ -23,10 +23,10 @@ public class JSONSupportTest {
|
||||
|
||||
|
||||
final TestBean testBean = JSONUtil.toBean(jsonstr, TestBean.class);
|
||||
Assert.assertEquals("https://hutool.cn", testBean.getLocation());
|
||||
Assert.assertEquals("这是一条测试消息", testBean.getMessage());
|
||||
Assert.assertEquals("123456789", testBean.getRequestId());
|
||||
Assert.assertEquals("987654321", testBean.getTraceId());
|
||||
Assertions.assertEquals("https://hutool.cn", testBean.getLocation());
|
||||
Assertions.assertEquals("这是一条测试消息", testBean.getMessage());
|
||||
Assertions.assertEquals("123456789", testBean.getRequestId());
|
||||
Assertions.assertEquals("987654321", testBean.getTraceId());
|
||||
}
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JSONTokenerTest {
|
||||
@Test
|
||||
public void parseTest() {
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.getUtf8Reader("issue1200.json"));
|
||||
Assert.assertNotNull(jsonObject);
|
||||
Assertions.assertNotNull(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,65 +9,75 @@ import cn.hutool.json.test.bean.Price;
|
||||
import cn.hutool.json.test.bean.UserA;
|
||||
import cn.hutool.json.test.bean.UserC;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
public class JSONUtilTest {
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseInvalid() {
|
||||
JSONUtil.parse("abc");
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
JSONUtil.parse("abc");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseInvalid2() {
|
||||
JSONUtil.parse("'abc");
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
JSONUtil.parse("'abc");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseInvalid3() {
|
||||
JSONUtil.parse("\"abc");
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
JSONUtil.parse("\"abc");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValueTest() {
|
||||
Object parse = JSONUtil.parse(123);
|
||||
Assert.assertEquals(123, parse);
|
||||
Assertions.assertEquals(123, parse);
|
||||
|
||||
parse = JSONUtil.parse("\"abc\"");
|
||||
Assert.assertEquals("abc", parse);
|
||||
Assertions.assertEquals("abc", parse);
|
||||
|
||||
parse = JSONUtil.parse("true");
|
||||
Assert.assertEquals(true, parse);
|
||||
Assertions.assertEquals(true, parse);
|
||||
|
||||
parse = JSONUtil.parse("False");
|
||||
Assert.assertEquals(false, parse);
|
||||
Assertions.assertEquals(false, parse);
|
||||
|
||||
parse = JSONUtil.parse("null");
|
||||
Assert.assertNull(parse);
|
||||
Assertions.assertNull(parse);
|
||||
|
||||
parse = JSONUtil.parse("");
|
||||
Assert.assertNull(parse);
|
||||
Assertions.assertNull(parse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 出现语法错误时报错,检查解析\x字符时是否会导致死循环异常
|
||||
*/
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseTest() {
|
||||
JSONUtil.parseArray("[{\"a\":\"a\\x]");
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
JSONUtil.parseArray("[{\"a\":\"a\\x]");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字解析为JSONArray报错
|
||||
*/
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseNumberToJSONArrayTest() {
|
||||
final JSONArray json = JSONUtil.parseArray(123L);
|
||||
Assert.assertNotNull(json);
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final JSONArray json = JSONUtil.parseArray(123L);
|
||||
Assertions.assertNotNull(json);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,16 +87,18 @@ public class JSONUtilTest {
|
||||
public void parseNumberToJSONArrayTest2() {
|
||||
final JSONArray json = JSONUtil.parseArray(123L,
|
||||
JSONConfig.of().setIgnoreError(true));
|
||||
Assert.assertNotNull(json);
|
||||
Assertions.assertNotNull(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字解析为JSONArray报错
|
||||
*/
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void parseNumberToJSONObjectTest() {
|
||||
final JSONObject json = JSONUtil.parseObj(123L);
|
||||
Assert.assertNotNull(json);
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final JSONObject json = JSONUtil.parseObj(123L);
|
||||
Assertions.assertNotNull(json);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +107,7 @@ public class JSONUtilTest {
|
||||
@Test
|
||||
public void parseNumberToJSONObjectTest2() {
|
||||
final JSONObject json = JSONUtil.parseObj(123L, JSONConfig.of().setIgnoreError(true));
|
||||
Assert.assertEquals(new JSONObject(), json);
|
||||
Assertions.assertEquals(new JSONObject(), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +128,7 @@ public class JSONUtilTest {
|
||||
|
||||
final String str = JSONUtil.toJsonPrettyStr(map);
|
||||
JSONUtil.parse(str);
|
||||
Assert.assertNotNull(str);
|
||||
Assertions.assertNotNull(str);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,10 +143,10 @@ public class JSONUtilTest {
|
||||
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(data);
|
||||
|
||||
Assert.assertTrue(jsonObject.containsKey("model"));
|
||||
Assert.assertEquals(1, jsonObject.getJSONObject("model").getInt("type").intValue());
|
||||
Assert.assertEquals("17610836523", jsonObject.getJSONObject("model").getStr("mobile"));
|
||||
// Assert.assertEquals("{\"model\":{\"type\":1,\"mobile\":\"17610836523\"}}", jsonObject.toString());
|
||||
Assertions.assertTrue(jsonObject.containsKey("model"));
|
||||
Assertions.assertEquals(1, jsonObject.getJSONObject("model").getInt("type").intValue());
|
||||
Assertions.assertEquals("17610836523", jsonObject.getJSONObject("model").getStr("mobile"));
|
||||
// Assertions.assertEquals("{\"model\":{\"type\":1,\"mobile\":\"17610836523\"}}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,11 +161,11 @@ public class JSONUtilTest {
|
||||
map.put("user", object.toString());
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(map);
|
||||
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json.get("user"));
|
||||
Assert.assertEquals("{\"user\":\"{\\\"name\\\":\\\"123123\\\",\\\"value\\\":\\\"\\\\\\\\\\\",\\\"value2\\\":\\\"</\\\"}\"}", json.toString());
|
||||
Assertions.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json.get("user"));
|
||||
Assertions.assertEquals("{\"user\":\"{\\\"name\\\":\\\"123123\\\",\\\"value\\\":\\\"\\\\\\\\\\\",\\\"value2\\\":\\\"</\\\"}\"}", json.toString());
|
||||
|
||||
final JSONObject json2 = JSONUtil.parseObj(json.toString());
|
||||
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json2.get("user"));
|
||||
Assertions.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json2.get("user"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +180,7 @@ public class JSONUtilTest {
|
||||
put("c", "c");
|
||||
}};
|
||||
|
||||
Assert.assertEquals("{\"attributes\":\"a\",\"b\":\"b\",\"c\":\"c\"}", JSONUtil.toJsonStr(sortedMap));
|
||||
Assertions.assertEquals("{\"attributes\":\"a\",\"b\":\"b\",\"c\":\"c\"}", JSONUtil.toJsonStr(sortedMap));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +191,7 @@ public class JSONUtilTest {
|
||||
final String json = "{\"ADT\":[[{\"BookingCode\":[\"N\",\"N\"]}]]}";
|
||||
|
||||
final Price price = JSONUtil.toBean(json, Price.class);
|
||||
Assert.assertEquals("N", price.getADT().get(0).get(0).getBookingCode().get(0));
|
||||
Assertions.assertEquals("N", price.getADT().get(0).get(0).getBookingCode().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,36 +199,36 @@ public class JSONUtilTest {
|
||||
// 测试JSONObject转为Bean中字符串字段的情况
|
||||
final String json = "{\"id\":123,\"name\":\"张三\",\"prop\":{\"gender\":\"男\", \"age\":18}}";
|
||||
final UserC user = JSONUtil.toBean(json, UserC.class);
|
||||
Assert.assertNotNull(user.getProp());
|
||||
Assertions.assertNotNull(user.getProp());
|
||||
final String prop = user.getProp();
|
||||
final JSONObject propJson = JSONUtil.parseObj(prop);
|
||||
Assert.assertEquals("男", propJson.getStr("gender"));
|
||||
Assert.assertEquals(18, propJson.getInt("age").intValue());
|
||||
// Assert.assertEquals("{\"age\":18,\"gender\":\"男\"}", user.getProp());
|
||||
Assertions.assertEquals("男", propJson.getStr("gender"));
|
||||
Assertions.assertEquals(18, propJson.getInt("age").intValue());
|
||||
// Assertions.assertEquals("{\"age\":18,\"gender\":\"男\"}", user.getProp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStrTest() {
|
||||
final String html = "{\"name\":\"Something must have been changed since you leave\"}";
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(html);
|
||||
Assert.assertEquals("Something must have been changed since you leave", jsonObject.getStr("name"));
|
||||
Assertions.assertEquals("Something must have been changed since you leave", jsonObject.getStr("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStrTest2() {
|
||||
final String html = "{\"name\":\"Something\\u00a0must have been changed since you leave\"}";
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(html);
|
||||
Assert.assertEquals("Something\\u00a0must\\u00a0have\\u00a0been\\u00a0changed\\u00a0since\\u00a0you\\u00a0leave", jsonObject.getStrEscaped("name"));
|
||||
Assertions.assertEquals("Something\\u00a0must\\u00a0have\\u00a0been\\u00a0changed\\u00a0since\\u00a0you\\u00a0leave", jsonObject.getStrEscaped("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFromXmlTest() {
|
||||
final String s = "<sfzh>640102197312070614</sfzh><sfz>640102197312070614X</sfz><name>aa</name><gender>1</gender>";
|
||||
final JSONObject json = JSONUtil.parseFromXml(s);
|
||||
Assert.assertEquals(640102197312070614L, json.get("sfzh"));
|
||||
Assert.assertEquals("640102197312070614X", json.get("sfz"));
|
||||
Assert.assertEquals("aa", json.get("name"));
|
||||
Assert.assertEquals(1, json.get("gender"));
|
||||
Assertions.assertEquals(640102197312070614L, json.get("sfzh"));
|
||||
Assertions.assertEquals("640102197312070614X", json.get("sfz"));
|
||||
Assertions.assertEquals("aa", json.get("name"));
|
||||
Assertions.assertEquals(1, json.get("gender"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,7 +236,7 @@ public class JSONUtilTest {
|
||||
final String json = "{\"test\": 12.00}";
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(json);
|
||||
//noinspection BigDecimalMethodWithoutRoundingCalled
|
||||
Assert.assertEquals("12.00", jsonObject.getBigDecimal("test").setScale(2).toString());
|
||||
Assertions.assertEquals("12.00", jsonObject.getBigDecimal("test").setScale(2).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,7 +244,7 @@ public class JSONUtilTest {
|
||||
final JSONObject jsonObject = JSONUtil.ofObj()
|
||||
.set("test2", (JSONStringer) () -> NumberUtil.format("#.0", 12.00D));
|
||||
|
||||
Assert.assertEquals("{\"test2\":12.0}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"test2\":12.0}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -240,16 +252,16 @@ public class JSONUtilTest {
|
||||
// 默认去除多余的0
|
||||
final JSONObject jsonObjectDefault = JSONUtil.ofObj()
|
||||
.set("test2", 12.00D);
|
||||
Assert.assertEquals("{\"test2\":12}", jsonObjectDefault.toString());
|
||||
Assertions.assertEquals("{\"test2\":12}", jsonObjectDefault.toString());
|
||||
|
||||
// 不去除多余的0
|
||||
final JSONObject jsonObject = JSONUtil.ofObj(JSONConfig.of().setStripTrailingZeros(false))
|
||||
.set("test2", 12.00D);
|
||||
Assert.assertEquals("{\"test2\":12.0}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"test2\":12.0}", jsonObject.toString());
|
||||
|
||||
// 去除多余的0
|
||||
jsonObject.getConfig().setStripTrailingZeros(true);
|
||||
Assert.assertEquals("{\"test2\":12}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"test2\":12}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,7 +271,7 @@ public class JSONUtilTest {
|
||||
" \"test\": \"\\\\地库地库\",\n" +
|
||||
"}");
|
||||
|
||||
Assert.assertEquals("\\地库地库", jsonObject.getObj("test"));
|
||||
Assertions.assertEquals("\\地库地库", jsonObject.getObj("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -267,14 +279,14 @@ public class JSONUtilTest {
|
||||
//https://github.com/dromara/hutool/issues/1399
|
||||
// SQLException实现了Iterable接口,默认是遍历之,会栈溢出,修正后只返回string
|
||||
final JSONObject set = JSONUtil.ofObj().set("test", new SQLException("test"));
|
||||
Assert.assertEquals("{\"test\":\"java.sql.SQLException: test\"}", set.toString());
|
||||
Assertions.assertEquals("{\"test\":\"java.sql.SQLException: test\"}", set.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseBigNumberTest(){
|
||||
// 科学计数法使用BigDecimal处理,默认输出非科学计数形式
|
||||
final String str = "{\"test\":100000054128897953e4}";
|
||||
Assert.assertEquals("{\"test\":1000000541288979530000}", JSONUtil.parseObj(str).toString());
|
||||
Assertions.assertEquals("{\"test\":1000000541288979530000}", JSONUtil.parseObj(str).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -283,23 +295,25 @@ public class JSONUtilTest {
|
||||
obj.set("key1", "v1")
|
||||
.set("key2", ListUtil.view("a", "b", "c"));
|
||||
final String xmlStr = JSONUtil.toXmlStr(obj);
|
||||
Assert.assertEquals("<key1>v1</key1><key2>a</key2><key2>b</key2><key2>c</key2>", xmlStr);
|
||||
Assertions.assertEquals("<key1>v1</key1><key2>a</key2><key2>b</key2><key2>c</key2>", xmlStr);
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
@Test
|
||||
public void toJsonStrOfStringTest(){
|
||||
final String a = "a";
|
||||
Assertions.assertThrows(JSONException.class, ()->{
|
||||
final String a = "a";
|
||||
|
||||
// 普通字符串不能解析为JSON字符串,必须由双引号或者单引号包裹
|
||||
final String s = JSONUtil.toJsonStr(a);
|
||||
Assert.assertEquals(a, s);
|
||||
// 普通字符串不能解析为JSON字符串,必须由双引号或者单引号包裹
|
||||
final String s = JSONUtil.toJsonStr(a);
|
||||
Assertions.assertEquals(a, s);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJsonStrOfNumberTest(){
|
||||
final int a = 1;
|
||||
final String s = JSONUtil.toJsonStr(a);
|
||||
Assert.assertEquals("1", s);
|
||||
Assertions.assertEquals("1", s);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +323,7 @@ public class JSONUtilTest {
|
||||
public void testArrayEntity() {
|
||||
final String jsonStr = JSONUtil.toJsonStr(new ArrayEntity());
|
||||
// a为空的bytes数组,按照空的流对待
|
||||
Assert.assertEquals("{\"b\":[0],\"c\":[],\"d\":[],\"e\":[]}", jsonStr);
|
||||
Assertions.assertEquals("{\"b\":[0],\"c\":[],\"d\":[],\"e\":[]}", jsonStr);
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -15,13 +15,13 @@ public class JSONWriterTest {
|
||||
|
||||
// 日期原样写入
|
||||
final Date date = jsonObject.getDate("date");
|
||||
Assert.assertEquals("2022-09-30 00:00:00", date.toString());
|
||||
Assertions.assertEquals("2022-09-30 00:00:00", date.toString());
|
||||
|
||||
// 自定义日期格式生效
|
||||
Assert.assertEquals("{\"date\":\"2022-09-30\"}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"date\":\"2022-09-30\"}", jsonObject.toString());
|
||||
|
||||
// 自定义日期格式解析生效
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonObject.toString(), JSONConfig.of().setDateFormat("yyyy-MM-dd"));
|
||||
Assert.assertEquals(String.class, parse.get("date").getClass());
|
||||
Assertions.assertEquals(String.class, parse.get("date").getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ParseBeanTest {
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(a);
|
||||
final A a1 = JSONUtil.toBean(json, A.class);
|
||||
Assert.assertEquals(json.toString(), JSONUtil.toJsonStr(a1));
|
||||
Assertions.assertEquals(json.toString(), JSONUtil.toJsonStr(a1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
@@ -14,7 +14,7 @@ public class Pr192Test {
|
||||
final String number = "1234.123456789123456";
|
||||
final String jsonString = "{\"create\":{\"details\":[{\"price\":" + number + "}]}}";
|
||||
final WebCreate create = JSONUtil.toBean(jsonString, WebCreate.class);
|
||||
Assert.assertEquals(number,create.getCreate().getDetails().get(0).getPrice().toString());
|
||||
Assertions.assertEquals(number,create.getCreate().getDetails().get(0).getPrice().toString());
|
||||
}
|
||||
|
||||
static class WebCreate {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TransientTest {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TransientTest {
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject jsonObject = new JSONObject(detailBill,
|
||||
JSONConfig.of().setTransientSupport(false));
|
||||
Assert.assertEquals("{\"id\":\"3243\",\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"id\":\"3243\",\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -33,7 +33,7 @@ public class TransientTest {
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
final JSONObject jsonObject = new JSONObject(detailBill,
|
||||
JSONConfig.of().setTransientSupport(true));
|
||||
Assert.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,8 +46,8 @@ public class TransientTest {
|
||||
JSONConfig.of().setTransientSupport(false));
|
||||
|
||||
final Bill bill = jsonObject.toBean(Bill.class);
|
||||
Assert.assertEquals("3243", bill.getId());
|
||||
Assert.assertEquals("bizNo", bill.getBizNo());
|
||||
Assertions.assertEquals("3243", bill.getId());
|
||||
Assertions.assertEquals("bizNo", bill.getBizNo());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +60,7 @@ public class TransientTest {
|
||||
JSONConfig.of().setTransientSupport(true));
|
||||
|
||||
final Bill bill = jsonObject.toBean(Bill.class);
|
||||
Assert.assertNull(bill.getId());
|
||||
Assert.assertEquals("bizNo", bill.getBizNo());
|
||||
Assertions.assertNull(bill.getId());
|
||||
Assertions.assertEquals("bizNo", bill.getBizNo());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import cn.hutool.json.JSONConfig;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class IssueIVMD5Test {
|
||||
final BaseResult<StudentInfo> bean = JSONUtil.toBean(jsonStr, JSONConfig.of(), typeReference.getType());
|
||||
|
||||
final StudentInfo data2 = bean.getData2();
|
||||
Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", data2.getAccountId());
|
||||
Assertions.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", data2.getAccountId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +37,6 @@ public class IssueIVMD5Test {
|
||||
|
||||
final List<StudentInfo> data = bean.getData();
|
||||
final StudentInfo studentInfo = data.get(0);
|
||||
Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", studentInfo.getAccountId());
|
||||
Assertions.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", studentInfo.getAccountId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json.jwt;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -31,11 +31,11 @@ public class IssueI5QRUOTest {
|
||||
};
|
||||
|
||||
final String token = JWTUtil.createToken(header, payload, "123456".getBytes());
|
||||
Assert.assertEquals("eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9." +
|
||||
Assertions.assertEquals("eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9." +
|
||||
"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." +
|
||||
"3Ywq9NlR3cBST4nfcdbR-fcZ8374RHzU50X6flKvG-tnWFMalMaHRm3cMpXs1NrZ", token);
|
||||
|
||||
final boolean verify = JWT.of(token).setKey("123456".getBytes()).verify();
|
||||
Assert.assertTrue(verify);
|
||||
Assertions.assertTrue(verify);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import cn.hutool.core.date.TimeUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -23,11 +23,11 @@ public class IssueI6IS5BTest {
|
||||
final JwtToken jwtToken = new JwtToken();
|
||||
jwtToken.setIat(iat);
|
||||
final String token = JWTUtil.createToken(JSONUtil.parseObj(jwtToken), "123".getBytes(StandardCharsets.UTF_8));
|
||||
Assert.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);
|
||||
Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);
|
||||
final JSONObject payloads = JWTUtil.parseToken(token).getPayloads();
|
||||
Assert.assertEquals("{\"iat\":1677772800}", payloads.toString());
|
||||
Assertions.assertEquals("{\"iat\":1677772800}", payloads.toString());
|
||||
final JwtToken o = payloads.toBean(JwtToken.class);
|
||||
Assert.assertEquals(iat, o.getIat());
|
||||
Assertions.assertEquals(iat, o.getIat());
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -41,11 +41,11 @@ public class IssueI6IS5BTest {
|
||||
final JwtToken2 jwtToken = new JwtToken2();
|
||||
jwtToken.setIat(iat);
|
||||
final String token = JWTUtil.createToken(JSONUtil.parseObj(jwtToken), "123".getBytes(StandardCharsets.UTF_8));
|
||||
Assert.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);
|
||||
Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token);
|
||||
final JSONObject payloads = JWTUtil.parseToken(token).getPayloads();
|
||||
Assert.assertEquals("{\"iat\":1677772800}", payloads.toString());
|
||||
Assertions.assertEquals("{\"iat\":1677772800}", payloads.toString());
|
||||
final JwtToken2 o = payloads.toBean(JwtToken2.class);
|
||||
Assert.assertEquals(iat, o.getIat());
|
||||
Assertions.assertEquals(iat, o.getIat());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -5,8 +5,8 @@ import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.json.jwt.signers.AlgorithmUtil;
|
||||
import cn.hutool.json.jwt.signers.JWTSigner;
|
||||
import cn.hutool.json.jwt.signers.JWTSignerUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JWTSignerTest {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class JWTSignerTest {
|
||||
public void hs256Test(){
|
||||
final String id = "hs256";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class JWTSignerTest {
|
||||
public void hs384Test(){
|
||||
final String id = "hs384";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class JWTSignerTest {
|
||||
public void hs512Test(){
|
||||
final String id = "hs512";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class JWTSignerTest {
|
||||
public void rs256Test(){
|
||||
final String id = "rs256";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class JWTSignerTest {
|
||||
public void rs384Test(){
|
||||
final String id = "rs384";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class JWTSignerTest {
|
||||
public void rs512Test(){
|
||||
final String id = "rs512";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class JWTSignerTest {
|
||||
public void es256Test(){
|
||||
final String id = "es256";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class JWTSignerTest {
|
||||
public void es384Test(){
|
||||
final String id = "es384";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class JWTSignerTest {
|
||||
public void es512Test(){
|
||||
final String id = "es512";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class JWTSignerTest {
|
||||
public void ps256Test(){
|
||||
final String id = "ps256";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class JWTSignerTest {
|
||||
public void ps384Test(){
|
||||
final String id = "ps384";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class JWTSignerTest {
|
||||
public void hmd5Test(){
|
||||
final String id = "hmd5";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class JWTSignerTest {
|
||||
public void hsha1Test(){
|
||||
final String id = "hsha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class JWTSignerTest {
|
||||
public void sm4cmacTest(){
|
||||
final String id = "sm4cmac";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -147,7 +147,7 @@ public class JWTSignerTest {
|
||||
public void rmd2Test(){
|
||||
final String id = "rmd2";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public class JWTSignerTest {
|
||||
public void rmd5Test(){
|
||||
final String id = "rmd5";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public class JWTSignerTest {
|
||||
public void rsha1Test(){
|
||||
final String id = "rsha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ public class JWTSignerTest {
|
||||
public void dnoneTest(){
|
||||
final String id = "dnone";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -183,7 +183,7 @@ public class JWTSignerTest {
|
||||
public void dsha1Test(){
|
||||
final String id = "dsha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -192,7 +192,7 @@ public class JWTSignerTest {
|
||||
public void enoneTest(){
|
||||
final String id = "enone";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -201,7 +201,7 @@ public class JWTSignerTest {
|
||||
public void esha1Test(){
|
||||
final String id = "esha1";
|
||||
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
|
||||
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
|
||||
|
||||
signAndVerify(signer);
|
||||
}
|
||||
@@ -215,6 +215,6 @@ public class JWTSignerTest {
|
||||
.setSigner(signer);
|
||||
|
||||
final String token = jwt.sign();
|
||||
Assert.assertTrue(JWT.of(token).verify(signer));
|
||||
Assertions.assertTrue(JWT.of(token).verify(signer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import cn.hutool.json.jwt.signers.AlgorithmUtil;
|
||||
import cn.hutool.json.jwt.signers.JWTSigner;
|
||||
import cn.hutool.json.jwt.signers.JWTSignerUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -29,9 +29,9 @@ public class JWTTest {
|
||||
"bXlSnqVeJXWqUIt7HyEhgKNVlIPjkumHlAwFY-5YCtk";
|
||||
|
||||
final String token = jwt.sign();
|
||||
Assert.assertEquals(rightToken, token);
|
||||
Assertions.assertEquals(rightToken, token);
|
||||
|
||||
Assert.assertTrue(JWT.of(rightToken).setKey(key).verify());
|
||||
Assertions.assertTrue(JWT.of(rightToken).setKey(key).verify());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,17 +42,17 @@ public class JWTTest {
|
||||
|
||||
final JWT jwt = JWT.of(rightToken);
|
||||
|
||||
Assert.assertTrue(jwt.setKey("1234567890".getBytes()).verify());
|
||||
Assertions.assertTrue(jwt.setKey("1234567890".getBytes()).verify());
|
||||
|
||||
//header
|
||||
Assert.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE));
|
||||
Assert.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM));
|
||||
Assert.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE));
|
||||
Assertions.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE));
|
||||
Assertions.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM));
|
||||
Assertions.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE));
|
||||
|
||||
//payload
|
||||
Assert.assertEquals("1234567890", jwt.getPayload("sub"));
|
||||
Assert.assertEquals("looly", jwt.getPayload("name"));
|
||||
Assert.assertEquals(true, jwt.getPayload("admin"));
|
||||
Assertions.assertEquals("1234567890", jwt.getPayload("sub"));
|
||||
Assertions.assertEquals("looly", jwt.getPayload("name"));
|
||||
Assertions.assertEquals(true, jwt.getPayload("admin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,26 +63,28 @@ public class JWTTest {
|
||||
.setPayload("admin", true)
|
||||
.setSigner(JWTSignerUtil.none());
|
||||
|
||||
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
|
||||
"eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9.";
|
||||
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0." +
|
||||
"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Imxvb2x5IiwiYWRtaW4iOnRydWV9.";
|
||||
|
||||
final String token = jwt.sign();
|
||||
Assert.assertEquals(token, token);
|
||||
Assertions.assertEquals(rightToken, token);
|
||||
|
||||
Assert.assertTrue(JWT.of(rightToken).setSigner(JWTSignerUtil.none()).verify());
|
||||
Assertions.assertTrue(JWT.of(rightToken).setSigner(JWTSignerUtil.none()).verify());
|
||||
}
|
||||
|
||||
/**
|
||||
* 必须定义签名器
|
||||
*/
|
||||
@Test(expected = JWTException.class)
|
||||
@Test
|
||||
public void needSignerTest(){
|
||||
final JWT jwt = JWT.of()
|
||||
Assertions.assertThrows(JWTException.class, ()->{
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("sub", "1234567890")
|
||||
.setPayload("name", "looly")
|
||||
.setPayload("admin", true);
|
||||
|
||||
jwt.sign();
|
||||
jwt.sign();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +94,7 @@ public class JWTTest {
|
||||
"aixF1eKlAKS_k3ynFnStE7-IRGiD5YaqznvK2xEjBew";
|
||||
|
||||
final boolean verify = JWT.of(token).setKey(ByteUtil.toUtf8Bytes("123456")).verify();
|
||||
Assert.assertTrue(verify);
|
||||
Assertions.assertTrue(verify);
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -135,15 +137,15 @@ public class JWTTest {
|
||||
final Integer numRes = jwt.getPayload("number", Integer.class);
|
||||
final HashMap<?, ?> mapRes = jwt.getPayload("map", HashMap.class);
|
||||
|
||||
Assert.assertEquals(bean, beanRes);
|
||||
Assert.assertEquals(numRes, num);
|
||||
Assert.assertEquals(username, strRes);
|
||||
Assert.assertEquals(list, listRes);
|
||||
Assertions.assertEquals(bean, beanRes);
|
||||
Assertions.assertEquals(numRes, num);
|
||||
Assertions.assertEquals(username, strRes);
|
||||
Assertions.assertEquals(list, listRes);
|
||||
|
||||
final String formattedDate = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
|
||||
final String formattedRes = DateUtil.format(dateRes, "yyyy-MM-dd HH:mm:ss");
|
||||
Assert.assertEquals(formattedDate, formattedRes);
|
||||
Assert.assertEquals(map, mapRes);
|
||||
Assertions.assertEquals(formattedDate, formattedRes);
|
||||
Assertions.assertEquals(map, mapRes);
|
||||
}
|
||||
|
||||
@Test()
|
||||
@@ -155,7 +157,7 @@ public class JWTTest {
|
||||
|
||||
// 签发时间早于被检查的时间
|
||||
final Date date = JWT.of(token).getPayload().getClaimsJson().getDate(JWTPayload.ISSUED_AT);
|
||||
Assert.assertEquals("2022-02-02", DateUtil.format(date, DatePattern.NORM_DATE_PATTERN));
|
||||
Assertions.assertEquals("2022-02-02", DateUtil.format(date, DatePattern.NORM_DATE_PATTERN));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,22 +167,21 @@ public class JWTTest {
|
||||
final JWTSigner jwtSigner = JWTSignerUtil.createSigner(AlgorithmUtil.getAlgorithm("HS256"), Base64.getDecoder().decode("abcdefghijklmn"));
|
||||
final String sign = JWT.of().addPayloads(map).sign(jwtSigner);
|
||||
final Object test2 = JWT.of(sign).getPayload().getClaim("test2");
|
||||
Assert.assertEquals(Long.class, test2.getClass());
|
||||
Assertions.assertEquals(Long.class, test2.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLongTest(){
|
||||
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9"
|
||||
+ ".eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiJhZG1pbiIsImRldmljZSI6ImRlZmF1bHQtZGV2aWNlIiwiZWZmIjoxNjc4Mjg1NzEzOTM1LCJyblN0ciI6IkVuMTczWFhvWUNaaVZUWFNGOTNsN1pabGtOalNTd0pmIn0"
|
||||
+ ".wRe2soTaWYPhwcjxdzesDi1BgEm9D61K-mMT3fPc4YM"
|
||||
+ "";
|
||||
+ ".wRe2soTaWYPhwcjxdzesDi1BgEm9D61K-mMT3fPc4YM";
|
||||
|
||||
final JWT jwt = JWTUtil.parseToken(rightToken);
|
||||
|
||||
Assert.assertEquals(
|
||||
Assertions.assertEquals(
|
||||
"{\"loginType\":\"login\",\"loginId\":\"admin\",\"device\":\"default-device\"," +
|
||||
"\"eff\":1678285713935,\"rnStr\":\"En173XXoYCZiVTXSF93l7ZZlkNjSSwJf\"}",
|
||||
jwt.getPayloads().toString());
|
||||
Assert.assertEquals(Long.valueOf(1678285713935L), jwt.getPayloads().getLong("eff"));
|
||||
Assertions.assertEquals(Long.valueOf(1678285713935L), jwt.getPayloads().getLong("eff"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.json.jwt;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -30,35 +30,41 @@ public class JWTUtilTest {
|
||||
"U2aQkC2THYV9L0fTN-yBBI7gmo5xhmvMhATtu8v0zEA";
|
||||
final JWT jwt = JWTUtil.parseToken(rightToken);
|
||||
|
||||
Assert.assertTrue(jwt.setKey("1234567890".getBytes()).verify());
|
||||
Assertions.assertTrue(jwt.setKey("1234567890".getBytes()).verify());
|
||||
|
||||
//header
|
||||
Assert.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE));
|
||||
Assert.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM));
|
||||
Assert.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE));
|
||||
Assertions.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE));
|
||||
Assertions.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM));
|
||||
Assertions.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE));
|
||||
|
||||
//payload
|
||||
Assert.assertEquals("1234567890", jwt.getPayload("sub"));
|
||||
Assert.assertEquals("looly", jwt.getPayload("name"));
|
||||
Assert.assertEquals(true, jwt.getPayload("admin"));
|
||||
Assertions.assertEquals("1234567890", jwt.getPayload("sub"));
|
||||
Assertions.assertEquals("looly", jwt.getPayload("name"));
|
||||
Assertions.assertEquals(true, jwt.getPayload("admin"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void parseNullTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I5OCQB
|
||||
JWTUtil.parseToken(null);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
||||
// https://gitee.com/dromara/hutool/issues/I5OCQB
|
||||
JWTUtil.parseToken(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void parseEmptyTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I5OCQB
|
||||
JWTUtil.parseToken("");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
||||
// https://gitee.com/dromara/hutool/issues/I5OCQB
|
||||
JWTUtil.parseToken("");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void parseBlankTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I5OCQB
|
||||
JWTUtil.parseToken(" ");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
||||
// https://gitee.com/dromara/hutool/issues/I5OCQB
|
||||
JWTUtil.parseToken(" ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,6 +74,6 @@ public class JWTUtilTest {
|
||||
"aixF1eKlAKS_k3ynFnStE7-IRGiD5YaqznvK2xEjBew";
|
||||
|
||||
final boolean verify = JWTUtil.verify(token, "123456".getBytes());
|
||||
Assert.assertTrue(verify);
|
||||
Assertions.assertTrue(verify);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,28 +3,32 @@ package cn.hutool.json.jwt;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.json.jwt.signers.JWTSignerUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class JWTValidatorTest {
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
@Test
|
||||
public void expiredAtTest(){
|
||||
final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo";
|
||||
JWTValidator.of(token).validateDate(DateUtil.now());
|
||||
Assertions.assertThrows(ValidateException.class, ()->{
|
||||
final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo";
|
||||
JWTValidator.of(token).validateDate(DateUtil.now());
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
@Test
|
||||
public void issueAtTest(){
|
||||
final String token = JWT.of()
|
||||
Assertions.assertThrows(ValidateException.class, ()->{
|
||||
final String token = JWT.of()
|
||||
.setIssuedAt(DateUtil.now())
|
||||
.setKey("123456".getBytes())
|
||||
.sign();
|
||||
|
||||
// 签发时间早于被检查的时间
|
||||
JWTValidator.of(token).validateDate(DateUtil.yesterday());
|
||||
// 签发时间早于被检查的时间
|
||||
JWTValidator.of(token).validateDate(DateUtil.yesterday());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -38,12 +42,14 @@ public class JWTValidatorTest {
|
||||
JWTValidator.of(token).validateDate(DateUtil.now());
|
||||
}
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
@Test
|
||||
public void notBeforeTest(){
|
||||
final JWT jwt = JWT.of()
|
||||
Assertions.assertThrows(ValidateException.class, ()->{
|
||||
final JWT jwt = JWT.of()
|
||||
.setNotBefore(DateUtil.now());
|
||||
|
||||
JWTValidator.of(jwt).validateDate(DateUtil.yesterday());
|
||||
JWTValidator.of(jwt).validateDate(DateUtil.yesterday());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,17 +75,19 @@ public class JWTValidatorTest {
|
||||
final String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNb0xpIiwiZXhwIjoxNjI0OTU4MDk0NTI4LCJpYXQiOjE2MjQ5NTgwMzQ1MjAsInVzZXIiOiJ1c2VyIn0.L0uB38p9sZrivbmP0VlDe--j_11YUXTu3TfHhfQhRKc";
|
||||
final byte[] key = "1234567890".getBytes();
|
||||
final boolean validate = JWT.of(token).setKey(key).validate(0);
|
||||
Assert.assertFalse(validate);
|
||||
Assertions.assertFalse(validate);
|
||||
}
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
@Test
|
||||
public void validateDateTest(){
|
||||
final JWT jwt = JWT.of()
|
||||
Assertions.assertThrows(ValidateException.class, ()->{
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("id", 123)
|
||||
.setPayload("username", "hutool")
|
||||
.setExpiresAt(DateUtil.parse("2021-10-13 09:59:00"));
|
||||
|
||||
JWTValidator.of(jwt).validateDate(DateUtil.now());
|
||||
JWTValidator.of(jwt).validateDate(DateUtil.now());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -4,13 +4,13 @@ import cn.hutool.core.convert.Converter;
|
||||
import cn.hutool.json.JSONConfig;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class GlobalValueWriterMappingTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init(){
|
||||
GlobalValueWriterMapping.put(CustomSubBean.class,
|
||||
(JSONValueWriter<CustomSubBean>) (writer, value) -> writer.writeRaw(String.valueOf(value.getId())));
|
||||
@@ -22,7 +22,7 @@ public class GlobalValueWriterMappingTest {
|
||||
customBean.setId(12);
|
||||
customBean.setName("aaa");
|
||||
final String s = JSONUtil.toJsonStr(customBean);
|
||||
Assert.assertEquals("12", s);
|
||||
Assertions.assertEquals("12", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -35,7 +35,7 @@ public class GlobalValueWriterMappingTest {
|
||||
customBean.setSub(customSubBean);
|
||||
|
||||
final String s = JSONUtil.toJsonStr(customBean);
|
||||
Assert.assertEquals("{\"id\":1,\"sub\":12}", s);
|
||||
Assertions.assertEquals("{\"id\":1,\"sub\":12}", s);
|
||||
|
||||
// 自定义转换
|
||||
final JSONConfig jsonConfig = JSONConfig.of();
|
||||
@@ -49,7 +49,7 @@ public class GlobalValueWriterMappingTest {
|
||||
return converter.convert(targetType, value);
|
||||
});
|
||||
final CustomBean customBean1 = JSONUtil.parseObj(s, jsonConfig).toBean(CustomBean.class);
|
||||
Assert.assertEquals(12, customBean1.getSub().getId());
|
||||
Assertions.assertEquals(12, customBean1.getSub().getId());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -2,10 +2,8 @@ package cn.hutool.json.xml;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class XMLTest {
|
||||
|
||||
@@ -15,7 +13,7 @@ public class XMLTest {
|
||||
.set("aaa", "你好")
|
||||
.set("键2", "test");
|
||||
final String s = JSONUtil.toXmlStr(put);
|
||||
MatcherAssert.assertThat(s, CoreMatchers.anyOf(CoreMatchers.is("<aaa>你好</aaa><键2>test</键2>"), CoreMatchers.is("<键2>test</键2><aaa>你好</aaa>")));
|
||||
Assertions.assertEquals("<aaa>你好</aaa><键2>test</键2>", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -23,10 +21,10 @@ public class XMLTest {
|
||||
final String xml = "<a>•</a>";
|
||||
final JSONObject jsonObject = JSONXMLUtil.toJSONObject(xml);
|
||||
|
||||
Assert.assertEquals("{\"a\":\"•\"}", jsonObject.toString());
|
||||
Assertions.assertEquals("{\"a\":\"•\"}", jsonObject.toString());
|
||||
|
||||
final String xml2 = JSONXMLUtil.toXml(JSONUtil.parseObj(jsonObject));
|
||||
Assert.assertEquals(xml, xml2);
|
||||
Assertions.assertEquals(xml, xml2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -34,9 +32,9 @@ public class XMLTest {
|
||||
final JSONObject jsonObject = JSONUtil.ofObj().set("content","123456");
|
||||
|
||||
String xml = JSONXMLUtil.toXml(jsonObject);
|
||||
Assert.assertEquals("123456", xml);
|
||||
Assertions.assertEquals("123456", xml);
|
||||
|
||||
xml = JSONXMLUtil.toXml(jsonObject, null, new String[0]);
|
||||
Assert.assertEquals("<content>123456</content>", xml);
|
||||
Assertions.assertEquals("<content>123456</content>", xml);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user