mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -64,4 +64,25 @@ public class BeanCopierTest {
|
||||
private static class B {
|
||||
private String value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为{@code null}则写,否则忽略。如果覆盖,则不判断直接写
|
||||
*/
|
||||
@Test
|
||||
public void issues2484Test() {
|
||||
final A a = new A();
|
||||
a.setValue("abc");
|
||||
final B b = new B();
|
||||
b.setValue("123");
|
||||
|
||||
BeanCopier<B> copier = BeanCopier.of(a, b, CopyOptions.of().setOverride(false));
|
||||
copier.copy();
|
||||
Assert.assertEquals("123", b.getValue());
|
||||
|
||||
b.setValue(null);
|
||||
copier = BeanCopier.of(a, b, CopyOptions.of().setOverride(false));
|
||||
copier.copy();
|
||||
Assert.assertEquals("abc", b.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtilTest.SubPerson;
|
||||
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -91,4 +92,30 @@ public class ConvertToBeanTest {
|
||||
final SubPerson subPerson = Convert.convertQuietly(SubPerson.class, nullStr);
|
||||
Assert.assertNull(subPerson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapToMapWithSelfTypeTest() {
|
||||
final CaseInsensitiveMap<String, Integer> caseInsensitiveMap = new CaseInsensitiveMap<>();
|
||||
caseInsensitiveMap.put("jerry", 1);
|
||||
caseInsensitiveMap.put("Jerry", 2);
|
||||
caseInsensitiveMap.put("tom", 3);
|
||||
|
||||
Map<String, String> map = Convert.toMap(String.class, String.class, caseInsensitiveMap);
|
||||
Assert.assertEquals("2", map.get("jerry"));
|
||||
Assert.assertEquals("2", map.get("Jerry"));
|
||||
Assert.assertEquals("3", map.get("tom"));
|
||||
}
|
||||
@Test
|
||||
public void beanToSpecifyMapTest() {
|
||||
final SubPerson person = new SubPerson();
|
||||
person.setAge(14);
|
||||
person.setOpenid("11213232");
|
||||
person.setName("测试A11");
|
||||
person.setSubName("sub名字");
|
||||
|
||||
Map<String, String> map = Convert.toMap(LinkedHashMap.class, String.class, String.class, person);
|
||||
Assert.assertEquals("测试A11", map.get("name"));
|
||||
Assert.assertEquals("14", map.get("age"));
|
||||
Assert.assertEquals("11213232", map.get("openid"));
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* {@link ZipUtil}单元测试
|
||||
@@ -197,4 +198,19 @@ public class ZipUtilTest {
|
||||
|
||||
ZipUtil.zip(FileUtil.file("d:\\test\\qr.zip"),false,dd);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sizeUnzip() throws IOException {
|
||||
String zipPath = "F:\\BaiduNetdiskDownload\\demo.zip";
|
||||
String outPath = "F:\\BaiduNetdiskDownload\\test";
|
||||
ZipFile zipFile = new ZipFile(zipPath, Charset.forName("GBK"));
|
||||
File file = new File(outPath);
|
||||
// 限制解压文件大小为637KB
|
||||
long size = 637*1024L;
|
||||
|
||||
// 限制解压文件大小为636KB
|
||||
// long size = 636*1024L;
|
||||
ZipUtil.unzip(zipFile, file, size);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user