This commit is contained in:
Looly
2022-04-30 20:47:32 +08:00
parent dea8344d91
commit ca094ca4a8
1356 changed files with 15747 additions and 16033 deletions

View File

@@ -12,24 +12,24 @@ public class CustomSerializeTest {
@Test
public void serializeTest() {
JSONUtil.putSerializer(CustomBean.class, (JSONObjectSerializer<CustomBean>) (json, bean) -> json.set("customName", bean.name));
CustomBean customBean = new CustomBean();
final CustomBean customBean = new CustomBean();
customBean.name = "testName";
JSONObject obj = JSONUtil.parseObj(customBean);
final JSONObject obj = JSONUtil.parseObj(customBean);
Assert.assertEquals("testName", obj.getStr("customName"));
}
@Test
public void deserializeTest() {
JSONUtil.putDeserializer(CustomBean.class, json -> {
CustomBean customBean = new CustomBean();
final CustomBean customBean = new CustomBean();
customBean.name = ((JSONObject)json).getStr("customName");
return customBean;
});
String jsonStr = "{\"customName\":\"testName\"}";
CustomBean bean = JSONUtil.parseObj(jsonStr).toBean(CustomBean.class);
final String jsonStr = "{\"customName\":\"testName\"}";
final CustomBean bean = JSONUtil.parseObj(jsonStr).toBean(CustomBean.class);
Assert.assertEquals("testName", bean.name);
}

View File

@@ -11,7 +11,7 @@ public class Issue1075Test {
@Test
public void testToBean() {
// 在不忽略大小写的情况下f2、fac都不匹配
ObjA o2 = JSONUtil.toBean(jsonStr, ObjA.class);
final ObjA o2 = JSONUtil.toBean(jsonStr, ObjA.class);
Assert.assertNull(o2.getFAC());
Assert.assertNull(o2.getF2());
}
@@ -19,7 +19,7 @@ public class Issue1075Test {
@Test
public void testToBeanIgnoreCase() {
// 在忽略大小写的情况下f2、fac都匹配
ObjA o2 = JSONUtil.parseObj(jsonStr, JSONConfig.create().setIgnoreCase(true)).toBean(ObjA.class);
final ObjA o2 = JSONUtil.parseObj(jsonStr, JSONConfig.create().setIgnoreCase(true)).toBean(ObjA.class);
Assert.assertEquals("fac", o2.getFAC());
Assert.assertEquals("f2", o2.getF2());

View File

@@ -17,7 +17,7 @@ public class Issue1101Test {
@Test
public void treeMapConvertTest(){
String json = "[{\"nodeName\":\"admin\",\"treeNodeId\":\"00010001_52c95b83-2083-4138-99fb-e6e21f0c1277\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"52c95b83-2083-4138-99fb-e6e21f0c1277\",\"status\":true},{\"nodeName\":\"test\",\"treeNodeId\":\"00010001_97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"status\":true}]";
final String json = "[{\"nodeName\":\"admin\",\"treeNodeId\":\"00010001_52c95b83-2083-4138-99fb-e6e21f0c1277\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"52c95b83-2083-4138-99fb-e6e21f0c1277\",\"status\":true},{\"nodeName\":\"test\",\"treeNodeId\":\"00010001_97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"status\":true}]";
final JSONArray objects = JSONUtil.parseArray(json);
final TreeSet<TreeNodeDto> convert = Convert.convert(new TypeReference<TreeSet<TreeNodeDto>>() {
}, objects);
@@ -26,7 +26,7 @@ public class Issue1101Test {
@Test
public void test(){
String json = "{\n" +
final String json = "{\n" +
"\t\"children\": [{\n" +
"\t\t\"children\": [],\n" +
"\t\t\"id\": \"52c95b83-2083-4138-99fb-e6e21f0c1277\",\n" +
@@ -60,7 +60,7 @@ public class Issue1101Test {
final TreeNode treeNode = JSONUtil.toBean(jsonObject, TreeNode.class);
Assert.assertEquals(2, treeNode.getChildren().size());
TreeNodeDto dto = new TreeNodeDto();
final TreeNodeDto dto = new TreeNodeDto();
BeanUtil.copyProperties(treeNode, dto, true);
Assert.assertEquals(2, dto.getChildren().size());
}
@@ -89,7 +89,7 @@ public class Issue1101Test {
private TreeSet<TreeNode> children = new TreeSet<>();
@Override
public int compareTo(TreeNode o) {
public int compareTo(final TreeNode o) {
return id.compareTo(o.getId());
}
}

View File

@@ -26,32 +26,32 @@ public class Issue2090Test {
@Test
public void parseLocalDateTest(){
LocalDate localDate = LocalDate.now();
final LocalDate localDate = LocalDate.now();
final JSONObject jsonObject = JSONUtil.parseObj(localDate);
Assert.assertNotNull(jsonObject.toString());
}
@Test
public void toBeanLocalDateTest(){
LocalDate d = LocalDate.now();
final LocalDate d = LocalDate.now();
final JSONObject obj = JSONUtil.parseObj(d);
LocalDate d2 = obj.toBean(LocalDate.class);
final LocalDate d2 = obj.toBean(LocalDate.class);
Assert.assertEquals(d, d2);
}
@Test
public void toBeanLocalDateTimeTest(){
LocalDateTime d = LocalDateTime.now();
final LocalDateTime d = LocalDateTime.now();
final JSONObject obj = JSONUtil.parseObj(d);
LocalDateTime d2 = obj.toBean(LocalDateTime.class);
final LocalDateTime d2 = obj.toBean(LocalDateTime.class);
Assert.assertEquals(d, d2);
}
@Test
public void toBeanLocalTimeTest(){
LocalTime d = LocalTime.now();
final LocalTime d = LocalTime.now();
final JSONObject obj = JSONUtil.parseObj(d);
LocalTime d2 = obj.toBean(LocalTime.class);
final LocalTime d2 = obj.toBean(LocalTime.class);
Assert.assertEquals(d, d2);
}

View File

@@ -19,16 +19,16 @@ public class Issue2131Test {
@Test
public void strToBean() {
GoodsResponse goodsResponse = new GoodsResponse();
GoodsItem apple = new GoodsItem().setGoodsId(1L).setGoodsName("apple").setChannel("wechat");
GoodsItem pear = new GoodsItem().setGoodsId(2L).setGoodsName("pear").setChannel("jd");
final GoodsResponse goodsResponse = new GoodsResponse();
final GoodsItem apple = new GoodsItem().setGoodsId(1L).setGoodsName("apple").setChannel("wechat");
final GoodsItem pear = new GoodsItem().setGoodsId(2L).setGoodsName("pear").setChannel("jd");
final List<GoodsItem> collections = goodsResponse.getCollections();
Stream.of(apple, pear).forEach(collections::add);
String jsonStr = JSONUtil.toJsonStr(goodsResponse);
final String jsonStr = JSONUtil.toJsonStr(goodsResponse);
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
GoodsResponse result = jsonObject.toBean(GoodsResponse.class);
final GoodsResponse result = jsonObject.toBean(GoodsResponse.class);
Assert.assertEquals(0, result.getCollections().size());
}

View File

@@ -12,14 +12,14 @@ public class Issue2223Test {
@Test
public void toStrOrderTest() {
Map<String, Long> m1 = new LinkedHashMap<>();
final Map<String, Long> m1 = new LinkedHashMap<>();
for (long i = 0; i < 5; i++) {
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));
Map<String, Map<String, Long>> map1 = new HashMap<>();
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}}",

View File

@@ -13,14 +13,14 @@ public class Issue488Test {
@Test
public void toBeanTest() {
String jsonStr = ResourceUtil.readUtf8Str("issue488.json");
final String jsonStr = ResourceUtil.readUtf8Str("issue488.json");
ResultSuccess<List<EmailAddress>> result = JSONUtil.toBean(jsonStr,
final ResultSuccess<List<EmailAddress>> result = JSONUtil.toBean(jsonStr,
new TypeReference<ResultSuccess<List<EmailAddress>>>() {}, false);
Assert.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext());
List<EmailAddress> adds = result.getValue();
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());
@@ -33,16 +33,16 @@ public class Issue488Test {
@Test
public void toCollctionBeanTest() {
String jsonStr = ResourceUtil.readUtf8Str("issue488Array.json");
final String jsonStr = ResourceUtil.readUtf8Str("issue488Array.json");
List<ResultSuccess<List<EmailAddress>>> resultList = JSONUtil.toBean(jsonStr,
final List<ResultSuccess<List<EmailAddress>>> resultList = JSONUtil.toBean(jsonStr,
new TypeReference<List<ResultSuccess<List<EmailAddress>>>>() {}, false);
ResultSuccess<List<EmailAddress>> result = resultList.get(0);
final ResultSuccess<List<EmailAddress>> result = resultList.get(0);
Assert.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext());
List<EmailAddress> adds = result.getValue();
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());

View File

@@ -9,8 +9,8 @@ public class Issue867Test {
@Test
public void toBeanTest(){
String json = "{\"abc_1d\":\"123\",\"abc_d\":\"456\",\"abc_de\":\"789\"}";
Test02 bean = JSONUtil.toBean(JSONUtil.parseObj(json),Test02.class);
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());

View File

@@ -19,19 +19,19 @@ public class IssueI1AU86Test {
@Test
public void toListTest() {
List<String> redisList = CollUtil.newArrayList(
final List<String> redisList = CollUtil.newArrayList(
"{\"updateDate\":1583376342000,\"code\":\"move\",\"id\":1,\"sort\":1,\"name\":\"电影大全\"}",
"{\"updateDate\":1583378882000,\"code\":\"zy\",\"id\":3,\"sort\":5,\"name\":\"综艺会\"}"
);
// 手动parse
final JSONArray jsonArray = new JSONArray();
for (String str : redisList) {
for (final String str : redisList) {
jsonArray.add(JSONUtil.parse(str));
}
final List<Vcc> vccs = jsonArray.toList(Vcc.class);
for (Vcc vcc : vccs) {
for (final Vcc vcc : vccs) {
Assert.assertNotNull(vcc);
}
}

View File

@@ -12,8 +12,8 @@ import java.time.LocalDateTime;
public class IssueI1F8M2 {
@Test
public void toBeanTest() {
String jsonStr = "{\"eventType\":\"fee\",\"fwdAlertingTime\":\"2020-04-22 16:34:13\",\"fwdAnswerTime\":\"\"}";
Param param = JSONUtil.toBean(jsonStr, Param.class);
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());
}

View File

@@ -15,9 +15,9 @@ public class IssueI1H2VN {
@Test
public void toBeanTest() {
String jsonStr = "{'conditionsVo':[{'column':'StockNo','value':'abc','type':'='},{'column':'CheckIncoming','value':'1','type':'='}]," +
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}}";
QueryVo vo = JSONUtil.toBean(jsonStr, QueryVo.class);
final QueryVo vo = JSONUtil.toBean(jsonStr, QueryVo.class);
Assert.assertEquals(2, vo.getConditionsVo().size());
final QueryVo subVo = vo.getQueryVo();
Assert.assertNotNull(subVo);

View File

@@ -14,7 +14,7 @@ public class IssueI3BS4S {
@Test
public void toBeanTest(){
String jsonStr = "{date: '2021-03-17T06:31:33.99'}";
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());

View File

@@ -9,10 +9,10 @@ public class IssueI3EGJP {
@Test
public void hutoolMapToBean() {
JSONObject paramJson = new JSONObject();
final JSONObject paramJson = new JSONObject();
paramJson.set("is_booleana", "1");
paramJson.set("is_booleanb", true);
ConvertDO convertDO = BeanUtil.toBean(paramJson, ConvertDO.class);
final ConvertDO convertDO = BeanUtil.toBean(paramJson, ConvertDO.class);
Assert.assertTrue(convertDO.isBooleana());
Assert.assertTrue(convertDO.getIsBooleanb());

View File

@@ -30,13 +30,13 @@ public class IssueI49VZBTest {
*/
snapKey;
public static NBCloudKeyType find(String value) {
public static NBCloudKeyType find(final String value) {
return Stream.of(values()).filter(e -> e.getValue().equalsIgnoreCase(value)).findFirst()
.orElse(null);
}
public static NBCloudKeyType downFind(String keyType) {
public static NBCloudKeyType downFind(final String keyType) {
if (fingerPrint.name().equals(keyType.toLowerCase())) {
return NBCloudKeyType.fingerPrint;
} else {
@@ -63,7 +63,7 @@ public class IssueI49VZBTest {
@Test
public void toBeanTest(){
String str = "{type: \"password\"}";
final String str = "{type: \"password\"}";
final UPOpendoor upOpendoor = JSONUtil.toBean(str, UPOpendoor.class);
Assert.assertEquals(NBCloudKeyType.password, upOpendoor.getType());
}

View File

@@ -10,7 +10,7 @@ public class IssueI4RBZ4Test {
@Test
public void sortTest(){
String jsonStr = "{\"id\":\"123\",\"array\":[1,2,3],\"outNum\":356,\"body\":{\"ava1\":\"20220108\",\"use\":1,\"ava2\":\"20230108\"},\"name\":\"John\"}";
final String jsonStr = "{\"id\":\"123\",\"array\":[1,2,3],\"outNum\":356,\"body\":{\"ava1\":\"20220108\",\"use\":1,\"ava2\":\"20230108\"},\"name\":\"John\"}";
final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, JSONConfig.create().setNatureKeyComparator());
Assert.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString());

View File

@@ -15,20 +15,20 @@ public class IssueI4XFMWTest {
@Test
public void test() {
List<TestEntity> entityList = new ArrayList<>();
TestEntity entityA = new TestEntity();
final List<TestEntity> entityList = new ArrayList<>();
final TestEntity entityA = new TestEntity();
entityA.setId("123");
entityA.setPassword("456");
entityList.add(entityA);
TestEntity entityB = new TestEntity();
final TestEntity entityB = new TestEntity();
entityB.setId("789");
entityB.setPassword("098");
entityList.add(entityB);
String jsonStr = JSONUtil.toJsonStr(entityList);
final String jsonStr = JSONUtil.toJsonStr(entityList);
Assert.assertEquals("[{\"uid\":\"123\",\"password\":\"456\"},{\"uid\":\"789\",\"password\":\"098\"}]", jsonStr);
List<TestEntity> testEntities = JSONUtil.toList(jsonStr, TestEntity.class);
final List<TestEntity> testEntities = JSONUtil.toList(jsonStr, TestEntity.class);
Assert.assertEquals("123", testEntities.get(0).getId());
Assert.assertEquals("789", testEntities.get(1).getId());
}

View File

@@ -9,7 +9,7 @@ public class IssueI50EGGTest {
@Test
public void toBeanTest(){
String data = "{\"return_code\": 1, \"return_msg\": \"成功\", \"return_data\" : null}";
final String data = "{\"return_code\": 1, \"return_msg\": \"成功\", \"return_data\" : null}";
final ApiResult<?> apiResult = JSONUtil.toBean(data, JSONConfig.create().setIgnoreCase(true), ApiResult.class);
Assert.assertEquals(1, apiResult.getReturn_code());
}

View File

@@ -27,7 +27,7 @@ public class Issues1881Test {
@Test
public void parseTest(){
List<ThingsHolderContactVO> holderContactVOList = new ArrayList<>();
final List<ThingsHolderContactVO> holderContactVOList = new ArrayList<>();
holderContactVOList.add(new ThingsHolderContactVO().setId(1L).setName("1"));
holderContactVOList.add(new ThingsHolderContactVO().setId(2L).setName("2"));

View File

@@ -21,7 +21,7 @@ public class IssuesI44E4HTest {
return testDto;
});
String jsonStr = "{\"md\":\"value1\"}";
final String jsonStr = "{\"md\":\"value1\"}";
final TestDto testDto = JSONUtil.toBean(jsonStr, TestDto.class);
Assert.assertEquals("value1", testDto.getMd().getValue());
}

View File

@@ -10,7 +10,7 @@ public class IssuesI4V14NTest {
@Test
public void parseTest(){
String str = "{\"A\" : \"A\\nb\"}";
final String str = "{\"A\" : \"A\\nb\"}";
final JSONObject jsonObject = JSONUtil.parseObj(str);
Assert.assertEquals("A\nb", jsonObject.getStr("A"));

View File

@@ -44,7 +44,7 @@ public class JSONArrayTest {
@Test
public void addNullTest(){
final List<String> aaa = ListUtil.of("aaa", null);
String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa,
final String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa,
JSONConfig.create().setIgnoreNullValue(false)));
Assert.assertEquals("[\"aaa\",null]", jsonStr);
}
@@ -52,7 +52,7 @@ public class JSONArrayTest {
@Test
public void addTest() {
// 方法1
JSONArray array = JSONUtil.createArray();
final JSONArray array = JSONUtil.createArray();
// 方法2
// JSONArray array = new JSONArray();
array.add("value1");
@@ -64,14 +64,14 @@ public class JSONArrayTest {
@Test
public void parseTest() {
String jsonStr = "[\"value1\", \"value2\", \"value3\"]";
JSONArray array = JSONUtil.parseArray(jsonStr);
final String jsonStr = "[\"value1\", \"value2\", \"value3\"]";
final JSONArray array = JSONUtil.parseArray(jsonStr);
Assert.assertEquals(array.get(0), "value1");
}
@Test
public void parseWithNullTest() {
String jsonStr = "[{\"grep\":\"4.8\",\"result\":\"\"},{\"grep\":\"4.8\",\"result\":null}]";
final String jsonStr = "[{\"grep\":\"4.8\",\"result\":\"\"},{\"grep\":\"4.8\",\"result\":null}]";
JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
Assert.assertFalse(jsonArray.getJSONObject(1).containsKey("result"));
@@ -82,45 +82,45 @@ public class JSONArrayTest {
@Test
public void parseFileTest() {
JSONArray array = JSONUtil.readJSONArray(FileUtil.file("exam_test.json"), CharsetUtil.UTF_8);
final JSONArray array = JSONUtil.readJSONArray(FileUtil.file("exam_test.json"), CharsetUtil.UTF_8);
JSONObject obj0 = array.getJSONObject(0);
Exam exam = JSONUtil.toBean(obj0, Exam.class);
final JSONObject obj0 = array.getJSONObject(0);
final Exam exam = JSONUtil.toBean(obj0, Exam.class);
Assert.assertEquals("0", exam.getAnswerArray()[0].getSeq());
}
@Test
public void parseBeanListTest() {
KeyBean b1 = new KeyBean();
final KeyBean b1 = new KeyBean();
b1.setAkey("aValue1");
b1.setBkey("bValue1");
KeyBean b2 = new KeyBean();
final KeyBean b2 = new KeyBean();
b2.setAkey("aValue2");
b2.setBkey("bValue2");
ArrayList<KeyBean> list = CollUtil.newArrayList(b1, b2);
final ArrayList<KeyBean> list = CollUtil.newArrayList(b1, b2);
JSONArray jsonArray = JSONUtil.parseArray(list);
final JSONArray jsonArray = JSONUtil.parseArray(list);
Assert.assertEquals("aValue1", jsonArray.getJSONObject(0).getStr("akey"));
Assert.assertEquals("bValue2", jsonArray.getJSONObject(1).getStr("bkey"));
}
@Test
public void toListTest() {
String jsonStr = FileUtil.readString("exam_test.json", CharsetUtil.UTF_8);
JSONArray array = JSONUtil.parseArray(jsonStr);
final String jsonStr = FileUtil.readString("exam_test.json", CharsetUtil.UTF_8);
final JSONArray array = JSONUtil.parseArray(jsonStr);
List<Exam> list = array.toList(Exam.class);
final List<Exam> list = array.toList(Exam.class);
Assert.assertFalse(list.isEmpty());
Assert.assertSame(Exam.class, list.get(0).getClass());
}
@Test
public void toListTest2() {
String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
final String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
JSONArray array = JSONUtil.parseArray(jsonArr);
List<User> userList = JSONUtil.toList(array, User.class);
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());
@@ -134,11 +134,11 @@ public class JSONArrayTest {
@Test
public void toDictListTest() {
String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
final String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
JSONArray array = JSONUtil.parseArray(jsonArr, JSONConfig.create().setIgnoreError(false));
final JSONArray array = JSONUtil.parseArray(jsonArr, JSONConfig.create().setIgnoreError(false));
List<Dict> list = JSONUtil.toList(array, Dict.class);
final List<Dict> list = JSONUtil.toList(array, Dict.class);
Assert.assertFalse(list.isEmpty());
Assert.assertSame(Dict.class, list.get(0).getClass());
@@ -152,11 +152,11 @@ public class JSONArrayTest {
@Test
public void toArrayTest() {
String jsonStr = FileUtil.readString("exam_test.json", CharsetUtil.UTF_8);
JSONArray array = JSONUtil.parseArray(jsonStr);
final String jsonStr = FileUtil.readString("exam_test.json", CharsetUtil.UTF_8);
final JSONArray array = JSONUtil.parseArray(jsonStr);
//noinspection SuspiciousToArrayCall
Exam[] list = array.toArray(new Exam[0]);
final Exam[] list = array.toArray(new Exam[0]);
Assert.assertNotEquals(0, list.length);
Assert.assertSame(Exam.class, list[0].getClass());
}
@@ -166,10 +166,10 @@ public class JSONArrayTest {
*/
@Test
public void toListWithNullTest() {
String json = "[null,{'akey':'avalue','bkey':'bvalue'}]";
JSONArray ja = JSONUtil.parseArray(json);
final String json = "[null,{'akey':'avalue','bkey':'bvalue'}]";
final JSONArray ja = JSONUtil.parseArray(json);
List<KeyBean> list = ja.toList(KeyBean.class);
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());
@@ -177,21 +177,21 @@ public class JSONArrayTest {
@Test(expected = ConvertException.class)
public void toListWithErrorTest(){
String json = "[['aaa',{'akey':'avalue','bkey':'bvalue'}]]";
JSONArray ja = JSONUtil.parseArray(json);
final String json = "[['aaa',{'akey':'avalue','bkey':'bvalue'}]]";
final JSONArray ja = JSONUtil.parseArray(json);
ja.toBean(new TypeReference<List<List<KeyBean>>>() {});
}
@Test
public void toBeanListTest() {
List<Map<String, String>> mapList = new ArrayList<>();
final List<Map<String, String>> mapList = new ArrayList<>();
mapList.add(buildMap("0", "0", "0"));
mapList.add(buildMap("1", "1", "1"));
mapList.add(buildMap("+0", "+0", "+0"));
mapList.add(buildMap("-0", "-0", "-0"));
JSONArray jsonArray = JSONUtil.parseArray(mapList);
List<JsonNode> nodeList = jsonArray.toList(JsonNode.class);
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());
@@ -211,7 +211,7 @@ public class JSONArrayTest {
@Test
public void getByPathTest(){
String jsonStr = "[{\"id\": \"1\",\"name\": \"a\"},{\"id\": \"2\",\"name\": \"b\"}]";
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"));
@@ -234,8 +234,8 @@ public class JSONArrayTest {
Assert.assertEquals(1, jsonArray.get(0));
}
private static Map<String, String> buildMap(String id, String parentId, String name) {
Map<String, String> map = new HashMap<>();
private static Map<String, String> buildMap(final String id, final String parentId, final String name) {
final Map<String, String> map = new HashMap<>();
map.put("id", id);
map.put("parentId", parentId);
map.put("name", name);
@@ -250,7 +250,7 @@ public class JSONArrayTest {
@Test
public void filterIncludeTest(){
JSONArray json1 = JSONUtil.createArray()
final JSONArray json1 = JSONUtil.createArray()
.set("value1")
.set("value2")
.set("value3")
@@ -262,7 +262,7 @@ public class JSONArrayTest {
@Test
public void filterExcludeTest(){
JSONArray json1 = JSONUtil.createArray()
final JSONArray json1 = JSONUtil.createArray()
.set("value1")
.set("value2")
.set("value3")
@@ -282,7 +282,7 @@ public class JSONArrayTest {
@Test
public void parseFilterTest() {
String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
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());
@@ -291,7 +291,7 @@ public class JSONArrayTest {
@Test
public void parseFilterEditTest() {
String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
final String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]";
//noinspection MismatchedQueryAndUpdateOfCollection
final JSONArray array = new JSONArray(jsonArr, null, (mutable) -> {
final JSONObject o = new JSONObject(mutable.get());

View File

@@ -8,7 +8,7 @@ public class JSONBeanParserTest {
@Test
public void parseTest(){
String jsonStr = "{\"customName\": \"customValue\", \"customAddress\": \"customAddressValue\"}";
final String jsonStr = "{\"customName\": \"customValue\", \"customAddress\": \"customAddressValue\"}";
final TestBean testBean = JSONUtil.toBean(jsonStr, TestBean.class);
Assert.assertNotNull(testBean);
Assert.assertEquals("customValue", testBean.getName());
@@ -22,7 +22,7 @@ public class JSONBeanParserTest {
private String address;
@Override
public void parse(JSONObject value) {
public void parse(final JSONObject value) {
this.name = value.getStr("customName");
this.address = value.getStr("customAddress");
}

View File

@@ -14,7 +14,7 @@ import java.util.Map;
/**
* JSON转换单元测试
*
*
* @author Looly质量过关
*
*/
@@ -23,81 +23,81 @@ public class JSONConvertTest {
@Test
public void testBean2Json() {
UserInfoDict userInfoDict = new UserInfoDict();
final UserInfoDict userInfoDict = new UserInfoDict();
userInfoDict.setId(1);
userInfoDict.setPhotoPath("yx.mm.com");
userInfoDict.setRealName("质量过关");
ExamInfoDict examInfoDict = new ExamInfoDict();
final ExamInfoDict examInfoDict = new ExamInfoDict();
examInfoDict.setId(1);
examInfoDict.setExamType(0);
examInfoDict.setAnswerIs(1);
ExamInfoDict examInfoDict1 = new ExamInfoDict();
final ExamInfoDict examInfoDict1 = new ExamInfoDict();
examInfoDict1.setId(2);
examInfoDict1.setExamType(0);
examInfoDict1.setAnswerIs(0);
ExamInfoDict examInfoDict2 = new ExamInfoDict();
final ExamInfoDict examInfoDict2 = new ExamInfoDict();
examInfoDict2.setId(3);
examInfoDict2.setExamType(1);
examInfoDict2.setAnswerIs(0);
List<ExamInfoDict> examInfoDicts = new ArrayList<>();
final List<ExamInfoDict> examInfoDicts = new ArrayList<>();
examInfoDicts.add(examInfoDict);
examInfoDicts.add(examInfoDict1);
examInfoDicts.add(examInfoDict2);
userInfoDict.setExamInfoDict(examInfoDicts);
Map<String, Object> tempMap = new HashMap<>();
final Map<String, Object> tempMap = new HashMap<>();
tempMap.put("userInfoDict", userInfoDict);
tempMap.put("toSendManIdCard", 1);
JSONObject obj = JSONUtil.parseObj(tempMap);
final JSONObject obj = JSONUtil.parseObj(tempMap);
Assert.assertEquals(new Integer(1), obj.getInt("toSendManIdCard"));
JSONObject examInfoDictsJson = obj.getJSONObject("userInfoDict");
final JSONObject examInfoDictsJson = obj.getJSONObject("userInfoDict");
Assert.assertEquals(new Integer(1), examInfoDictsJson.getInt("id"));
Assert.assertEquals("质量过关", examInfoDictsJson.getStr("realName"));
Object id = JSONUtil.getByPath(obj, "userInfoDict.examInfoDict[0].id");
final Object id = JSONUtil.getByPath(obj, "userInfoDict.examInfoDict[0].id");
Assert.assertEquals(1, id);
}
@Test
public void testJson2Bean() {
// language=JSON
String examJson = "{\n" + " \"examInfoDicts\": {\n" + " \"id\": 1,\n" + " \"realName\": \"质量过关\",\n" //
final String examJson = "{\n" + " \"examInfoDicts\": {\n" + " \"id\": 1,\n" + " \"realName\": \"质量过关\",\n" //
+ " \"examInfoDict\": [\n" + " {\n" + " \"id\": 1,\n" + " \"answerIs\": 1,\n" + " \"examType\": 0\n" //
+ " },\n" + " {\n" + " \"id\": 2,\n" + " \"answerIs\": 0,\n" + " \"examType\": 0\n" + " },\n" //
+ " {\n" + " \"id\": 3,\n" + " \"answerIs\": 0,\n" + " \"examType\": 1\n" + " }\n" + " ],\n" //
+ " \"photoPath\": \"yx.mm.com\"\n" + " },\n" + " \"toSendManIdCard\": 1\n" + "}";
JSONObject jsonObject = JSONUtil.parseObj(examJson).getJSONObject("examInfoDicts");
UserInfoDict userInfoDict = jsonObject.toBean(UserInfoDict.class);
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(), "质量过关");
//============
String jsonStr = "{\"id\":null,\"examInfoDict\":[{\"answerIs\":1, \"id\":null}]}";//JSONUtil.toJsonStr(userInfoDict1);
JSONObject jsonObject2 = JSONUtil.parseObj(jsonStr);//.getJSONObject("examInfoDicts");
UserInfoDict userInfoDict2 = jsonObject2.toBean(UserInfoDict.class);
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());
}
/**
* 针对Bean中Setter返回this测试是否可以成功调用Setter方法并注入
*/
@Test
public void testJson2Bean2() {
String jsonStr = ResourceUtil.readUtf8Str("evaluation.json");
JSONObject obj = JSONUtil.parseObj(jsonStr);
PerfectEvaluationProductResVo vo = obj.toBean(PerfectEvaluationProductResVo.class);
final String jsonStr = ResourceUtil.readUtf8Str("evaluation.json");
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());
}
}
}

View File

@@ -7,7 +7,7 @@ public class JSONNullTest {
@Test
public void parseNullTest(){
JSONObject bodyjson = JSONUtil.parseObj("{\n" +
final JSONObject bodyjson = JSONUtil.parseObj("{\n" +
" \"device_model\": null,\n" +
" \"device_status_date\": null,\n" +
" \"imsi\": null,\n" +
@@ -22,7 +22,7 @@ public class JSONNullTest {
@Test
public void parseNullTest2(){
JSONObject bodyjson = JSONUtil.parseObj("{\n" +
final JSONObject bodyjson = JSONUtil.parseObj("{\n" +
" \"device_model\": null,\n" +
" \"device_status_date\": null,\n" +
" \"imsi\": null,\n" +

View File

@@ -49,8 +49,8 @@ public class JSONObjectTest {
@Test
@Ignore
public void toStringTest() {
String str = "{\"code\": 500, \"data\":null}";
JSONObject jsonObject = new JSONObject(str);
final String str = "{\"code\": 500, \"data\":null}";
final JSONObject jsonObject = new JSONObject(str);
Console.log(jsonObject);
jsonObject.getConfig().setIgnoreNullValue(true);
Console.log(jsonObject.toStringPretty());
@@ -58,9 +58,9 @@ public class JSONObjectTest {
@Test
public void toStringTest2() {
String str = "{\"test\":\"关于开展2018年度“文明集体”、“文明职工”评选表彰活动的通知\"}";
final String str = "{\"test\":\"关于开展2018年度“文明集体”、“文明职工”评选表彰活动的通知\"}";
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject json = new JSONObject(str);
final JSONObject json = new JSONObject(str);
Assert.assertEquals(str, json.toString());
}
@@ -69,7 +69,7 @@ public class JSONObjectTest {
*/
@Test
public void toStringTest3() {
JSONObject json = Objects.requireNonNull(JSONUtil.createObj()//
final JSONObject json = Objects.requireNonNull(JSONUtil.createObj()//
.set("dateTime", DateUtil.parse("2019-05-02 22:12:01")))//
.setDateFormat(DatePattern.NORM_DATE_PATTERN);
Assert.assertEquals("{\"dateTime\":\"2019-05-02\"}", json.toString());
@@ -88,13 +88,13 @@ public class JSONObjectTest {
@Test
public void putAllTest() {
JSONObject json1 = JSONUtil.createObj()
final JSONObject json1 = JSONUtil.createObj()
.set("a", "value1")
.set("b", "value2")
.set("c", "value3")
.set("d", true);
JSONObject json2 = JSONUtil.createObj()
final JSONObject json2 = JSONUtil.createObj()
.set("a", "value21")
.set("b", "value22");
@@ -108,8 +108,8 @@ public class JSONObjectTest {
@Test
public void parseStringTest() {
String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
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");
@@ -121,57 +121,57 @@ public class JSONObjectTest {
@Test
public void parseStringTest2() {
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\"}";
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
JSONObject json = new JSONObject(jsonStr);
final JSONObject json = new JSONObject(jsonStr);
Assert.assertEquals("F140", json.getStr("error_code"));
Assert.assertEquals("最早发送时间格式错误该字段可以为空当不为空时正确填写格式为“YYYYMMDDHHMISS”", json.getStr("error_info"));
}
@Test
public void parseStringTest3() {
String jsonStr = "{\"test\":\"体”、“文\"}";
final String jsonStr = "{\"test\":\"体”、“文\"}";
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject json = new JSONObject(jsonStr);
final JSONObject json = new JSONObject(jsonStr);
Assert.assertEquals("体”、“文", json.getStr("test"));
}
@Test
public void parseStringTest4() {
String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject json = new JSONObject(jsonStr);
final JSONObject json = new JSONObject(jsonStr);
Assert.assertEquals(new Integer(0), json.getInt("ok"));
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
}
@Test
public void parseBytesTest() {
String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject json = new JSONObject(jsonStr.getBytes(StandardCharsets.UTF_8));
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"));
}
@Test
public void parseReaderTest() {
String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
final StringReader stringReader = new StringReader(jsonStr);
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject json = new JSONObject(stringReader);
final JSONObject json = new JSONObject(stringReader);
Assert.assertEquals(new Integer(0), json.getInt("ok"));
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
}
@Test
public void parseInputStreamTest() {
String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
final ByteArrayInputStream in = new ByteArrayInputStream(jsonStr.getBytes(StandardCharsets.UTF_8));
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject json = new JSONObject(in);
final JSONObject json = new JSONObject(in);
Assert.assertEquals(new Integer(0), json.getInt("ok"));
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
}
@@ -179,9 +179,9 @@ public class JSONObjectTest {
@Test
@Ignore
public void parseStringWithBomTest() {
String jsonStr = FileUtil.readUtf8String("f:/test/jsontest.txt");
JSONObject json = new JSONObject(jsonStr);
JSONObject json2 = JSONUtil.parseObj(json);
final String jsonStr = FileUtil.readUtf8String("f:/test/jsontest.txt");
final JSONObject json = new JSONObject(jsonStr);
final JSONObject json2 = JSONUtil.parseObj(json);
Console.log(json);
Console.log(json2);
}
@@ -189,23 +189,23 @@ public class JSONObjectTest {
@Test
public void parseStringWithSlashTest() {
//在5.3.2之前,</div>中的/会被转义修复此bug的单元测试
String jsonStr = "{\"a\":\"<div>aaa</div>\"}";
final String jsonStr = "{\"a\":\"<div>aaa</div>\"}";
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject json = new JSONObject(jsonStr);
final JSONObject json = new JSONObject(jsonStr);
Assert.assertEquals("<div>aaa</div>", json.get("a"));
Assert.assertEquals(jsonStr, json.toString());
}
@Test
public void toBeanTest() {
JSONObject subJson = JSONUtil.createObj().set("value1", "strValue1").set("value2", "234");
JSONObject json = JSONUtil.createObj().set("strValue", "strTest").set("intValue", 123)
final JSONObject subJson = JSONUtil.createObj().set("value1", "strValue1").set("value2", "234");
final JSONObject json = JSONUtil.createObj().set("strValue", "strTest").set("intValue", 123)
// 测试空字符串转对象
.set("doubleValue", "")
.set("beanValue", subJson)
.set("list", JSONUtil.createArray().set("a").set("b")).set("testEnum", "TYPE_A");
TestBean bean = json.toBean(TestBean.class);
final TestBean bean = json.toBean(TestBean.class);
Assert.assertEquals("a", bean.getList().get(0));
Assert.assertEquals("b", bean.getList().get(1));
@@ -218,14 +218,14 @@ public class JSONObjectTest {
@Test
public void toBeanNullStrTest() {
JSONObject json = JSONUtil.createObj()//
final JSONObject json = JSONUtil.createObj()//
.set("strValue", "null")//
.set("intValue", 123)//
// 子对象对应"null"字符串,如果忽略错误,跳过,否则抛出转换异常
.set("beanValue", "null")//
.set("list", JSONUtil.createArray().set("a").set("b"));
TestBean bean = json.toBean(TestBean.class, true);
final TestBean bean = json.toBean(TestBean.class, true);
// 当JSON中为字符串"null"时应被当作字符串处理
Assert.assertEquals("null", bean.getStrValue());
// 当JSON中为字符串"null"时Bean中的字段类型不匹配应在ignoreError模式下忽略注入
@@ -234,14 +234,14 @@ public class JSONObjectTest {
@Test
public void toBeanTest2() {
UserA userA = new UserA();
final UserA userA = new UserA();
userA.setA("A user");
userA.setName("{\n\t\"body\":{\n\t\t\"loginId\":\"id\",\n\t\t\"password\":\"pwd\"\n\t}\n}");
userA.setDate(new Date());
userA.setSqs(CollUtil.newArrayList(new Seq("seq1"), new Seq("seq2")));
JSONObject json = JSONUtil.parseObj(userA);
UserA userA2 = json.toBean(UserA.class);
final JSONObject json = JSONUtil.parseObj(userA);
final UserA userA2 = json.toBean(UserA.class);
// 测试数组
Assert.assertEquals("seq1", userA2.getSqs().get(0).getSeq());
// 测试带换行符等特殊字符转换是否成功
@@ -250,33 +250,33 @@ public class JSONObjectTest {
@Test
public void toBeanWithNullTest() {
String jsonStr = "{'data':{'userName':'ak','password': null}}";
UserWithMap user = JSONUtil.toBean(JSONUtil.parseObj(jsonStr), UserWithMap.class);
final String jsonStr = "{'data':{'userName':'ak','password': null}}";
final UserWithMap user = JSONUtil.toBean(JSONUtil.parseObj(jsonStr), UserWithMap.class);
Assert.assertTrue(user.getData().containsKey("password"));
}
@Test
public void toBeanTest4() {
String json = "{\"data\":{\"b\": \"c\"}}";
final String json = "{\"data\":{\"b\": \"c\"}}";
UserWithMap map = JSONUtil.toBean(json, UserWithMap.class);
final UserWithMap map = JSONUtil.toBean(json, UserWithMap.class);
Assert.assertEquals("c", map.getData().get("b"));
}
@Test
public void toBeanTest5() {
String readUtf8Str = ResourceUtil.readUtf8Str("suiteReport.json");
JSONObject json = JSONUtil.parseObj(readUtf8Str);
SuiteReport bean = json.toBean(SuiteReport.class);
final String readUtf8Str = ResourceUtil.readUtf8Str("suiteReport.json");
final JSONObject json = JSONUtil.parseObj(readUtf8Str);
final SuiteReport bean = json.toBean(SuiteReport.class);
// 第一层
List<CaseReport> caseReports = bean.getCaseReports();
CaseReport caseReport = caseReports.get(0);
final List<CaseReport> caseReports = bean.getCaseReports();
final CaseReport caseReport = caseReports.get(0);
Assert.assertNotNull(caseReport);
// 第二层
List<StepReport> stepReports = caseReports.get(0).getStepReports();
StepReport stepReport = stepReports.get(0);
final List<StepReport> stepReports = caseReports.get(0).getStepReports();
final StepReport stepReport = stepReports.get(0);
Assert.assertNotNull(stepReport);
}
@@ -285,18 +285,18 @@ public class JSONObjectTest {
*/
@Test
public void toBeanTest6() {
JSONObject json = JSONUtil.createObj()
final JSONObject json = JSONUtil.createObj()
.set("targetUrl", "http://test.com")
.set("success", "true")
.set("result", JSONUtil.createObj()
.set("token", "tokenTest")
.set("userId", "测试用户1"));
TokenAuthWarp2 bean = json.toBean(TokenAuthWarp2.class);
final TokenAuthWarp2 bean = json.toBean(TokenAuthWarp2.class);
Assert.assertEquals("http://test.com", bean.getTargetUrl());
Assert.assertEquals("true", bean.getSuccess());
TokenAuthResponse result = bean.getResult();
final TokenAuthResponse result = bean.getResult();
Assert.assertNotNull(result);
Assert.assertEquals("tokenTest", result.getToken());
Assert.assertEquals("测试用户1", result.getUserId());
@@ -308,21 +308,21 @@ public class JSONObjectTest {
*/
@Test
public void toBeanTest7() {
String jsonStr = " {\"result\":{\"phone\":\"15926297342\",\"appKey\":\"e1ie12e1ewsdqw1\"," +
final String jsonStr = " {\"result\":{\"phone\":\"15926297342\",\"appKey\":\"e1ie12e1ewsdqw1\"," +
"\"secret\":\"dsadadqwdqs121d1e2\",\"message\":\"hello world\"},\"code\":100,\"" +
"message\":\"validate message\"}";
ResultDto<?> dto = JSONUtil.toBean(jsonStr, ResultDto.class);
final ResultDto<?> dto = JSONUtil.toBean(jsonStr, ResultDto.class);
Assert.assertEquals("validate message", dto.getMessage());
}
@Test
public void parseBeanTest() {
UserA userA = new UserA();
final UserA userA = new UserA();
userA.setName("nameTest");
userA.setDate(new Date());
userA.setSqs(CollUtil.newArrayList(new Seq(null), new Seq("seq2")));
JSONObject json = JSONUtil.parseObj(userA, false);
final JSONObject json = JSONUtil.parseObj(userA, false);
Assert.assertTrue(json.containsKey("a"));
Assert.assertTrue(json.getJSONArray("sqs").getJSONObject(0).containsKey("seq"));
@@ -330,28 +330,28 @@ public class JSONObjectTest {
@Test
public void parseBeanTest2() {
TestBean bean = new TestBean();
final TestBean bean = new TestBean();
bean.setDoubleValue(111.1);
bean.setIntValue(123);
bean.setList(CollUtil.newArrayList("a", "b", "c"));
bean.setStrValue("strTest");
bean.setTestEnum(TestEnum.TYPE_B);
JSONObject json = JSONUtil.parseObj(bean, false);
final JSONObject json = JSONUtil.parseObj(bean, false);
// 枚举转换检查
Assert.assertEquals("TYPE_B", json.get("testEnum"));
TestBean bean2 = json.toBean(TestBean.class);
final TestBean bean2 = json.toBean(TestBean.class);
Assert.assertEquals(bean.toString(), bean2.toString());
}
@Test
public void parseBeanTest3() {
JSONObject json = JSONUtil.createObj()
final JSONObject json = JSONUtil.createObj()
.set("code", 22)
.set("data", "{\"jobId\": \"abc\", \"videoUrl\": \"http://a.com/a.mp4\"}");
JSONBean bean = json.toBean(JSONBean.class);
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"));
@@ -359,13 +359,13 @@ public class JSONObjectTest {
@Test
public void beanTransTest() {
UserA userA = new UserA();
final UserA userA = new UserA();
userA.setA("A user");
userA.setName("nameTest");
userA.setDate(new Date());
JSONObject userAJson = JSONUtil.parseObj(userA);
UserB userB = JSONUtil.toBean(userAJson, UserB.class);
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());
@@ -373,63 +373,63 @@ public class JSONObjectTest {
@Test
public void beanTransTest2() {
UserA userA = new UserA();
final UserA userA = new UserA();
userA.setA("A user");
userA.setName("nameTest");
userA.setDate(DateUtil.parse("2018-10-25"));
JSONObject userAJson = JSONUtil.parseObj(userA);
final JSONObject userAJson = JSONUtil.parseObj(userA);
// 自定义日期格式
userAJson.setDateFormat("yyyy-MM-dd");
UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class);
final UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class);
Assert.assertEquals(DateUtil.parse("2018-10-25"), bean.getDate());
}
@Test
public void beanTransTest3() {
JSONObject userAJson = JSONUtil.createObj()
final JSONObject userAJson = JSONUtil.createObj()
.set("a", "AValue")
.set("name", "nameValue")
.set("date", "08:00:00");
UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class);
final UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class);
Assert.assertEquals(DateUtil.formatToday() + " 08:00:00", DateUtil.date(bean.getDate()).toString());
}
@Test
public void parseFromBeanTest() {
UserA userA = new UserA();
final UserA userA = new UserA();
userA.setA(null);
userA.setName("nameTest");
userA.setDate(new Date());
JSONObject userAJson = JSONUtil.parseObj(userA);
final JSONObject userAJson = JSONUtil.parseObj(userA);
Assert.assertFalse(userAJson.containsKey("a"));
JSONObject userAJsonWithNullValue = JSONUtil.parseObj(userA, false);
final JSONObject userAJsonWithNullValue = JSONUtil.parseObj(userA, false);
Assert.assertTrue(userAJsonWithNullValue.containsKey("a"));
Assert.assertTrue(userAJsonWithNullValue.containsKey("sqs"));
}
@Test
public void specialCharTest() {
String json = "{\"pattern\": \"[abc]\b\u2001\", \"pattern2Json\": {\"patternText\": \"[ab]\\b\"}}";
JSONObject obj = JSONUtil.parseObj(json);
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"));
}
@Test
public void getStrTest() {
String json = "{\"name\": \"yyb\\nbbb\"}";
JSONObject jsonObject = JSONUtil.parseObj(json);
final String json = "{\"name\": \"yyb\\nbbb\"}";
final JSONObject jsonObject = JSONUtil.parseObj(json);
// 没有转义按照默认规则显示
Assert.assertEquals("yyb\nbbb", jsonObject.getStr("name"));
// 转义按照字符串显示
Assert.assertEquals("yyb\\nbbb", jsonObject.getStrEscaped("name"));
String bbb = jsonObject.getStr("bbb", "defaultBBB");
final String bbb = jsonObject.getStr("bbb", "defaultBBB");
Assert.assertEquals("defaultBBB", bbb);
}
@@ -443,7 +443,7 @@ public class JSONObjectTest {
Assert.assertEquals("张三", jsonObject.getStr("name"));
Assert.assertEquals(new Integer(35), jsonObject.getInt("age"));
JSONObject json = JSONUtil.createObj()
final JSONObject json = JSONUtil.createObj()
.set("name", "张三")
.set("age", 35);
final BeanWithAlias bean = JSONUtil.toBean(Objects.requireNonNull(json).toString(), BeanWithAlias.class);
@@ -453,10 +453,10 @@ public class JSONObjectTest {
@Test
public void setDateFormatTest() {
JSONConfig jsonConfig = JSONConfig.create();
final JSONConfig jsonConfig = JSONConfig.create();
jsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
JSONObject json = new JSONObject(jsonConfig);
final JSONObject json = new JSONObject(jsonConfig);
json.append("date", DateUtil.parse("2020-06-05 11:16:11"));
json.append("bbb", "222");
json.append("aaa", "123");
@@ -465,16 +465,16 @@ public class JSONObjectTest {
@Test
public void setDateFormatTest2() {
JSONConfig jsonConfig = JSONConfig.create();
final JSONConfig jsonConfig = JSONConfig.create();
jsonConfig.setDateFormat("yyyy#MM#dd");
Date date = DateUtil.parse("2020-06-05 11:16:11");
JSONObject json = new JSONObject(jsonConfig);
final Date date = DateUtil.parse("2020-06-05 11:16:11");
final JSONObject json = new JSONObject(jsonConfig);
json.set("date", date);
json.set("bbb", "222");
json.set("aaa", "123");
String jsonStr = "{\"date\":\"2020#06#05\",\"bbb\":\"222\",\"aaa\":\"123\"}";
final String jsonStr = "{\"date\":\"2020#06#05\",\"bbb\":\"222\",\"aaa\":\"123\"}";
Assert.assertEquals(jsonStr, json.toString());
@@ -485,16 +485,16 @@ public class JSONObjectTest {
@Test
public void setCustomDateFormatTest() {
JSONConfig jsonConfig = JSONConfig.create();
final JSONConfig jsonConfig = JSONConfig.create();
jsonConfig.setDateFormat("#sss");
Date date = DateUtil.parse("2020-06-05 11:16:11");
JSONObject json = new JSONObject(jsonConfig);
final Date date = DateUtil.parse("2020-06-05 11:16:11");
final JSONObject json = new JSONObject(jsonConfig);
json.set("date", date);
json.set("bbb", "222");
json.set("aaa", "123");
String jsonStr = "{\"date\":1591326971,\"bbb\":\"222\",\"aaa\":\"123\"}";
final String jsonStr = "{\"date\":1591326971,\"bbb\":\"222\",\"aaa\":\"123\"}";
Assert.assertEquals(jsonStr, json.toString());
@@ -505,7 +505,7 @@ public class JSONObjectTest {
@Test
public void getTimestampTest() {
String timeStr = "1970-01-01 00:00:00";
final String timeStr = "1970-01-01 00:00:00";
final JSONObject jsonObject = JSONUtil.createObj().set("time", timeStr);
final Timestamp time = jsonObject.get("time", Timestamp.class);
Assert.assertEquals("1970-01-01 00:00:00.0", time.toString());
@@ -604,7 +604,7 @@ public class JSONObjectTest {
@Test
public void floatTest() {
Map<String, Object> map = new HashMap<>();
final Map<String, Object> map = new HashMap<>();
map.put("c", 2.0F);
final String s = JSONUtil.toJsonStr(map);
@@ -625,7 +625,7 @@ public class JSONObjectTest {
@Test
public void putByPathTest() {
JSONObject json = new JSONObject();
final JSONObject json = new JSONObject();
json.putByPath("aa.bb", "BB");
Assert.assertEquals("{\"aa\":{\"bb\":\"BB\"}}", json.toString());
}
@@ -633,8 +633,8 @@ public class JSONObjectTest {
@Test
public void bigDecimalTest() {
String jsonStr = "{\"orderId\":\"1704747698891333662002277\"}";
BigDecimalBean bigDecimalBean = JSONUtil.toBean(jsonStr, BigDecimalBean.class);
final String jsonStr = "{\"orderId\":\"1704747698891333662002277\"}";
final BigDecimalBean bigDecimalBean = JSONUtil.toBean(jsonStr, BigDecimalBean.class);
Assert.assertEquals("{\"orderId\":1704747698891333662002277}", JSONUtil.toJsonStr(bigDecimalBean));
}
@@ -646,7 +646,7 @@ public class JSONObjectTest {
@Test
public void filterIncludeTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("a", "value1")
.set("b", "value2")
.set("c", "value3")
@@ -658,7 +658,7 @@ public class JSONObjectTest {
@Test
public void filterExcludeTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("a", "value1")
.set("b", "value2")
.set("c", "value3")
@@ -670,7 +670,7 @@ public class JSONObjectTest {
@Test
public void editTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("a", "value1")
.set("b", "value2")
.set("c", "value3")
@@ -690,7 +690,7 @@ public class JSONObjectTest {
@Test
public void toUnderLineCaseTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create())
.set("aKey", "value1")
.set("bJob", "value2")
.set("cGood", "value3")
@@ -705,7 +705,7 @@ public class JSONObjectTest {
@Test
public void nullToEmptyTest() {
JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setIgnoreNullValue(false))
final JSONObject json1 = JSONUtil.createObj(JSONConfig.create().setIgnoreNullValue(false))
.set("a", null)
.set("b", "value2");
@@ -718,18 +718,18 @@ public class JSONObjectTest {
@Test
public void parseFilterTest() {
String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject jsonObject = new JSONObject(jsonStr, null, (pair)-> "b".equals(pair.getKey()));
final JSONObject jsonObject = new JSONObject(jsonStr, null, (pair)-> "b".equals(pair.getKey()));
Assert.assertEquals(1, jsonObject.size());
Assert.assertEquals("value2", jsonObject.get("b"));
}
@Test
public void parseFilterEditTest() {
String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}";
//noinspection MismatchedQueryAndUpdateOfCollection
JSONObject jsonObject = new JSONObject(jsonStr, null, (pair)-> {
final JSONObject jsonObject = new JSONObject(jsonStr, null, (pair)-> {
if("b".equals(pair.getKey())){
pair.setValue(pair.getValue() + "_edit");
}

View File

@@ -13,7 +13,7 @@ public class JSONPathTest {
@Test
public void getByPathTest() {
String json = "[{\"id\":\"1\",\"name\":\"xingming\"},{\"id\":\"2\",\"name\":\"mingzi\"}]";
final String json = "[{\"id\":\"1\",\"name\":\"xingming\"},{\"id\":\"2\",\"name\":\"mingzi\"}]";
Object value = JSONUtil.parseArray(json).getByPath("[0].name");
Assert.assertEquals("xingming", value);
value = JSONUtil.parseArray(json).getByPath("[1].name");
@@ -22,9 +22,9 @@ public class JSONPathTest {
@Test
public void getByPathTest2(){
String str = "{'accountId':111}";
JSON json = JSONUtil.parse(str);
Long accountId = JSONUtil.getByPath(json, "$.accountId", 0L);
final String str = "{'accountId':111}";
final JSON json = JSONUtil.parse(str);
final Long accountId = JSONUtil.getByPath(json, "$.accountId", 0L);
Assert.assertEquals(111L, accountId.longValue());
}
}

View File

@@ -14,29 +14,29 @@ public class JSONStrFormatterTest {
@Test
public void formatTest() {
String json = "{'age':23,'aihao':['pashan','movies'],'name':{'firstName':'zhang','lastName':'san','aihao':['pashan','movies','name':{'firstName':'zhang','lastName':'san','aihao':['pashan','movies']}]}}";
String result = JSONStrFormatter.format(json);
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);
}
@Test
public void formatTest2() {
String json = "{\"abc\":{\"def\":\"\\\"[ghi]\"}}";
String result = JSONStrFormatter.format(json);
final String json = "{\"abc\":{\"def\":\"\\\"[ghi]\"}}";
final String result = JSONStrFormatter.format(json);
Assert.assertNotNull(result);
}
@Test
public void formatTest3() {
String json = "{\"id\":13,\"title\":\"《标题》\",\"subtitle\":\"副标题z'c'z'xv'c'xv\",\"user_id\":6,\"type\":0}";
String result = JSONStrFormatter.format(json);
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);
}
@Test
@Ignore
public void formatTest4(){
String jsonStr = "{\"employees\":[{\"firstName\":\"Bill\",\"lastName\":\"Gates\"},{\"firstName\":\"George\",\"lastName\":\"Bush\"},{\"firstName\":\"Thomas\",\"lastName\":\"Carter\"}]}";
final String jsonStr = "{\"employees\":[{\"firstName\":\"Bill\",\"lastName\":\"Gates\"},{\"firstName\":\"George\",\"lastName\":\"Bush\"},{\"firstName\":\"Thomas\",\"lastName\":\"Carter\"}]}";
Console.log(JSONUtil.formatJsonStr(jsonStr));
}
}

View File

@@ -14,7 +14,7 @@ public class JSONSupportTest {
*/
@Test
public void parseTest() {
String jsonstr = "{\n" +
final String jsonstr = "{\n" +
" \"location\": \"https://hutool.cn\",\n" +
" \"message\": \"这是一条测试消息\",\n" +
" \"requestId\": \"123456789\",\n" +

View File

@@ -26,7 +26,7 @@ public class JSONUtilTest {
*/
@Test(expected = JSONException.class)
public void parseTest() {
JSONArray jsonArray = JSONUtil.parseArray("[{\"a\":\"a\\x]");
final JSONArray jsonArray = JSONUtil.parseArray("[{\"a\":\"a\\x]");
Console.log(jsonArray);
}
@@ -35,7 +35,7 @@ public class JSONUtilTest {
*/
@Test(expected = JSONException.class)
public void parseNumberTest() {
JSONArray json = JSONUtil.parseArray(123L);
final JSONArray json = JSONUtil.parseArray(123L);
Assert.assertNotNull(json);
}
@@ -44,42 +44,42 @@ public class JSONUtilTest {
*/
@Test
public void parseNumberTest2() {
JSONObject json = JSONUtil.parseObj(123L);
final JSONObject json = JSONUtil.parseObj(123L);
Assert.assertEquals(new JSONObject(), json);
}
@Test
public void toJsonStrTest() {
UserA a1 = new UserA();
final UserA a1 = new UserA();
a1.setA("aaaa");
a1.setDate(DateUtil.date());
a1.setName("AAAAName");
UserA a2 = new UserA();
final UserA a2 = new UserA();
a2.setA("aaaa222");
a2.setDate(DateUtil.date());
a2.setName("AAAA222Name");
ArrayList<UserA> list = CollUtil.newArrayList(a1, a2);
HashMap<String, Object> map = MapUtil.newHashMap();
final ArrayList<UserA> list = CollUtil.newArrayList(a1, a2);
final HashMap<String, Object> map = MapUtil.newHashMap();
map.put("total", 13);
map.put("rows", list);
String str = JSONUtil.toJsonPrettyStr(map);
final String str = JSONUtil.toJsonPrettyStr(map);
JSONUtil.parse(str);
Assert.assertNotNull(str);
}
@Test
public void toJsonStrTest2() {
Map<String, Object> model = new HashMap<>();
final Map<String, Object> model = new HashMap<>();
model.put("mobile", "17610836523");
model.put("type", 1);
Map<String, Object> data = new HashMap<>();
final Map<String, Object> data = new HashMap<>();
data.put("model", model);
data.put("model2", model);
JSONObject jsonObject = JSONUtil.parseObj(data);
final JSONObject jsonObject = JSONUtil.parseObj(data);
Assert.assertTrue(jsonObject.containsKey("model"));
Assert.assertEquals(1, jsonObject.getJSONObject("model").getInt("type").intValue());
@@ -90,25 +90,25 @@ public class JSONUtilTest {
@Test
public void toJsonStrTest3() {
// 验证某个字段为JSON字符串时转义是否规范
JSONObject object = new JSONObject(true);
final JSONObject object = new JSONObject(true);
object.set("name", "123123");
object.set("value", "\\");
object.set("value2", "</");
HashMap<String, String> map = MapUtil.newHashMap();
final HashMap<String, String> map = MapUtil.newHashMap();
map.put("user", object.toString());
JSONObject json = JSONUtil.parseObj(map);
final JSONObject json = JSONUtil.parseObj(map);
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json.get("user"));
Assert.assertEquals("{\"user\":\"{\\\"name\\\":\\\"123123\\\",\\\"value\\\":\\\"\\\\\\\\\\\",\\\"value2\\\":\\\"</\\\"}\"}", json.toString());
JSONObject json2 = JSONUtil.parseObj(json.toString());
final JSONObject json2 = JSONUtil.parseObj(json.toString());
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json2.get("user"));
}
@Test
public void toJsonStrFromSortedTest() {
SortedMap<Object, Object> sortedMap = new TreeMap<Object, Object>() {
final SortedMap<Object, Object> sortedMap = new TreeMap<Object, Object>() {
private static final long serialVersionUID = 1L;
{
@@ -125,20 +125,20 @@ public class JSONUtilTest {
*/
@Test
public void toBeanTest() {
String json = "{\"ADT\":[[{\"BookingCode\":[\"N\",\"N\"]}]]}";
final String json = "{\"ADT\":[[{\"BookingCode\":[\"N\",\"N\"]}]]}";
Price price = JSONUtil.toBean(json, Price.class);
final Price price = JSONUtil.toBean(json, Price.class);
Assert.assertEquals("N", price.getADT().get(0).get(0).getBookingCode().get(0));
}
@Test
public void toBeanTest2() {
// 测试JSONObject转为Bean中字符串字段的情况
String json = "{\"id\":123,\"name\":\"张三\",\"prop\":{\"gender\":\"\", \"age\":18}}";
UserC user = JSONUtil.toBean(json, UserC.class);
final String json = "{\"id\":123,\"name\":\"张三\",\"prop\":{\"gender\":\"\", \"age\":18}}";
final UserC user = JSONUtil.toBean(json, UserC.class);
Assert.assertNotNull(user.getProp());
String prop = user.getProp();
JSONObject propJson = JSONUtil.parseObj(prop);
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());
@@ -146,22 +146,22 @@ public class JSONUtilTest {
@Test
public void getStrTest() {
String html = "{\"name\":\"Something must have been changed since you leave\"}";
JSONObject jsonObject = JSONUtil.parseObj(html);
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"));
}
@Test
public void getStrTest2() {
String html = "{\"name\":\"Something\\u00a0must have been changed since you leave\"}";
JSONObject jsonObject = JSONUtil.parseObj(html);
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"));
}
@Test
public void parseFromXmlTest() {
String s = "<sfzh>640102197312070614</sfzh><sfz>640102197312070614X</sfz><name>aa</name><gender>1</gender>";
JSONObject json = JSONUtil.parseFromXml(s);
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"));
@@ -170,7 +170,7 @@ public class JSONUtilTest {
@Test
public void doubleTest() {
String json = "{\"test\": 12.00}";
final String json = "{\"test\": 12.00}";
final JSONObject jsonObject = JSONUtil.parseObj(json);
//noinspection BigDecimalMethodWithoutRoundingCalled
Assert.assertEquals("12.00", jsonObject.getBigDecimal("test").setScale(2).toString());
@@ -222,7 +222,7 @@ public class JSONUtilTest {
@Test
public void parseBigNumberTest(){
// 科学计数法使用BigDecimal处理默认输出非科学计数形式
String str = "{\"test\":100000054128897953e4}";
final String str = "{\"test\":100000054128897953e4}";
Assert.assertEquals("{\"test\":1000000541288979530000}", JSONUtil.parseObj(str).toString());
}

View File

@@ -1,16 +1,15 @@
package cn.hutool.json;
import java.util.List;
import cn.hutool.core.collection.CollUtil;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.collection.CollUtil;
import java.util.List;
/**
* 测试Bean中嵌套List等对象时是否完整转换<br>
* 同时测试私有class是否可以有效实例化
*
*
* @author looly
*
*/
@@ -19,21 +18,21 @@ public class ParseBeanTest {
@Test
public void parseBeanTest() {
C c1 = new C();
final C c1 = new C();
c1.setTest("test1");
C c2 = new C();
final C c2 = new C();
c2.setTest("test2");
B b1 = new B();
final B b1 = new B();
b1.setCs(CollUtil.newArrayList(c1, c2));
B b2 = new B();
final B b2 = new B();
b2.setCs(CollUtil.newArrayList(c1, c2));
A a = new A();
final A a = new A();
a.setBs(CollUtil.newArrayList(b1, b2));
JSONObject json = JSONUtil.parseObj(a);
A a1 = JSONUtil.toBean(json, A.class);
final JSONObject json = JSONUtil.parseObj(a);
final A a1 = JSONUtil.toBean(json, A.class);
Assert.assertEquals(json.toString(), JSONUtil.toJsonStr(a1));
}
@@ -47,7 +46,7 @@ class A {
return bs;
}
public void setBs(List<B> bs) {
public void setBs(final List<B> bs) {
this.bs = bs;
}
}
@@ -60,7 +59,7 @@ class B {
return cs;
}
public void setCs(List<C> cs) {
public void setCs(final List<C> cs) {
this.cs = cs;
}
}
@@ -72,7 +71,7 @@ class C {
return test;
}
public void setTest(String test) {
public void setTest(final String test) {
this.test = test;
}
}

View File

@@ -11,9 +11,9 @@ public class Pr192Test {
@Test
public void toBeanTest3() {
// 测试数字类型精度丢失的情况
String number = "1234.123456789123456";
String jsonString = "{\"create\":{\"details\":[{\"price\":" + number + "}]}}";
WebCreate create = JSONUtil.toBean(jsonString, WebCreate.class);
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());
}
@@ -26,7 +26,7 @@ public class Pr192Test {
'}';
}
public void setCreate(Create create) {
public void setCreate(final Create create) {
this.create = create;
}
@@ -45,7 +45,7 @@ public class Pr192Test {
private List<Detail> details;
public void setDetails(List<Detail> details) {
public void setDetails(final List<Detail> details) {
this.details = details;
}
@@ -57,7 +57,7 @@ public class Pr192Test {
static class Detail {
private BigDecimal price;
public void setPrice(BigDecimal price) {
public void setPrice(final BigDecimal price) {
this.price = price;
}

View File

@@ -14,7 +14,7 @@ public class TransientTest {
@Test
public void beanWithoutTransientTest(){
Bill detailBill = new Bill();
final Bill detailBill = new Bill();
detailBill.setId("3243");
detailBill.setBizNo("bizNo");
@@ -26,7 +26,7 @@ public class TransientTest {
@Test
public void beanWithTransientTest(){
Bill detailBill = new Bill();
final Bill detailBill = new Bill();
detailBill.setId("3243");
detailBill.setBizNo("bizNo");
@@ -38,7 +38,7 @@ public class TransientTest {
@Test
public void beanWithoutTransientToBeanTest(){
Bill detailBill = new Bill();
final Bill detailBill = new Bill();
detailBill.setId("3243");
detailBill.setBizNo("bizNo");
@@ -52,7 +52,7 @@ public class TransientTest {
@Test
public void beanWithTransientToBeanTest(){
Bill detailBill = new Bill();
final Bill detailBill = new Bill();
detailBill.setId("3243");
detailBill.setBizNo("bizNo");

View File

@@ -16,12 +16,12 @@ public class IssueIVMD5Test {
*/
@Test
public void toBeanTest() {
String jsonStr = ResourceUtil.readUtf8Str("issueIVMD5.json");
final String jsonStr = ResourceUtil.readUtf8Str("issueIVMD5.json");
TypeReference<BaseResult<StudentInfo>> typeReference = new TypeReference<BaseResult<StudentInfo>>() {};
BaseResult<StudentInfo> bean = JSONUtil.toBean(jsonStr, typeReference.getType(), false);
final TypeReference<BaseResult<StudentInfo>> typeReference = new TypeReference<BaseResult<StudentInfo>>() {};
final BaseResult<StudentInfo> bean = JSONUtil.toBean(jsonStr, typeReference.getType(), false);
StudentInfo data2 = bean.getData2();
final StudentInfo data2 = bean.getData2();
Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", data2.getAccountId());
}
@@ -30,13 +30,13 @@ public class IssueIVMD5Test {
*/
@Test
public void toBeanTest2() {
String jsonStr = ResourceUtil.readUtf8Str("issueIVMD5.json");
final String jsonStr = ResourceUtil.readUtf8Str("issueIVMD5.json");
TypeReference<BaseResult<StudentInfo>> typeReference = new TypeReference<BaseResult<StudentInfo>>() {};
BaseResult<StudentInfo> bean = JSONUtil.toBean(jsonStr, typeReference.getType(), false);
final TypeReference<BaseResult<StudentInfo>> typeReference = new TypeReference<BaseResult<StudentInfo>>() {};
final BaseResult<StudentInfo> bean = JSONUtil.toBean(jsonStr, typeReference.getType(), false);
List<StudentInfo> data = bean.getData();
StudentInfo studentInfo = data.get(0);
final List<StudentInfo> data = bean.getData();
final StudentInfo studentInfo = data.get(0);
Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", studentInfo.getAccountId());
}
}

View File

@@ -12,7 +12,7 @@ public class JWTSignerTest {
@Test
public void hs256Test(){
String id = "hs256";
final String id = "hs256";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -28,7 +28,7 @@ public class JWTSignerTest {
@Test
public void hs384Test(){
String id = "hs384";
final String id = "hs384";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -37,7 +37,7 @@ public class JWTSignerTest {
@Test
public void hs512Test(){
String id = "hs512";
final String id = "hs512";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -46,7 +46,7 @@ public class JWTSignerTest {
@Test
public void rs256Test(){
String id = "rs256";
final String id = "rs256";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -55,7 +55,7 @@ public class JWTSignerTest {
@Test
public void rs384Test(){
String id = "rs384";
final String id = "rs384";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -64,7 +64,7 @@ public class JWTSignerTest {
@Test
public void rs512Test(){
String id = "rs512";
final String id = "rs512";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -73,7 +73,7 @@ public class JWTSignerTest {
@Test
public void es256Test(){
String id = "es256";
final String id = "es256";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -82,7 +82,7 @@ public class JWTSignerTest {
@Test
public void es384Test(){
String id = "es384";
final String id = "es384";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -91,7 +91,7 @@ public class JWTSignerTest {
@Test
public void es512Test(){
String id = "es512";
final String id = "es512";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -100,7 +100,7 @@ public class JWTSignerTest {
@Test
public void ps256Test(){
String id = "ps256";
final String id = "ps256";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
@@ -109,22 +109,22 @@ public class JWTSignerTest {
@Test
public void ps384Test(){
String id = "ps384";
final String id = "ps384";
final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id)));
Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm());
signAndVerify(signer);
}
private static void signAndVerify(JWTSigner signer){
JWT jwt = JWT.create()
private static void signAndVerify(final JWTSigner signer){
final JWT jwt = JWT.create()
.setPayload("sub", "1234567890")
.setPayload("name", "looly")
.setPayload("admin", true)
.setExpiresAt(DateUtil.tomorrow())
.setSigner(signer);
String token = jwt.sign();
final String token = jwt.sign();
Assert.assertTrue(JWT.of(token).verify(signer));
}
}

View File

@@ -10,19 +10,19 @@ public class JWTTest {
@Test
public void createHs256Test(){
byte[] key = "1234567890".getBytes();
JWT jwt = JWT.create()
final byte[] key = "1234567890".getBytes();
final JWT jwt = JWT.create()
.setPayload("sub", "1234567890")
.setPayload("name", "looly")
.setPayload("admin", true)
.setExpiresAt(DateUtil.parse("2022-01-01"))
.setKey(key);
String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Imxvb2x5IiwiYWRtaW4iOnRydWUsImV4cCI6MTY0MDk2NjQwMH0." +
"bXlSnqVeJXWqUIt7HyEhgKNVlIPjkumHlAwFY-5YCtk";
String token = jwt.sign();
final String token = jwt.sign();
Assert.assertEquals(rightToken, token);
Assert.assertTrue(JWT.of(rightToken).setKey(key).verify());
@@ -30,7 +30,7 @@ public class JWTTest {
@Test
public void parseTest(){
String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
"eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9." +
"U2aQkC2THYV9L0fTN-yBBI7gmo5xhmvMhATtu8v0zEA";
@@ -51,16 +51,16 @@ public class JWTTest {
@Test
public void createNoneTest(){
JWT jwt = JWT.create()
final JWT jwt = JWT.create()
.setPayload("sub", "1234567890")
.setPayload("name", "looly")
.setPayload("admin", true)
.setSigner(JWTSignerUtil.none());
String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
"eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9.";
String token = jwt.sign();
final String token = jwt.sign();
Assert.assertEquals(token, token);
Assert.assertTrue(JWT.of(rightToken).setSigner(JWTSignerUtil.none()).verify());
@@ -71,7 +71,7 @@ public class JWTTest {
*/
@Test(expected = JWTException.class)
public void needSignerTest(){
JWT jwt = JWT.create()
final JWT jwt = JWT.create()
.setPayload("sub", "1234567890")
.setPayload("name", "looly")
.setPayload("admin", true);
@@ -81,7 +81,7 @@ public class JWTTest {
@Test
public void verifyTest(){
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
"eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE2MjQwMDQ4MjIsInVzZXJJZCI6MSwiYXV0aG9yaXRpZXMiOlsiUk9MRV_op5LoibLkuozlj7ciLCJzeXNfbWVudV8xIiwiUk9MRV_op5LoibLkuIDlj7ciLCJzeXNfbWVudV8yIl0sImp0aSI6ImQ0YzVlYjgwLTA5ZTctNGU0ZC1hZTg3LTVkNGI5M2FhNmFiNiIsImNsaWVudF9pZCI6ImhhbmR5LXNob3AifQ." +
"aixF1eKlAKS_k3ynFnStE7-IRGiD5YaqznvK2xEjBew";

View File

@@ -10,8 +10,8 @@ public class JWTUtilTest {
@Test
public void createTest(){
byte[] key = "1234".getBytes();
Map<String, Object> map = new HashMap<String, Object>() {
final byte[] key = "1234".getBytes();
final Map<String, Object> map = new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put("uid", Integer.parseInt("123"));
@@ -25,7 +25,7 @@ public class JWTUtilTest {
@Test
public void parseTest(){
String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
"eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9." +
"U2aQkC2THYV9L0fTN-yBBI7gmo5xhmvMhATtu8v0zEA";
final JWT jwt = JWTUtil.parseToken(rightToken);
@@ -45,7 +45,7 @@ public class JWTUtilTest {
@Test
public void verifyTest(){
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
"eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE2MjQwMDQ4MjIsInVzZXJJZCI6MSwiYXV0aG9yaXRpZXMiOlsiUk9MRV_op5LoibLkuozlj7ciLCJzeXNfbWVudV8xIiwiUk9MRV_op5LoibLkuIDlj7ciLCJzeXNfbWVudV8yIl0sImp0aSI6ImQ0YzVlYjgwLTA5ZTctNGU0ZC1hZTg3LTVkNGI5M2FhNmFiNiIsImNsaWVudF9pZCI6ImhhbmR5LXNob3AifQ." +
"aixF1eKlAKS_k3ynFnStE7-IRGiD5YaqznvK2xEjBew";

View File

@@ -10,7 +10,7 @@ public class JWTValidatorTest {
@Test(expected = ValidateException.class)
public void expiredAtTest(){
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo";
final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo";
JWTValidator.of(token).validateDate(DateUtil.date());
}
@@ -64,9 +64,9 @@ public class JWTValidatorTest {
@Test
public void validateTest(){
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNb0xpIiwiZXhwIjoxNjI0OTU4MDk0NTI4LCJpYXQiOjE2MjQ5NTgwMzQ1MjAsInVzZXIiOiJ1c2VyIn0.L0uB38p9sZrivbmP0VlDe--j_11YUXTu3TfHhfQhRKc";
byte[] key = "1234567890".getBytes();
boolean validate = JWT.of(token).setKey(key).validate(0);
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);
}

View File

@@ -15,7 +15,7 @@ public class JsonNode implements Serializable {
public JsonNode() {
}
public JsonNode(Long id, Integer parentId, String name) {
public JsonNode(final Long id, final Integer parentId, final String name) {
this.id = id;
this.parentId = parentId;
this.name = name;

View File

@@ -66,7 +66,7 @@ public class ResultDto<T> implements Serializable {
* @param code the code
* @param message the message
*/
public ResultDto(int code, String message) {
public ResultDto(final int code, final String message) {
this(code, message, null);
}
@@ -77,7 +77,7 @@ public class ResultDto<T> implements Serializable {
* @param message the message
* @param result the result
*/
public ResultDto(int code, String message, T result) {
public ResultDto(final int code, final String message, final T result) {
this.code(code).message(message).result(result);
}
@@ -87,7 +87,7 @@ public class ResultDto<T> implements Serializable {
* @param code the new 编号
* @return the wrapper
*/
private ResultDto<T> code(int code) {
private ResultDto<T> code(final int code) {
this.setCode(code);
return this;
}
@@ -98,7 +98,7 @@ public class ResultDto<T> implements Serializable {
* @param message the new 信息
* @return the wrapper
*/
private ResultDto<T> message(String message) {
private ResultDto<T> message(final String message) {
this.setMessage(message);
return this;
}
@@ -109,7 +109,7 @@ public class ResultDto<T> implements Serializable {
* @param result the new 结果数据
* @return the wrapper
*/
public ResultDto<T> result(T result) {
public ResultDto<T> result(final T result) {
this.setResult(result);
return this;
}

View File

@@ -9,7 +9,7 @@ public class Seq {
public Seq() {
}
public Seq(String seq) {
public Seq(final String seq) {
this.seq = seq;
}
}

View File

@@ -10,17 +10,17 @@ import java.util.List;
*
*/
public class CaseReport {
/**
* 包含的测试步骤报告
*/
private List<StepReport> stepReports = new ArrayList<>();
public List<StepReport> getStepReports() {
return stepReports;
}
public void setStepReports(List<StepReport> stepReports) {
public void setStepReports(final List<StepReport> stepReports) {
this.stepReports = stepReports;
}

View File

@@ -9,29 +9,29 @@ import java.util.Collection;
*
*/
public class EnvSettingInfo {
public static boolean DEV_MODE = true;
private boolean remoteMode;
private String hubRemoteUrl;
private String reportFolder = "/report";
private String screenshotFolder = "/screenshot";
private String elementFolder = "/config/element/";
private String suiteFolder = "/config/suite/";
private String chromeDriverPath = "/src/main/resources/chromedriver.exe";
private String ieDriverPath = "/src/main/resources/IEDriverServer.exe";
private String operaDriverPath = "/src/main/resources/operadriver.exe";
private String firefoxDriverPath = "/src/main/resources/geckodriver.exe";
private Double defaultSleepSeconds;
private Integer elementLocationRetryCount;
private Double elementLocationTimeouts;
/**
* 收件人列表
*/
@@ -44,51 +44,51 @@ public class EnvSettingInfo {
* 密送人列表
*/
private Collection<String> bccs;
/**
* 是否可以开启定时任务
*/
private boolean cronEnabled = false;
/**
* 定时执行suite文件
*/
private String cronSuite;
/**
* 定时执行cron表达式支持linux crontab格式(5位)和Quartz的cron格式(6位)
*/
private String cronExpression;
/**
* 存储测试报告数据的轻量级数据库,路径
*/
private String sqlitePath;
public EnvSettingInfo() {
}
public void setSqlitePath(String sqlitePath) {
public void setSqlitePath(final String sqlitePath) {
this.sqlitePath = sqlitePath;
}
public String getSqlitePath() {
return sqlitePath;
}
public void setCronEnabled(boolean cronEnabled) {
public void setCronEnabled(final boolean cronEnabled) {
this.cronEnabled = cronEnabled;
}
public boolean isCronEnabled() {
return cronEnabled;
}
public String getCronSuite() {
return cronSuite;
}
public void setCronSuite(String cronSuite) {
public void setCronSuite(final String cronSuite) {
this.cronSuite = cronSuite;
}
@@ -96,7 +96,7 @@ public class EnvSettingInfo {
return cronExpression;
}
public void setCronExpression(String cronExpression) {
public void setCronExpression(final String cronExpression) {
this.cronExpression = cronExpression;
}
@@ -104,7 +104,7 @@ public class EnvSettingInfo {
return elementLocationRetryCount;
}
public void setElementLocationRetryCount(Integer elementLocationRetryCount) {
public void setElementLocationRetryCount(final Integer elementLocationRetryCount) {
this.elementLocationRetryCount = elementLocationRetryCount;
}
@@ -112,7 +112,7 @@ public class EnvSettingInfo {
return elementLocationTimeouts;
}
public void setElementLocationTimeouts(Double elementLocationTimeouts) {
public void setElementLocationTimeouts(final Double elementLocationTimeouts) {
this.elementLocationTimeouts = elementLocationTimeouts;
}
@@ -120,7 +120,7 @@ public class EnvSettingInfo {
return elementFolder;
}
public void setElementFolder(String elementFolder) {
public void setElementFolder(final String elementFolder) {
this.elementFolder = elementFolder;
}
@@ -128,7 +128,7 @@ public class EnvSettingInfo {
return suiteFolder;
}
public void setSuiteFolder(String suiteFolder) {
public void setSuiteFolder(final String suiteFolder) {
this.suiteFolder = suiteFolder;
}
@@ -136,7 +136,7 @@ public class EnvSettingInfo {
return remoteMode;
}
public void setRemoteMode(boolean remoteMode) {
public void setRemoteMode(final boolean remoteMode) {
this.remoteMode = remoteMode;
}
@@ -144,7 +144,7 @@ public class EnvSettingInfo {
return hubRemoteUrl;
}
public void setHubRemoteUrl(String hubRemoteUrl) {
public void setHubRemoteUrl(final String hubRemoteUrl) {
this.hubRemoteUrl = hubRemoteUrl;
}
@@ -152,7 +152,7 @@ public class EnvSettingInfo {
return reportFolder;
}
public void setReportFolder(String reportFolder) {
public void setReportFolder(final String reportFolder) {
this.reportFolder = reportFolder;
}
@@ -160,7 +160,7 @@ public class EnvSettingInfo {
return screenshotFolder;
}
public void setScreenshotFolder(String screenshotFolder) {
public void setScreenshotFolder(final String screenshotFolder) {
this.screenshotFolder = screenshotFolder;
}
@@ -168,7 +168,7 @@ public class EnvSettingInfo {
return chromeDriverPath;
}
public void setChromeDriverPath(String chromeDriverPath) {
public void setChromeDriverPath(final String chromeDriverPath) {
this.chromeDriverPath = chromeDriverPath;
}
@@ -176,7 +176,7 @@ public class EnvSettingInfo {
return ieDriverPath;
}
public void setIeDriverPath(String ieDriverPath) {
public void setIeDriverPath(final String ieDriverPath) {
this.ieDriverPath = ieDriverPath;
}
@@ -184,7 +184,7 @@ public class EnvSettingInfo {
return operaDriverPath;
}
public void setOperaDriverPath(String operaDriverPath) {
public void setOperaDriverPath(final String operaDriverPath) {
this.operaDriverPath = operaDriverPath;
}
@@ -192,7 +192,7 @@ public class EnvSettingInfo {
return firefoxDriverPath;
}
public void setFirefoxDriverPath(String firefoxDriverPath) {
public void setFirefoxDriverPath(final String firefoxDriverPath) {
this.firefoxDriverPath = firefoxDriverPath;
}
@@ -200,7 +200,7 @@ public class EnvSettingInfo {
return defaultSleepSeconds;
}
public void setDefaultSleepSeconds(Double defaultSleepSeconds) {
public void setDefaultSleepSeconds(final Double defaultSleepSeconds) {
this.defaultSleepSeconds = defaultSleepSeconds;
}
@@ -208,7 +208,7 @@ public class EnvSettingInfo {
return tos;
}
public void setTos(Collection<String> tos) {
public void setTos(final Collection<String> tos) {
this.tos = tos;
}
@@ -216,7 +216,7 @@ public class EnvSettingInfo {
return ccs;
}
public void setCcs(Collection<String> ccs) {
public void setCcs(final Collection<String> ccs) {
this.ccs = ccs;
}
@@ -224,7 +224,7 @@ public class EnvSettingInfo {
return bccs;
}
public void setBccs(Collection<String> bccs) {
public void setBccs(final Collection<String> bccs) {
this.bccs = bccs;
}

View File

@@ -62,11 +62,11 @@ public class StepReport {
return stepId;
}
public void setStepId(int stepId) {
public void setStepId(final int stepId) {
this.stepId = stepId;
}
public void setResult(String result) {
public void setResult(final String result) {
this.result = result;
}
@@ -78,7 +78,7 @@ public class StepReport {
return stepName;
}
public void setStepName(String stepName) {
public void setStepName(final String stepName) {
this.stepName = stepName;
}
@@ -90,7 +90,7 @@ public class StepReport {
return elementName;
}
public void setElementName(String elementName) {
public void setElementName(final String elementName) {
this.elementName = elementName;
}
@@ -98,7 +98,7 @@ public class StepReport {
return location;
}
public void setLocation(String location) {
public void setLocation(final String location) {
this.location = location;
}
@@ -106,7 +106,7 @@ public class StepReport {
return params;
}
public void setParams(String params) {
public void setParams(final String params) {
this.params = params;
}
@@ -114,7 +114,7 @@ public class StepReport {
return actionName;
}
public void setActionName(String actionName) {
public void setActionName(final String actionName) {
this.actionName = actionName;
}
@@ -122,7 +122,7 @@ public class StepReport {
return testTime;
}
public void setTestTime(String testTime) {
public void setTestTime(final String testTime) {
this.testTime = testTime;
}
@@ -130,7 +130,7 @@ public class StepReport {
return status;
}
public void setStatus(boolean status) {
public void setStatus(final boolean status) {
this.status = status;
}
@@ -138,7 +138,7 @@ public class StepReport {
return mark;
}
public void setMark(String mark) {
public void setMark(final String mark) {
this.mark = mark;
}
@@ -146,7 +146,7 @@ public class StepReport {
return screenshot;
}
public void setScreenshot(String screenshot) {
public void setScreenshot(final String screenshot) {
this.screenshot = screenshot;
}

View File

@@ -10,17 +10,17 @@ import java.util.List;
*
*/
public class SuiteReport {
/**
* 包含的用例测试报告
*/
private List<CaseReport> caseReports = new ArrayList<>();
public List<CaseReport> getCaseReports() {
return caseReports;
}
public void setCaseReports(List<CaseReport> caseReports) {
public void setCaseReports(final List<CaseReport> caseReports) {
this.caseReports = caseReports;
}

View File

@@ -21,18 +21,18 @@ public class XMLTest {
@Test
public void escapeTest(){
String xml = "<a>•</a>";
JSONObject jsonObject = XML.toJSONObject(xml);
final String xml = "<a>•</a>";
final JSONObject jsonObject = XML.toJSONObject(xml);
Assert.assertEquals("{\"a\":\"\"}", jsonObject.toString());
String xml2 = XML.toXml(JSONUtil.parseObj(jsonObject));
final String xml2 = XML.toXml(JSONUtil.parseObj(jsonObject));
Assert.assertEquals(xml, xml2);
}
@Test
public void xmlContentTest(){
JSONObject jsonObject = JSONUtil.createObj().set("content","123456");
final JSONObject jsonObject = JSONUtil.createObj().set("content","123456");
String xml = XML.toXml(jsonObject);
Assert.assertEquals("123456", xml);