mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix test
This commit is contained in:
parent
a9cc50e98e
commit
c529fa129f
@ -13,6 +13,7 @@
|
||||
package org.dromara.hutool.core.bean;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.dromara.hutool.core.bean.copier.CopyOptions;
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
@ -33,16 +34,33 @@ public class IssueI8M38TTest {
|
||||
final ArrayList<SubPerson> subPeople = ListUtil.of(subPerson);
|
||||
|
||||
final HashMap<String, String> mapping = MapUtil.of("subName", "name");
|
||||
final List<Person> people = BeanUtil.copyToList(subPeople, Person.class,
|
||||
// 不覆盖模式下,当第一次subName已经拷贝到值,后续不再覆盖
|
||||
CopyOptions.of().setFieldMapping(mapping).setOverride(false));
|
||||
|
||||
Assertions.assertEquals(subPerson.getSubName(), people.get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void copyListByMappingTest2() {
|
||||
final SubPerson subPerson = new SubPerson();
|
||||
subPerson.setAge(14);
|
||||
subPerson.setOpenid(112233);
|
||||
subPerson.setSubName("sub名字");
|
||||
final ArrayList<SubPerson> subPeople = ListUtil.of(subPerson);
|
||||
|
||||
final HashMap<String, String> mapping = MapUtil.of("subName", "name");
|
||||
// subName复制到name后,name字段继续拷贝,覆盖了subName的值
|
||||
mapping.put("name", "aaa");
|
||||
final List<Person> people = BeanUtil.copyToList(subPeople, Person.class,
|
||||
CopyOptions.of().setFieldMapping(mapping));
|
||||
|
||||
Assertions.assertEquals(subPerson.getSubName(), people.get(0).getName());
|
||||
}
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
static class SubPerson {
|
||||
private int age;
|
||||
private int openid;
|
||||
static class SubPerson extends Person{
|
||||
private String subName;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user