mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix bug
This commit is contained in:
@@ -16,8 +16,11 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -76,7 +79,7 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBeanTest(){
|
||||
public void toBeanTest() {
|
||||
SubPerson person = new SubPerson();
|
||||
person.setAge(14);
|
||||
person.setOpenid("11213232");
|
||||
@@ -95,7 +98,7 @@ public class BeanUtilTest {
|
||||
* 忽略转换错误测试
|
||||
*/
|
||||
@Test
|
||||
public void toBeanIgnoreErrorTest(){
|
||||
public void toBeanIgnoreErrorTest() {
|
||||
HashMap<String, Object> map = CollUtil.newHashMap();
|
||||
map.put("name", "Joe");
|
||||
// 错误的类型,此处忽略
|
||||
@@ -372,7 +375,7 @@ public class BeanUtilTest {
|
||||
@Getter
|
||||
@Setter
|
||||
public static class Person {
|
||||
private String name;
|
||||
private String name;
|
||||
private int age;
|
||||
private String openid;
|
||||
}
|
||||
@@ -384,6 +387,7 @@ public class BeanUtilTest {
|
||||
private int age;
|
||||
private String openid;
|
||||
}
|
||||
|
||||
public static class Person2 {
|
||||
|
||||
public Person2(String name, int age, String openid) {
|
||||
@@ -445,9 +449,9 @@ public class BeanUtilTest {
|
||||
Assert.assertEquals(info.getBookID(), entity.getBookId());
|
||||
Assert.assertEquals(info.getCode(), entity.getCode2());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void copyBeanTest(){
|
||||
public void copyBeanTest() {
|
||||
Food info = new Food();
|
||||
info.setBookID("0");
|
||||
info.setCode("123");
|
||||
@@ -473,14 +477,14 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPropertiesTest(){
|
||||
public void setPropertiesTest() {
|
||||
Map<String, Object> resultMap = MapUtil.newHashMap();
|
||||
BeanUtil.setProperty(resultMap, "codeList[0].name", "张三");
|
||||
Assert.assertEquals("{codeList={0={name=张三}}}", resultMap.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanCopyTest(){
|
||||
public void beanCopyTest() {
|
||||
final Station station = new Station();
|
||||
station.setId(123456L);
|
||||
|
||||
@@ -499,7 +503,38 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Entity<T>{
|
||||
public static class Entity<T> {
|
||||
private T id;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toMapTest() {
|
||||
// 测试转map的时候返回key
|
||||
String name = null;
|
||||
PrivilegeIClassification a = new PrivilegeIClassification();
|
||||
a.setId("1");
|
||||
a.setName("2");
|
||||
a.setCode("3");
|
||||
a.setCreateTime(new Date());
|
||||
a.setSortOrder(9L);
|
||||
|
||||
Map<String, Object> f = BeanUtil.beanToMap(
|
||||
a,
|
||||
new LinkedHashMap<>(),
|
||||
false,
|
||||
key -> Arrays.asList("id", "name", "code", "sortOrder").contains(key) ? key : null);
|
||||
Assert.assertFalse(f.containsKey(null));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PrivilegeIClassification implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String code;
|
||||
private Long rowStatus;
|
||||
private Long sortOrder;
|
||||
private Date createTime;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user