mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix code
This commit is contained in:
@@ -9,8 +9,8 @@ import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -330,7 +330,7 @@ public class BeanUtilTest {
|
||||
|
||||
for (int i=0;i<5000;i++){
|
||||
new Thread(()->{
|
||||
List<Student> list = ObjectUtil.clone(studentList);
|
||||
List<Student> list = ObjUtil.clone(studentList);
|
||||
List<Student> listReps = list.stream().map(s1 -> {
|
||||
Student s2 = new Student();
|
||||
BeanUtil.copyProperties(s1, s2);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.builder;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.codec;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.codec;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -54,10 +54,10 @@ public class Base64Test {
|
||||
@Test
|
||||
public void encodeAndDecodeTest2() {
|
||||
String a = "a61a5db5a67c01445ca2-HZ20181120172058/pdf/中国电信影像云单体网关Docker版-V1.2.pdf";
|
||||
String encode = Base64.encode(a, CharsetUtil.UTF_8);
|
||||
String encode = Base64.encode(a, CharsetUtil.NAME_UTF_8);
|
||||
Assert.assertEquals("YTYxYTVkYjVhNjdjMDE0NDVjYTItSFoyMDE4MTEyMDE3MjA1OC9wZGYv5Lit5Zu955S15L+h5b2x5YOP5LqR5Y2V5L2T572R5YWzRG9ja2Vy54mILVYxLjIucGRm", encode);
|
||||
|
||||
String decodeStr = Base64.decodeStr(encode, CharsetUtil.UTF_8);
|
||||
String decodeStr = Base64.decodeStr(encode, CharsetUtil.NAME_UTF_8);
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.comparator.ComparableComparator;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.map.Dict;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.core.compiler;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.compress.ZipUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.hutool.core.compress;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.hutool.core.compress;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.FileResource;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -20,7 +19,7 @@ public class ZipWriterTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void addTest(){
|
||||
final ZipWriter writer = ZipWriter.of(FileUtil.file("d:/test/test.zip"), CharsetUtil.CHARSET_UTF_8);
|
||||
final ZipWriter writer = ZipWriter.of(FileUtil.file("d:/test/test.zip"), CharsetUtil.UTF_8);
|
||||
writer.add(new FileResource("d:/test/qr_c.png"));
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ public class ConvertOtherTest {
|
||||
@Test
|
||||
public void hexTest() {
|
||||
String a = "我是一个小小的可爱的字符串";
|
||||
String hex = Convert.toHex(a, CharsetUtil.CHARSET_UTF_8);
|
||||
String hex = Convert.toHex(a, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("e68891e698afe4b880e4b8aae5b08fe5b08fe79a84e58fafe788b1e79a84e5ad97e7aca6e4b8b2", hex);
|
||||
|
||||
String raw = Convert.hexToStr(hex, CharsetUtil.CHARSET_UTF_8);
|
||||
String raw = Convert.hexToStr(hex, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(a, raw);
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ public class ConvertOtherTest {
|
||||
public void convertCharsetTest() {
|
||||
String a = "我不是乱码";
|
||||
// 转换后result为乱码
|
||||
String result = Convert.convertCharset(a, CharsetUtil.UTF_8, CharsetUtil.ISO_8859_1);
|
||||
String raw = Convert.convertCharset(result, CharsetUtil.ISO_8859_1, "UTF-8");
|
||||
String result = Convert.convertCharset(a, CharsetUtil.NAME_UTF_8, CharsetUtil.NAME_ISO_8859_1);
|
||||
String raw = Convert.convertCharset(result, CharsetUtil.NAME_ISO_8859_1, "UTF-8");
|
||||
Assert.assertEquals(raw, a);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package cn.hutool.core.convert;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateException;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.reflect.TypeReference;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ByteUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtilTest.SubPerson;
|
||||
import cn.hutool.core.lang.reflect.TypeReference;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.reflect.TypeReference;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* BufferUtil单元测试
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@@ -49,15 +49,15 @@ public class BufferUtilTest {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(text.getBytes());
|
||||
|
||||
// 第一行
|
||||
String line = BufferUtil.readLine(buffer, CharsetUtil.CHARSET_UTF_8);
|
||||
String line = BufferUtil.readLine(buffer, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("aa", line);
|
||||
|
||||
// 第二行
|
||||
line = BufferUtil.readLine(buffer, CharsetUtil.CHARSET_UTF_8);
|
||||
line = BufferUtil.readLine(buffer, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("bbb", line);
|
||||
|
||||
// 第三行因为没有行结束标志,因此返回null
|
||||
line = BufferUtil.readLine(buffer, CharsetUtil.CHARSET_UTF_8);
|
||||
line = BufferUtil.readLine(buffer, CharsetUtil.UTF_8);
|
||||
Assert.assertNull(line);
|
||||
|
||||
// 读取剩余部分
|
||||
|
||||
@@ -13,7 +13,7 @@ public class CharsetDetectorTest {
|
||||
public void detectTest(){
|
||||
// 测试多个Charset对同一个流的处理是否有问题
|
||||
final Charset detect = CharsetDetector.detect(ResourceUtil.getStream("test.xml"),
|
||||
CharsetUtil.CHARSET_GBK, CharsetUtil.CHARSET_UTF_8);
|
||||
Assert.assertEquals(CharsetUtil.CHARSET_UTF_8, detect);
|
||||
CharsetUtil.GBK, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(CharsetUtil.UTF_8, detect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ public class FileUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void convertLineSeparatorTest() {
|
||||
FileUtil.convertLineSeparator(FileUtil.file("d:/aaa.txt"), CharsetUtil.CHARSET_UTF_8, LineSeparator.WINDOWS);
|
||||
FileUtil.convertLineSeparator(FileUtil.file("d:/aaa.txt"), CharsetUtil.UTF_8, LineSeparator.WINDOWS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -466,7 +466,7 @@ public class FileUtilTest {
|
||||
@Ignore
|
||||
public void appendLinesTest(){
|
||||
List<String> list = ListUtil.toList("a", "b", "c");
|
||||
FileUtil.appendLines(list, FileUtil.file("d:/test/appendLines.txt"), CharsetUtil.CHARSET_UTF_8);
|
||||
FileUtil.appendLines(list, FileUtil.file("d:/test/appendLines.txt"), CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.io.checksum;
|
||||
|
||||
import cn.hutool.core.io.checksum.crc16.CRC16XModem;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class FileSystemUtilTest {
|
||||
@Ignore
|
||||
public void listTest(){
|
||||
final FileSystem fileSystem = FileSystemUtil.createZip("d:/test/test.zip",
|
||||
CharsetUtil.CHARSET_GBK);
|
||||
CharsetUtil.GBK);
|
||||
final Path root = FileSystemUtil.getRoot(fileSystem);
|
||||
PathUtil.walkFiles(root, new SimpleFileVisitor<Path>() {
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TailerTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void tailTest() {
|
||||
FileUtil.tail(FileUtil.file("d:/test/tail.txt"), CharsetUtil.CHARSET_GBK);
|
||||
FileUtil.tail(FileUtil.file("d:/test/tail.txt"), CharsetUtil.GBK);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.io.resource;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateRange;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -4,19 +4,19 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.text.Simhash;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
public class SimhashTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void simTest() {
|
||||
String text1 = "我是 一个 普通 字符串";
|
||||
String text2 = "我是 一个 普通 字符串";
|
||||
|
||||
|
||||
Simhash simhash = new Simhash();
|
||||
long hash = simhash.hash(StrUtil.split(text1, ' '));
|
||||
Assert.assertTrue(hash != 0);
|
||||
|
||||
|
||||
simhash.store(hash);
|
||||
boolean duplicate = simhash.equals(StrUtil.split(text2, ' '));
|
||||
Assert.assertTrue(duplicate);
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.lang.id.Snowflake;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.lang.id.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.lang.hash;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ package cn.hutool.core.lang.hash;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -21,14 +21,14 @@ public class MetroHashTest {
|
||||
|
||||
@Test
|
||||
public void metroHash64Test() {
|
||||
byte[] str = "我是一段测试123".getBytes(CharsetUtil.CHARSET_UTF_8);
|
||||
byte[] str = "我是一段测试123".getBytes(CharsetUtil.UTF_8);
|
||||
final long hash64 = MetroHash.hash64(str);
|
||||
Assert.assertEquals(62920234463891865L, hash64);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metroHash128Test() {
|
||||
byte[] str = "我是一段测试123".getBytes(CharsetUtil.CHARSET_UTF_8);
|
||||
byte[] str = "我是一段测试123".getBytes(CharsetUtil.UTF_8);
|
||||
final long[] hash128 = MetroHash.hash128(str).getLongArray();
|
||||
Assert.assertEquals(4956592424592439349L, hash128[0]);
|
||||
Assert.assertEquals(6301214698325086246L, hash128[1]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.lang.hash;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.lang.reflect;
|
||||
|
||||
import cn.hutool.core.reflect.ActualTypeMapperPool;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package cn.hutool.core.lang.reflect;
|
||||
|
||||
import cn.hutool.core.reflect.MethodHandleUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.util.ClassLoaderUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Opt;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -19,15 +19,15 @@ public class TolerantMapTest {
|
||||
|
||||
@Test
|
||||
public void testSerialize() {
|
||||
byte[] bytes = ObjectUtil.serialize(map);
|
||||
TolerantMap<String, String> serializedMap = ObjectUtil.deserialize(bytes);
|
||||
byte[] bytes = ObjUtil.serialize(map);
|
||||
TolerantMap<String, String> serializedMap = ObjUtil.deserialize(bytes);
|
||||
assert serializedMap != map;
|
||||
assert map.equals(serializedMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClone() {
|
||||
TolerantMap<String, String> clonedMap = ObjectUtil.clone(map);
|
||||
TolerantMap<String, String> clonedMap = ObjUtil.clone(map);
|
||||
assert clonedMap != map;
|
||||
assert map.equals(clonedMap);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.thread.ConcurrencyTester;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -46,7 +46,7 @@ public class WeakConcurrentMapTest {
|
||||
tester.test(()-> cache.computeIfAbsent("aaa" + RandomUtil.randomInt(2), (key)-> "aaaValue"));
|
||||
|
||||
Assert.assertTrue(tester.getInterval() > 0);
|
||||
String value = ObjectUtil.defaultIfNull(cache.get("aaa0"), cache.get("aaa1"));
|
||||
String value = ObjUtil.defaultIfNull(cache.get("aaa0"), cache.get("aaa1"));
|
||||
Assert.assertEquals("aaaValue", value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ public class FormUrlencodedTest {
|
||||
|
||||
@Test
|
||||
public void encodeParamTest(){
|
||||
String encode = FormUrlencoded.ALL.encode("a+b", CharsetUtil.CHARSET_UTF_8);
|
||||
String encode = FormUrlencoded.ALL.encode("a+b", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a%2Bb", encode);
|
||||
|
||||
encode = FormUrlencoded.ALL.encode("a b", CharsetUtil.CHARSET_UTF_8);
|
||||
encode = FormUrlencoded.ALL.encode("a b", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a+b", encode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,22 @@ public class RFC3986Test {
|
||||
|
||||
@Test
|
||||
public void encodeQueryTest(){
|
||||
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=b", CharsetUtil.CHARSET_UTF_8);
|
||||
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=b", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a=b", encode);
|
||||
|
||||
encode = RFC3986.QUERY_PARAM_VALUE.encode("a+1=b", CharsetUtil.CHARSET_UTF_8);
|
||||
encode = RFC3986.QUERY_PARAM_VALUE.encode("a+1=b", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a+1=b", encode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeQueryPercentTest(){
|
||||
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=%b", CharsetUtil.CHARSET_UTF_8);
|
||||
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=%b", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a=%25b", encode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeQueryWithSafeTest(){
|
||||
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=%25", CharsetUtil.CHARSET_UTF_8, '%');
|
||||
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=%25", CharsetUtil.UTF_8, '%');
|
||||
Assert.assertEquals("a=%25", encode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class URLEncoderTest {
|
||||
@Test
|
||||
public void encodeTest() {
|
||||
String body = "366466 - 副本.jpg";
|
||||
String encode = URLEncoder.encodeAll(body);
|
||||
Assert.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode);
|
||||
Assert.assertEquals(body, URLDecoder.decode(encode));
|
||||
|
||||
String encode2 = URLEncoder.encodeQuery(body);
|
||||
Assert.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeQueryPlusTest() {
|
||||
String body = "+";
|
||||
String encode2 = URLEncoder.encodeQuery(body);
|
||||
Assert.assertEquals("+", encode2);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.hutool.core.util;
|
||||
package cn.hutool.core.net;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -75,24 +75,6 @@ public class URLUtilTest {
|
||||
Assert.assertEquals("https://www.hutool.cn", host.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeTest() {
|
||||
String body = "366466 - 副本.jpg";
|
||||
String encode = URLUtil.encode(body);
|
||||
Assert.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode);
|
||||
Assert.assertEquals(body, URLUtil.decode(encode));
|
||||
|
||||
String encode2 = URLUtil.encodeQuery(body);
|
||||
Assert.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeQueryPlusTest() {
|
||||
String body = "+";
|
||||
String encode2 = URLUtil.encodeQuery(body);
|
||||
Assert.assertEquals("+", encode2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPathTest(){
|
||||
String url = " http://www.aaa.bbb/search?scope=ccc&q=ddd";
|
||||
@@ -23,7 +23,7 @@ public class UrlBuilderTest {
|
||||
@Test
|
||||
public void buildTest2() {
|
||||
// path中的+不做处理
|
||||
String buildUrl = UrlBuilder.ofHttp("http://www.hutool.cn/+8618888888888", CharsetUtil.CHARSET_UTF_8).build();
|
||||
String buildUrl = UrlBuilder.ofHttp("http://www.hutool.cn/+8618888888888", CharsetUtil.UTF_8).build();
|
||||
Assert.assertEquals("http://www.hutool.cn/+8618888888888", buildUrl);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class UrlBuilderTest {
|
||||
|
||||
@Test
|
||||
public void ofTest() {
|
||||
final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb/?a=1&b=2#frag1", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb/?a=1&b=2#frag1", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("http", builder.getScheme());
|
||||
Assert.assertEquals("www.hutool.cn", builder.getHost());
|
||||
|
||||
@@ -141,14 +141,14 @@ public class UrlBuilderTest {
|
||||
|
||||
@Test
|
||||
public void ofNullQueryTest() {
|
||||
final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb", CharsetUtil.UTF_8);
|
||||
Assert.assertNotNull(builder.getQuery());
|
||||
Assert.assertNull(builder.getQuery().get("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWithChineseTest() {
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp("www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp("www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("http", builder.getScheme());
|
||||
Assert.assertEquals("www.hutool.cn", builder.getHost());
|
||||
|
||||
@@ -163,7 +163,7 @@ public class UrlBuilderTest {
|
||||
|
||||
@Test
|
||||
public void ofWithBlankTest() {
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("http", builder.getScheme());
|
||||
Assert.assertEquals("www.hutool.cn", builder.getHost());
|
||||
|
||||
@@ -179,7 +179,7 @@ public class UrlBuilderTest {
|
||||
@Test
|
||||
public void ofSpecialTest() {
|
||||
//测试不规范的或者无需解码的字符串是否成功解码
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%%e5%9b%9b#frag1", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("http", builder.getScheme());
|
||||
Assert.assertEquals("www.hutool.cn", builder.getHost());
|
||||
|
||||
@@ -200,7 +200,7 @@ public class UrlBuilderTest {
|
||||
"&idx=1" +
|
||||
"&sn=1044c0d19723f74f04f4c1da34eefa35" +
|
||||
"&chksm=6cbda3a25bca2ab4516410db6ce6e125badaac2f8c5548ea6e18eab6dc3c5422cb8cbe1095f7";
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(urlStr, CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(urlStr, CharsetUtil.UTF_8);
|
||||
// 原URL中的&替换为&
|
||||
Assert.assertEquals("https://mp.weixin.qq.com/s?" +
|
||||
"__biz=MzI5NjkyNTIxMg==" +
|
||||
@@ -215,26 +215,26 @@ public class UrlBuilderTest {
|
||||
// 原URL中以/结尾,则这个规则需保留,issue#I1G44J@Gitee
|
||||
final String today = DateUtil.date().toString("yyyyMMdd");
|
||||
final String getWorkDayUrl = "https://tool.bitefu.net/jiari/?info=1&d=" + today;
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(getWorkDayUrl, CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(getWorkDayUrl, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(getWorkDayUrl, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blankEncodeTest(){
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://a.com/aaa bbb.html", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://a.com/aaa bbb.html", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("http://a.com/aaa%20bbb.html", urlBuilder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dotEncodeTest(){
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://xtbgyy.digitalgd.com.cn/ebus/../../..", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://xtbgyy.digitalgd.com.cn/ebus/../../..", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("http://xtbgyy.digitalgd.com.cn/ebus/../../..", urlBuilder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiSlashTest(){
|
||||
//issue#I25MZL,某些URL中有多个斜杠,此为合法路径
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("https://hutool.cn//file/test.jpg", CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("https://hutool.cn//file/test.jpg", CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("https://hutool.cn//file/test.jpg", urlBuilder.toString());
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ public class UrlBuilderTest {
|
||||
public void encodePathTest(){
|
||||
// Path中的某些符号无需转义,比如=
|
||||
final String urlStr = "http://hq.sinajs.cn/list=sh600519";
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp(urlStr, CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp(urlStr, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(urlStr, urlBuilder.toString());
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ public class UrlBuilderTest {
|
||||
// https://gitee.com/dromara/hutool/issues/I4RA42
|
||||
// Path中`:`在第一个segment需要转义,之后的不需要
|
||||
final String urlStr = "https://hutool.cn/aa/bb/Pre-K,Kindergarten,First,Second,Third,Fourth,Fifth/Page:3";
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp(urlStr, CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp(urlStr, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(urlStr, urlBuilder.toString());
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ public class UrlBuilderTest {
|
||||
// https://github.com/dromara/hutool/issues/2243
|
||||
// 如果用户已经做了%编码,不应该重复编码
|
||||
String url = "https://hutool.cn/v1.0?privateNum=%2B8616512884988";
|
||||
final String s = UrlBuilder.of(url, null).setCharset(CharsetUtil.CHARSET_UTF_8).toString();
|
||||
final String s = UrlBuilder.of(url, null).setCharset(CharsetUtil.UTF_8).toString();
|
||||
Assert.assertEquals(url, s);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ import org.junit.Test;
|
||||
public class UrlDecoderTest {
|
||||
@Test
|
||||
public void decodeForPathTest(){
|
||||
Assert.assertEquals("+", URLDecoder.decodeForPath("+", CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("+", URLDecoder.decodeForPath("+", CharsetUtil.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -54,7 +53,7 @@ public class UrlQueryTest {
|
||||
public void parseTest4(){
|
||||
// https://github.com/dromara/hutool/issues/1989
|
||||
String queryStr = "imageMogr2/thumbnail/x800/format/jpg";
|
||||
final UrlQuery query = UrlQuery.of(queryStr, CharsetUtil.CHARSET_UTF_8);
|
||||
final UrlQuery query = UrlQuery.of(queryStr, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(queryStr, query.toString());
|
||||
}
|
||||
|
||||
@@ -112,22 +111,22 @@ public class UrlQueryTest {
|
||||
@Test
|
||||
public void plusTest(){
|
||||
// 根据RFC3986,在URL中,+是安全字符,即此符号不转义
|
||||
final String a = UrlQuery.of(MapUtil.of("a+b", "1+2")).build(CharsetUtil.CHARSET_UTF_8);
|
||||
final String a = UrlQuery.of(MapUtil.of("a+b", "1+2")).build(CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a+b=1+2", a);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsePlusTest(){
|
||||
// 根据RFC3986,在URL中,+是安全字符,即此符号不转义
|
||||
final String a = UrlQuery.of("a+b=1+2", CharsetUtil.CHARSET_UTF_8)
|
||||
.build(CharsetUtil.CHARSET_UTF_8);
|
||||
final String a = UrlQuery.of("a+b=1+2", CharsetUtil.UTF_8)
|
||||
.build(CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a+b=1+2", a);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spaceTest(){
|
||||
// 根据RFC3986,在URL中,空格编码为"%20"
|
||||
final String a = UrlQuery.of(MapUtil.of("a ", " ")).build(CharsetUtil.CHARSET_UTF_8);
|
||||
final String a = UrlQuery.of(MapUtil.of("a ", " ")).build(CharsetUtil.UTF_8);
|
||||
Assert.assertEquals("a%20=%20", a);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,10 +92,10 @@ public class CharSequenceUtilTest {
|
||||
String s = "华硕K42Intel酷睿i31代2G以下独立显卡不含机械硬盘固态硬盘120GB-192GB4GB-6GB";
|
||||
|
||||
String v = CharSequenceUtil.subPreGbk(s, 40, false);
|
||||
Assert.assertEquals(39, v.getBytes(CharsetUtil.CHARSET_GBK).length);
|
||||
Assert.assertEquals(39, v.getBytes(CharsetUtil.GBK).length);
|
||||
|
||||
v = CharSequenceUtil.subPreGbk(s, 40, true);
|
||||
Assert.assertEquals(41, v.getBytes(CharsetUtil.CHARSET_GBK).length);
|
||||
Assert.assertEquals(41, v.getBytes(CharsetUtil.GBK).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -9,12 +9,12 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* {@link ClassUtil} 单元测试
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class ClassUtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void getClassNameTest() {
|
||||
String className = ClassUtil.getClassName(ClassUtil.class, false);
|
||||
@@ -39,7 +39,7 @@ public class ClassUtilTest {
|
||||
@SuppressWarnings({"unused", "InnerClassMayBeStatic"})
|
||||
class TestSubClass extends TestClass {
|
||||
private String subField;
|
||||
|
||||
|
||||
private void privateSubMethod() {
|
||||
}
|
||||
|
||||
@@ -90,16 +90,16 @@ public class ClassUtilTest {
|
||||
Field subField = ClassUtil.getDeclaredField(TestSubClass.class, "subField");
|
||||
Assert.assertNotNull(subField);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getClassPathTest() {
|
||||
String classPath = ClassUtil.getClassPath();
|
||||
Assert.assertNotNull(classPath);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getShortClassNameTest() {
|
||||
String className = "cn.hutool.core.util.StrUtil";
|
||||
String className = "cn.hutool.core.text.StrUtil";
|
||||
String result = ClassUtil.getShortClassName(className);
|
||||
Assert.assertEquals("c.h.c.u.StrUtil", result);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.text.DesensitizedUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.lang.hash.HashUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class HexUtilTest {
|
||||
public void hexStrTest(){
|
||||
String str = "我是一个字符串";
|
||||
|
||||
String hex = HexUtil.encodeHexStr(str, CharsetUtil.CHARSET_UTF_8);
|
||||
String hex = HexUtil.encodeHexStr(str, CharsetUtil.UTF_8);
|
||||
String decodedStr = HexUtil.decodeHexStr(hex);
|
||||
|
||||
Assert.assertEquals(str, decodedStr);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.reflect.ModifierUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -18,20 +18,20 @@ public class ObjectUtilTest {
|
||||
public void equalsTest(){
|
||||
Object a = null;
|
||||
Object b = null;
|
||||
Assert.assertTrue(ObjectUtil.equals(a, b));
|
||||
Assert.assertTrue(ObjUtil.equals(a, b));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lengthTest(){
|
||||
int[] array = new int[]{1,2,3,4,5};
|
||||
int length = ObjectUtil.length(array);
|
||||
int length = ObjUtil.length(array);
|
||||
Assert.assertEquals(5, length);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("a", "a1");
|
||||
map.put("b", "b1");
|
||||
map.put("c", "c1");
|
||||
length = ObjectUtil.length(map);
|
||||
length = ObjUtil.length(map);
|
||||
Assert.assertEquals(3, length);
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ public class ObjectUtilTest {
|
||||
public void containsTest(){
|
||||
int[] array = new int[]{1,2,3,4,5};
|
||||
|
||||
final boolean contains = ObjectUtil.contains(array, 1);
|
||||
final boolean contains = ObjUtil.contains(array, 1);
|
||||
Assert.assertTrue(contains);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloneTest() {
|
||||
Obj obj = new Obj();
|
||||
Obj obj2 = ObjectUtil.clone(obj);
|
||||
Obj obj2 = ObjUtil.clone(obj);
|
||||
Assert.assertEquals("OK", obj2.doSomeThing());
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ObjectUtilTest {
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
ArrayList<String> strings = CollUtil.newArrayList("1", "2");
|
||||
String result = ObjectUtil.toString(strings);
|
||||
String result = ObjUtil.toString(strings);
|
||||
Assert.assertEquals("[1, 2]", result);
|
||||
}
|
||||
|
||||
@@ -67,10 +67,10 @@ public class ObjectUtilTest {
|
||||
public void defaultIfNullTest() {
|
||||
final String nullValue = null;
|
||||
final String dateStr = "2020-10-23 15:12:30";
|
||||
Instant result1 = ObjectUtil.defaultIfNull(dateStr,
|
||||
Instant result1 = ObjUtil.defaultIfNull(dateStr,
|
||||
() -> DateUtil.parse(dateStr, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant.now());
|
||||
Assert.assertNotNull(result1);
|
||||
Instant result2 = ObjectUtil.defaultIfNull(nullValue,
|
||||
Instant result2 = ObjUtil.defaultIfNull(nullValue,
|
||||
() -> DateUtil.parse(nullValue, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant.now());
|
||||
Assert.assertNotNull(result2);
|
||||
}
|
||||
@@ -79,10 +79,10 @@ public class ObjectUtilTest {
|
||||
public void defaultIfEmptyTest() {
|
||||
final String emptyValue = "";
|
||||
final String dateStr = "2020-10-23 15:12:30";
|
||||
Instant result1 = ObjectUtil.defaultIfEmpty(emptyValue,
|
||||
Instant result1 = ObjUtil.defaultIfEmpty(emptyValue,
|
||||
() -> DateUtil.parse(emptyValue, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant.now());
|
||||
Assert.assertNotNull(result1);
|
||||
Instant result2 = ObjectUtil.defaultIfEmpty(dateStr,
|
||||
Instant result2 = ObjUtil.defaultIfEmpty(dateStr,
|
||||
() -> DateUtil.parse(dateStr, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant.now());
|
||||
Assert.assertNotNull(result2);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class ObjectUtilTest {
|
||||
@Test
|
||||
public void isBasicTypeTest(){
|
||||
int a = 1;
|
||||
final boolean basicType = ObjectUtil.isBasicType(a);
|
||||
final boolean basicType = ObjUtil.isBasicType(a);
|
||||
Assert.assertTrue(basicType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.regex.PatternPool;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.date.Week;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.lang.test.bean.ExamInfoDict;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ClassUtilTest.TestSubClass;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.map.Dict;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -10,32 +11,32 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TypeUtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void getEleTypeTest() {
|
||||
Method method = ReflectUtil.getMethod(TestClass.class, "getList");
|
||||
Type type = TypeUtil.getReturnType(method);
|
||||
Assert.assertEquals("java.util.List<java.lang.String>", type.toString());
|
||||
|
||||
|
||||
Type type2 = TypeUtil.getTypeArgument(type);
|
||||
Assert.assertEquals(String.class, type2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getParamTypeTest() {
|
||||
Method method = ReflectUtil.getMethod(TestClass.class, "intTest", Integer.class);
|
||||
Type type = TypeUtil.getParamType(method, 0);
|
||||
Assert.assertEquals(Integer.class, type);
|
||||
|
||||
|
||||
Type returnType = TypeUtil.getReturnType(method);
|
||||
Assert.assertEquals(Integer.class, returnType);
|
||||
}
|
||||
|
||||
|
||||
public static class TestClass {
|
||||
public List<String> getList(){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
public Integer intTest(Integer integer) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.compress.ZipReader;
|
||||
import cn.hutool.core.compress.ZipUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -67,7 +69,7 @@ public class ZipUtilTest {
|
||||
*/
|
||||
private List<String> zipEntryNames(File zipFile) {
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
ZipReader reader = ZipReader.of(zipFile, CharsetUtil.CHARSET_UTF_8);
|
||||
ZipReader reader = ZipReader.of(zipFile, CharsetUtil.UTF_8);
|
||||
reader.read(zipEntry -> fileNames.add(zipEntry.getName()));
|
||||
reader.close();
|
||||
return fileNames;
|
||||
@@ -89,14 +91,14 @@ public class ZipUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void unzipTest2() {
|
||||
File unzip = ZipUtil.unzip("f:/test/各种资源.zip", "f:/test/各种资源", CharsetUtil.CHARSET_GBK);
|
||||
File unzip = ZipUtil.unzip("f:/test/各种资源.zip", "f:/test/各种资源", CharsetUtil.GBK);
|
||||
Console.log(unzip);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void unzipFromStreamTest() {
|
||||
File unzip = ZipUtil.unzip(FileUtil.getInputStream("e:/test/hutool-core-5.1.0.jar"), FileUtil.file("e:/test/"), CharsetUtil.CHARSET_UTF_8);
|
||||
File unzip = ZipUtil.unzip(FileUtil.getInputStream("e:/test/hutool-core-5.1.0.jar"), FileUtil.file("e:/test/"), CharsetUtil.UTF_8);
|
||||
Console.log(unzip);
|
||||
}
|
||||
|
||||
@@ -109,7 +111,7 @@ public class ZipUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void unzipFileBytesTest() {
|
||||
byte[] fileBytes = ZipUtil.unzipFileBytes(FileUtil.file("e:/02 电力相关设备及服务2-241-.zip"), CharsetUtil.CHARSET_GBK, "images/CE-EP-HY-MH01-ES-0001.jpg");
|
||||
byte[] fileBytes = ZipUtil.unzipFileBytes(FileUtil.file("e:/02 电力相关设备及服务2-241-.zip"), CharsetUtil.GBK, "images/CE-EP-HY-MH01-ES-0001.jpg");
|
||||
Assert.assertNotNull(fileBytes);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user