This commit is contained in:
Looly
2023-03-26 08:53:56 +08:00
parent 1d4d4e0e76
commit f970dc7632
25 changed files with 308 additions and 98 deletions

View File

@@ -3,6 +3,8 @@ package cn.hutool.core.bean;
import cn.hutool.core.lang.test.bean.ExamInfoDict;
import cn.hutool.core.lang.test.bean.UserInfoDict;
import cn.hutool.core.map.Dict;
import cn.hutool.core.util.ArrayUtil;
import lombok.Data;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -152,4 +154,36 @@ public class BeanPathTest {
BeanPath.of("aa.bb").set(dict, "BB");
Assert.assertEquals("{aa={bb=BB}}", dict.toString());
}
@Test
public void appendArrayTest(){
// issue#3008@Github
final MyUser myUser = new MyUser();
BeanPath.of("hobby[0]").set(myUser, "LOL");
BeanPath.of("hobby[1]").set(myUser, "KFC");
BeanPath.of("hobby[2]").set(myUser, "COFFE");
Assert.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(myUser.getHobby()));
}
@Test
public void appendArrayTest2(){
// issue#3008@Github
final MyUser2 myUser = new MyUser2();
BeanPath.of("myUser.hobby[0]").set(myUser, "LOL");
BeanPath.of("myUser.hobby[1]").set(myUser, "KFC");
BeanPath.of("myUser.hobby[2]").set(myUser, "COFFE");
Assert.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(myUser.getMyUser().getHobby()));
}
@Data
static class MyUser {
private String[] hobby;
}
@Data
static class MyUser2 {
private MyUser myUser;
}
}

View File

@@ -78,10 +78,17 @@ public class NetUtilTest {
}
@Test
@Ignore
public void getLocalHostNameTest() {
// 注意此方法会触发反向DNS解析导致阻塞阻塞时间取决于网络
Assert.assertNotNull(NetUtil.getLocalHostName());
}
@Test
public void getLocalHostTest() {
Assert.assertNotNull(NetUtil.getLocalhost());
}
@Test
public void pingTest(){
Assert.assertTrue(NetUtil.ping("127.0.0.1"));