mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
Merge remote-tracking branch 'origin/v6-dev' into v6-dev
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
package cn.hutool.core.bean;
|
||||
|
||||
import cn.hutool.core.lang.test.bean.ExamInfoDict;
|
||||
import cn.hutool.core.lang.test.bean.UserInfoDict;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.lang.test.bean.ExamInfoDict;
|
||||
import cn.hutool.core.lang.test.bean.UserInfoDict;
|
||||
|
||||
/**
|
||||
* {@link BeanPath} 单元测试
|
||||
*
|
||||
@@ -87,14 +86,14 @@ public class BeanPathTest {
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
final BeanPath pattern = BeanPath.create("userInfo.examInfoDict[0].id");
|
||||
final BeanPath pattern = BeanPath.of("userInfo.examInfoDict[0].id");
|
||||
final Object result = pattern.get(tempMap);
|
||||
Assert.assertEquals(1, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTest() {
|
||||
final BeanPath pattern = BeanPath.create("userInfo.examInfoDict[0].id");
|
||||
final BeanPath pattern = BeanPath.of("userInfo.examInfoDict[0].id");
|
||||
pattern.set(tempMap, 2);
|
||||
final Object result = pattern.get(tempMap);
|
||||
Assert.assertEquals(2, result);
|
||||
@@ -102,9 +101,28 @@ public class BeanPathTest {
|
||||
|
||||
@Test
|
||||
public void getMapTest () {
|
||||
final BeanPath pattern = BeanPath.create("userInfo[id, photoPath]");
|
||||
@SuppressWarnings("unchecked") final Map<String, Object> result = (Map<String, Object>)pattern.get(tempMap);
|
||||
final BeanPath pattern = BeanPath.of("userInfo[id, photoPath]");
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, Object> result = (Map<String, Object>)pattern.get(tempMap);
|
||||
Assert.assertEquals(1, result.get("id"));
|
||||
Assert.assertEquals("yx.mm.com", result.get("photoPath"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKeyWithDotTest () {
|
||||
Map<String, Object> dataMap = new HashMap<>(16);
|
||||
dataMap.put("aa", "value0");
|
||||
dataMap.put("aa.bb.cc", "value111111");// key 是类名 格式 带 ' . '
|
||||
|
||||
final BeanPath pattern = BeanPath.of("'aa.bb.cc'");
|
||||
Assert.assertEquals("value111111", pattern.get(dataMap));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileTest(){
|
||||
final BeanPath of = BeanPath.of("'abc.dd'.ee.ff'.'");
|
||||
Assert.assertEquals("abc.dd", of.getPatternParts().get(0));
|
||||
Assert.assertEquals("ee", of.getPatternParts().get(1));
|
||||
Assert.assertEquals("ff.", of.getPatternParts().get(2));
|
||||
}
|
||||
}
|
||||
|
@@ -3,14 +3,14 @@ package cn.hutool.core.bean;
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.bean.copier.ValueProvider;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -116,7 +116,7 @@ public class BeanUtilTest {
|
||||
// 错误的类型,此处忽略
|
||||
map.put("age", "aaaaaa");
|
||||
|
||||
final Person person = BeanUtil.toBeanIgnoreError(map, Person.class);
|
||||
final Person person = BeanUtil.toBean(map, Person.class, CopyOptions.create().setIgnoreError(true));
|
||||
Assert.assertEquals("Joe", person.getName());
|
||||
// 错误的类型,不copy这个字段,使用对象创建的默认值
|
||||
Assert.assertEquals(0, person.getAge());
|
||||
@@ -128,7 +128,7 @@ public class BeanUtilTest {
|
||||
map.put("Name", "Joe");
|
||||
map.put("aGe", 12);
|
||||
|
||||
final Person person = BeanUtil.toBeanIgnoreCase(map, Person.class, false);
|
||||
final Person person = BeanUtil.toBean(map, Person.class, CopyOptions.create().setIgnoreCase(true));
|
||||
Assert.assertEquals("Joe", person.getName());
|
||||
Assert.assertEquals(12, person.getAge());
|
||||
}
|
||||
@@ -191,6 +191,23 @@ public class BeanUtilTest {
|
||||
Assert.assertFalse(map.containsKey("SUBNAME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanToMapNullPropertiesTest() {
|
||||
final SubPerson person = new SubPerson();
|
||||
person.setAge(14);
|
||||
person.setOpenid("11213232");
|
||||
person.setName("测试A11");
|
||||
person.setSubName("sub名字");
|
||||
|
||||
final Map<String, Object> map = BeanUtil.beanToMap(person, (String[])null);
|
||||
|
||||
Assert.assertEquals("测试A11", map.get("name"));
|
||||
Assert.assertEquals(14, map.get("age"));
|
||||
Assert.assertEquals("11213232", map.get("openid"));
|
||||
// static属性应被忽略
|
||||
Assert.assertFalse(map.containsKey("SUBNAME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanToMapTest2() {
|
||||
final SubPerson person = new SubPerson();
|
||||
@@ -285,7 +302,7 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void getPropertyDescriptorsTest() {
|
||||
final HashSet<Object> set = CollUtil.newHashSet();
|
||||
final HashSet<Object> set = SetUtil.of();
|
||||
final PropertyDescriptor[] propertyDescriptors = BeanUtil.getPropertyDescriptors(SubPerson.class);
|
||||
for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
set.add(propertyDescriptor.getName());
|
||||
@@ -326,7 +343,7 @@ public class BeanUtilTest {
|
||||
student.setAge(125);
|
||||
student.setNo(8848L);
|
||||
|
||||
final List<Student> studentList = ListUtil.of(student, student2);
|
||||
final List<Student> studentList = ListUtil.view(student, student2);
|
||||
|
||||
for (int i=0;i<5000;i++){
|
||||
new Thread(()->{
|
||||
@@ -550,6 +567,11 @@ public class BeanUtilTest {
|
||||
Assert.assertNull(newFood.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyNullTest() {
|
||||
Assert.assertNull(BeanUtil.copyProperties(null, Food.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyBeanPropertiesFilterTest() {
|
||||
final Food info = new Food();
|
||||
@@ -633,7 +655,7 @@ public class BeanUtilTest {
|
||||
student.setAge(125);
|
||||
student.setNo(8848L);
|
||||
|
||||
final List<Student> studentList = ListUtil.of(student, student2);
|
||||
final List<Student> studentList = ListUtil.view(student, student2);
|
||||
final List<Person> people = BeanUtil.copyToList(studentList, Person.class);
|
||||
|
||||
Assert.assertEquals(studentList.size(), people.size());
|
||||
@@ -687,7 +709,7 @@ public class BeanUtilTest {
|
||||
|
||||
testPojo.setTestPojo2List(new TestPojo2[]{testPojo2, testPojo3});
|
||||
|
||||
final BeanPath beanPath = BeanPath.create("testPojo2List.age");
|
||||
final BeanPath beanPath = BeanPath.of("testPojo2List.age");
|
||||
final Object o = beanPath.get(testPojo);
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(2), ArrayUtil.get(o, 0));
|
||||
@@ -759,7 +781,7 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void issueI41WKPTest(){
|
||||
final Test1 t1 = new Test1().setStrList(ListUtil.toList("list"));
|
||||
final Test1 t1 = new Test1().setStrList(ListUtil.of("list"));
|
||||
final Test2 t2_hu = new Test2();
|
||||
BeanUtil.copyProperties(t1, t2_hu, CopyOptions.create().setIgnoreError(true));
|
||||
Assert.assertNull(t2_hu.getStrList());
|
||||
|
@@ -35,22 +35,22 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void testPredicateContains() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("bbbbb", "aaaaa", "ccccc");
|
||||
final ArrayList<String> list = ListUtil.of("bbbbb", "aaaaa", "ccccc");
|
||||
Assert.assertTrue(CollUtil.contains(list, s -> s.startsWith("a")));
|
||||
Assert.assertFalse(CollUtil.contains(list, s -> s.startsWith("d")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveWithAddIf() {
|
||||
ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3);
|
||||
final ArrayList<Integer> exceptRemovedList = CollUtil.newArrayList(2, 3);
|
||||
final ArrayList<Integer> exceptResultList = CollUtil.newArrayList(1);
|
||||
ArrayList<Integer> list = ListUtil.of(1, 2, 3);
|
||||
final ArrayList<Integer> exceptRemovedList = ListUtil.of(2, 3);
|
||||
final ArrayList<Integer> exceptResultList = ListUtil.of(1);
|
||||
|
||||
List<Integer> resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele);
|
||||
Assert.assertEquals(list, exceptRemovedList);
|
||||
Assert.assertEquals(resultList, exceptResultList);
|
||||
|
||||
list = CollUtil.newArrayList(1, 2, 3);
|
||||
list = ListUtil.of(1, 2, 3);
|
||||
resultList = new ArrayList<>();
|
||||
CollUtil.removeWithAddIf(list, resultList, ele -> 1 == ele);
|
||||
Assert.assertEquals(list, exceptRemovedList);
|
||||
@@ -59,27 +59,27 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void testPadLeft() {
|
||||
List<String> srcList = CollUtil.newArrayList();
|
||||
List<String> answerList = CollUtil.newArrayList("a", "b");
|
||||
List<String> srcList = ListUtil.of();
|
||||
List<String> answerList = ListUtil.of("a", "b");
|
||||
CollUtil.padLeft(srcList, 1, "b");
|
||||
CollUtil.padLeft(srcList, 2, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
|
||||
srcList = CollUtil.newArrayList("a", "b");
|
||||
answerList = CollUtil.newArrayList("a", "b");
|
||||
srcList = ListUtil.of("a", "b");
|
||||
answerList = ListUtil.of("a", "b");
|
||||
CollUtil.padLeft(srcList, 2, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
|
||||
srcList = CollUtil.newArrayList("c");
|
||||
answerList = CollUtil.newArrayList("a", "a", "c");
|
||||
srcList = ListUtil.of("c");
|
||||
answerList = ListUtil.of("a", "a", "c");
|
||||
CollUtil.padLeft(srcList, 3, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPadRight() {
|
||||
final List<String> srcList = CollUtil.newArrayList("a");
|
||||
final List<String> answerList = CollUtil.newArrayList("a", "b", "b", "b", "b");
|
||||
final List<String> srcList = ListUtil.of("a");
|
||||
final List<String> answerList = ListUtil.of("a", "b", "b", "b", "b");
|
||||
CollUtil.padRight(srcList, 5, "b");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void newHashSetTest() {
|
||||
final Set<String> set = CollUtil.newHashSet((String[]) null);
|
||||
final Set<String> set = SetUtil.of((String[]) null);
|
||||
Assert.assertNotNull(set);
|
||||
}
|
||||
|
||||
@@ -114,8 +114,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void unionTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("a", "b", "b", "b", "c", "d");
|
||||
|
||||
final Collection<String> union = CollUtil.union(list1, list2);
|
||||
|
||||
@@ -124,8 +124,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void intersectionTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("a", "b", "b", "b", "c", "d");
|
||||
|
||||
final Collection<String> intersection = CollUtil.intersection(list1, list2);
|
||||
Assert.assertEquals(2, CollUtil.count(intersection, "b"::equals));
|
||||
@@ -133,12 +133,12 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void intersectionDistinctTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list3 = CollUtil.newArrayList();
|
||||
final ArrayList<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list3 = ListUtil.of();
|
||||
|
||||
final Collection<String> intersectionDistinct = CollUtil.intersectionDistinct(list1, list2);
|
||||
Assert.assertEquals(CollUtil.newLinkedHashSet("a", "b", "c", "d"), intersectionDistinct);
|
||||
Assert.assertEquals(SetUtil.ofLinked("a", "b", "c", "d"), intersectionDistinct);
|
||||
|
||||
final Collection<String> intersectionDistinct2 = CollUtil.intersectionDistinct(list1, list2, list3);
|
||||
Assert.assertTrue(intersectionDistinct2.isEmpty());
|
||||
@@ -146,8 +146,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void disjunctionTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final ArrayList<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("a", "b", "b", "b", "c", "d", "x2");
|
||||
|
||||
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
|
||||
Assert.assertTrue(disjunction.contains("b"));
|
||||
@@ -163,8 +163,8 @@ public class CollUtilTest {
|
||||
@Test
|
||||
public void disjunctionTest2() {
|
||||
// 任意一个集合为空,差集为另一个集合
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList();
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final ArrayList<String> list1 = ListUtil.of();
|
||||
final ArrayList<String> list2 = ListUtil.of("a", "b", "b", "b", "c", "d", "x2");
|
||||
|
||||
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
|
||||
Assert.assertEquals(list2, disjunction);
|
||||
@@ -175,8 +175,8 @@ public class CollUtilTest {
|
||||
@Test
|
||||
public void disjunctionTest3() {
|
||||
// 无交集下返回共同的元素
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("1", "2", "3");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list1 = ListUtil.of("1", "2", "3");
|
||||
final ArrayList<String> list2 = ListUtil.of("a", "b", "c");
|
||||
|
||||
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
|
||||
Assert.assertTrue(disjunction.contains("1"));
|
||||
@@ -196,8 +196,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void subtractTest() {
|
||||
final List<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final List<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final List<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final List<String> list2 = ListUtil.of("a", "b", "b", "b", "c", "d", "x2");
|
||||
final Collection<String> subtract = CollUtil.subtract(list1, list2);
|
||||
Assert.assertEquals(1, subtract.size());
|
||||
Assert.assertEquals("x", subtract.iterator().next());
|
||||
@@ -236,7 +236,7 @@ public class CollUtilTest {
|
||||
map2.put("c", "值3");
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
final ArrayList<HashMap<String, String>> list = CollUtil.newArrayList(map1, map2);
|
||||
final ArrayList<HashMap<String, String>> list = ListUtil.of(map1, map2);
|
||||
final Map<String, List<String>> map = CollUtil.toListMap(list);
|
||||
Assert.assertEquals("值1", map.get("a").get(0));
|
||||
Assert.assertEquals("值2", map.get("a").get(1));
|
||||
@@ -251,7 +251,7 @@ public class CollUtilTest {
|
||||
public void getFieldValuesTest() {
|
||||
final Dict v1 = Dict.create().set("id", 12).set("name", "张三").set("age", 23);
|
||||
final Dict v2 = Dict.create().set("age", 13).set("id", 15).set("name", "李四");
|
||||
final ArrayList<Dict> list = CollUtil.newArrayList(v1, v2);
|
||||
final ArrayList<Dict> list = ListUtil.of(v1, v2);
|
||||
|
||||
final List<Object> fieldValues = CollUtil.getFieldValues(list, "name");
|
||||
Assert.assertEquals("张三", fieldValues.get(0));
|
||||
@@ -260,7 +260,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void splitTest() {
|
||||
final ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final ArrayList<Integer> list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<List<Integer>> split = CollUtil.split(list, 3);
|
||||
Assert.assertEquals(3, split.size());
|
||||
Assert.assertEquals(3, split.get(0).size());
|
||||
@@ -285,35 +285,35 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void filterTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c");
|
||||
|
||||
final Collection<String> filtered = CollUtil.edit(list, t -> t + 1);
|
||||
|
||||
Assert.assertEquals(CollUtil.newArrayList("a1", "b1", "c1"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a1", "b1", "c1"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest2() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.filter(list, t -> false == "a".equals(t));
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterSetTest() {
|
||||
final Set<String> set = CollUtil.newLinkedHashSet("a", "b", "", " ", "c");
|
||||
final Set<String> set = SetUtil.ofLinked("a", "b", "", " ", "c");
|
||||
final Set<String> filtered = CollUtil.filter(set, StrUtil::isNotBlank);
|
||||
|
||||
Assert.assertEquals(CollUtil.newLinkedHashSet("a", "b", "c"), filtered);
|
||||
Assert.assertEquals(SetUtil.ofLinked("a", "b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterRemoveTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c");
|
||||
|
||||
final List<String> removed = new ArrayList<>();
|
||||
final ArrayList<String> filtered = CollUtil.filter(list, t -> {
|
||||
@@ -329,45 +329,45 @@ public class CollUtilTest {
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeNullTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeNull(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", "", " "), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a", "b", "c", "", " "), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeEmptyTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeEmpty(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", " "), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a", "b", "c", " "), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeBlankTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeBlank(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a", "b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupTest() {
|
||||
final List<String> list = CollUtil.newArrayList("1", "2", "3", "4", "5", "6");
|
||||
final List<String> list = ListUtil.of("1", "2", "3", "4", "5", "6");
|
||||
final List<List<String>> group = CollUtil.group(list, null);
|
||||
Assert.assertTrue(group.size() > 0);
|
||||
|
||||
@@ -375,13 +375,13 @@ public class CollUtilTest {
|
||||
// 按照奇数偶数分类
|
||||
return Integer.parseInt(t) % 2;
|
||||
});
|
||||
Assert.assertEquals(CollUtil.newArrayList("2", "4", "6"), group2.get(0));
|
||||
Assert.assertEquals(CollUtil.newArrayList("1", "3", "5"), group2.get(1));
|
||||
Assert.assertEquals(ListUtil.of("2", "4", "6"), group2.get(0));
|
||||
Assert.assertEquals(ListUtil.of("1", "3", "5"), group2.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupByFieldTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
|
||||
final List<TestBean> list = ListUtil.of(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
|
||||
final List<List<TestBean>> groupByField = CollUtil.groupByField(list, "age");
|
||||
Assert.assertEquals("张三", groupByField.get(0).get(0).getName());
|
||||
Assert.assertEquals("王五", groupByField.get(0).get(1).getName());
|
||||
@@ -391,7 +391,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortByPropertyTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(
|
||||
final List<TestBean> list = ListUtil.of(
|
||||
new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 12, DateUtil.parse("2018-04-01"))//
|
||||
@@ -405,7 +405,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortByPropertyTest2() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(
|
||||
final List<TestBean> list = ListUtil.of(
|
||||
new TestBean("张三", 0, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", -12, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 23, DateUtil.parse("2018-04-01"))//
|
||||
@@ -419,7 +419,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void fieldValueMapTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
final List<TestBean> list = ListUtil.of(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 12, DateUtil.parse("2018-04-01"))//
|
||||
);
|
||||
@@ -432,7 +432,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void fieldValueAsMapTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
final List<TestBean> list = ListUtil.of(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 14, DateUtil.parse("2018-04-01"))//
|
||||
);
|
||||
@@ -470,8 +470,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void listTest() {
|
||||
final List<Object> list1 = CollUtil.list(false);
|
||||
final List<Object> list2 = CollUtil.list(true);
|
||||
final List<Object> list1 = ListUtil.of(false);
|
||||
final List<Object> list2 = ListUtil.of(true);
|
||||
|
||||
Assert.assertTrue(list1 instanceof ArrayList);
|
||||
Assert.assertTrue(list2 instanceof LinkedList);
|
||||
@@ -479,8 +479,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void listTest2() {
|
||||
final List<String> list1 = CollUtil.list(false, "a", "b", "c");
|
||||
final List<String> list2 = CollUtil.list(true, "a", "b", "c");
|
||||
final List<String> list1 = ListUtil.of( "a", "b", "c");
|
||||
final List<String> list2 = ListUtil.ofLinked( "a", "b", "c");
|
||||
Assert.assertEquals("[a, b, c]", list1.toString());
|
||||
Assert.assertEquals("[a, b, c]", list2.toString());
|
||||
}
|
||||
@@ -492,15 +492,15 @@ public class CollUtilTest {
|
||||
set.add("b");
|
||||
set.add("c");
|
||||
|
||||
final List<String> list1 = CollUtil.list(false, set);
|
||||
final List<String> list2 = CollUtil.list(true, set);
|
||||
final List<String> list1 = ListUtil.of(false, set);
|
||||
final List<String> list2 = ListUtil.of(true, set);
|
||||
Assert.assertEquals("[a, b, c]", list1.toString());
|
||||
Assert.assertEquals("[a, b, c]", list2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
final HashSet<String> set = CollUtil.set(true, "A", "B", "C", "D");
|
||||
final HashSet<String> set = SetUtil.ofLinked("A", "B", "C", "D");
|
||||
String str = CollUtil.get(set, 2);
|
||||
Assert.assertEquals("C", str);
|
||||
|
||||
@@ -701,43 +701,43 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortPageAllTest() {
|
||||
final List<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<Integer> list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<Integer> sortPageAll = CollUtil.sortPageAll(1, 5, Comparator.reverseOrder(), list);
|
||||
|
||||
Assert.assertEquals(CollUtil.newArrayList(4, 3, 2, 1), sortPageAll);
|
||||
Assert.assertEquals(ListUtil.of(4, 3, 2, 1), sortPageAll);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAnyTest() {
|
||||
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = CollUtil.newArrayList(5, 3, 1, 9, 11);
|
||||
final ArrayList<Integer> list1 = ListUtil.of(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.of(5, 3, 1, 9, 11);
|
||||
|
||||
Assert.assertTrue(CollUtil.containsAny(list1, list2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAllTest() {
|
||||
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = CollUtil.newArrayList(5, 3, 1);
|
||||
final ArrayList<Integer> list1 = ListUtil.of(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.of(5, 3, 1);
|
||||
Assert.assertTrue(CollUtil.containsAll(list1, list2));
|
||||
|
||||
final ArrayList<Integer> list3 = CollUtil.newArrayList(1);
|
||||
final ArrayList<Integer> list4 = CollUtil.newArrayList();
|
||||
final ArrayList<Integer> list3 = ListUtil.of(1);
|
||||
final ArrayList<Integer> list4 = ListUtil.of();
|
||||
Assert.assertTrue(CollUtil.containsAll(list3, list4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLastTest() {
|
||||
// 测试:空数组返回null而不是报错
|
||||
final List<String> test = CollUtil.newArrayList();
|
||||
final List<String> test = ListUtil.of();
|
||||
final String last = CollUtil.getLast(test);
|
||||
Assert.assertNull(last);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zipTest() {
|
||||
final Collection<String> keys = CollUtil.newArrayList("a", "b", "c", "d");
|
||||
final Collection<Integer> values = CollUtil.newArrayList(1, 2, 3, 4);
|
||||
final Collection<String> keys = ListUtil.of("a", "b", "c", "d");
|
||||
final Collection<Integer> values = ListUtil.of(1, 2, 3, 4);
|
||||
|
||||
final Map<String, Integer> map = CollUtil.zip(keys, values);
|
||||
|
||||
@@ -751,7 +751,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void toMapTest() {
|
||||
final Collection<String> keys = CollUtil.newArrayList("a", "b", "c", "d");
|
||||
final Collection<String> keys = ListUtil.of("a", "b", "c", "d");
|
||||
final Map<String, String> map = CollUtil.toMap(keys, new HashMap<>(), (value) -> "key" + value);
|
||||
Assert.assertEquals("a", map.get("keya"));
|
||||
Assert.assertEquals("b", map.get("keyb"));
|
||||
@@ -778,7 +778,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void countMapTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", "c", "a", "b", "d");
|
||||
final Map<String, Integer> countMap = CollUtil.countMap(list);
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(2), countMap.get("a"));
|
||||
@@ -789,7 +789,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void indexOfTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", "c", "a", "b", "d");
|
||||
final int i = CollUtil.indexOf(list, (str) -> str.charAt(0) == 'c');
|
||||
Assert.assertEquals(2, i);
|
||||
}
|
||||
@@ -797,14 +797,14 @@ public class CollUtilTest {
|
||||
@Test
|
||||
public void lastIndexOfTest() {
|
||||
// List有优化
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", "c", "a", "b", "d");
|
||||
final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'c');
|
||||
Assert.assertEquals(3, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastIndexOfSetTest() {
|
||||
final Set<String> list = CollUtil.set(true, "a", "b", "c", "c", "a", "b", "d");
|
||||
final Set<String> list = SetUtil.ofLinked("a", "b", "c", "c", "a", "b", "d");
|
||||
// 去重后c排第三
|
||||
final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'c');
|
||||
Assert.assertEquals(2, i);
|
||||
@@ -812,7 +812,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void pageTest() {
|
||||
final List<Dict> objects = CollUtil.newArrayList();
|
||||
final List<Dict> objects = ListUtil.of();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
objects.add(Dict.create().set("name", "姓名:" + i));
|
||||
}
|
||||
@@ -832,7 +832,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortComparableTest() {
|
||||
final List<String> of = ListUtil.toList("a", "c", "b");
|
||||
final List<String> of = ListUtil.of("a", "c", "b");
|
||||
final List<String> sort = CollUtil.sort(of, new ComparableComparator<>());
|
||||
Assert.assertEquals("a,b,c", CollUtil.join(sort, ","));
|
||||
}
|
||||
@@ -880,8 +880,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void distinctTest(){
|
||||
final ArrayList<Integer> distinct = CollUtil.distinct(ListUtil.of(5, 3, 10, 9, 0, 5, 10, 9));
|
||||
Assert.assertEquals(ListUtil.of(5, 3, 10, 9, 0), distinct);
|
||||
final ArrayList<Integer> distinct = CollUtil.distinct(ListUtil.view(5, 3, 10, 9, 0, 5, 10, 9));
|
||||
Assert.assertEquals(ListUtil.view(5, 3, 10, 9, 0), distinct);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -17,20 +17,20 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link IterUtil} 单元测试
|
||||
* @author looly
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void getFirstNonNullTest(){
|
||||
final ArrayList<String> strings = CollUtil.newArrayList(null, null, "123", "456", null);
|
||||
public void getFirstNonNullTest() {
|
||||
final ArrayList<String> strings = ListUtil.of(null, null, "123", "456", null);
|
||||
Assert.assertEquals("123", IterUtil.getFirstNoneNull(strings));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldValueMapTest() {
|
||||
final ArrayList<Car> carList = CollUtil.newArrayList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
|
||||
final ArrayList<Car> carList = ListUtil.of(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
|
||||
final Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList.iterator(), "carNumber");
|
||||
|
||||
Assert.assertEquals("大众", carNameMap.get("123").getCarName());
|
||||
@@ -40,30 +40,30 @@ public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void joinTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
|
||||
final ArrayList<String> list = ListUtil.of("1", "2", "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":");
|
||||
Assert.assertEquals("1:2:3:4", join);
|
||||
|
||||
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4);
|
||||
final ArrayList<Integer> list1 = ListUtil.of(1, 2, 3, 4);
|
||||
final String join1 = IterUtil.join(list1.iterator(), ":");
|
||||
Assert.assertEquals("1:2:3:4", join1);
|
||||
|
||||
// 包装每个节点
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("1", "2", "3", "4");
|
||||
final ArrayList<String> list2 = ListUtil.of("1", "2", "3", "4");
|
||||
final String join2 = IterUtil.join(list2.iterator(), ":", "\"", "\"");
|
||||
Assert.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinWithFuncTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
|
||||
final ArrayList<String> list = ListUtil.of("1", "2", "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
|
||||
Assert.assertEquals("1:2:3:4", join);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinWithNullTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("1", null, "3", "4");
|
||||
final ArrayList<String> list = ListUtil.of("1", null, "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
|
||||
Assert.assertEquals("1:null:3:4", join);
|
||||
}
|
||||
@@ -94,10 +94,10 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getElementTypeTest(){
|
||||
public void getElementTypeTest() {
|
||||
final List<Integer> integers = Arrays.asList(null, 1);
|
||||
final Class<?> elementType = IterUtil.getElementType(integers);
|
||||
Assert.assertEquals(Integer.class,elementType);
|
||||
Assert.assertEquals(Integer.class, elementType);
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -108,9 +108,9 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest(){
|
||||
final List<String> obj2 = ListUtil.toList("3");
|
||||
final List<String> obj = ListUtil.toList("1", "3");
|
||||
public void filterTest() {
|
||||
final List<String> obj2 = ListUtil.of("3");
|
||||
final List<String> obj = ListUtil.of("1", "3");
|
||||
|
||||
IterUtil.filter(obj.iterator(), obj2::contains);
|
||||
|
||||
@@ -119,9 +119,9 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filteredTest(){
|
||||
final List<String> obj2 = ListUtil.toList("3");
|
||||
final List<String> obj = ListUtil.toList("1", "3");
|
||||
public void filteredTest() {
|
||||
final List<String> obj2 = ListUtil.of("3");
|
||||
final List<String> obj = ListUtil.of("1", "3");
|
||||
|
||||
final FilterIter<String> filtered = IterUtil.filtered(obj.iterator(), obj2::contains);
|
||||
|
||||
@@ -130,9 +130,9 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterToListTest(){
|
||||
final List<String> obj2 = ListUtil.toList("3");
|
||||
final List<String> obj = ListUtil.toList("1", "3");
|
||||
public void filterToListTest() {
|
||||
final List<String> obj2 = ListUtil.of("3");
|
||||
final List<String> obj = ListUtil.of("1", "3");
|
||||
|
||||
final List<String> filtered = IterUtil.filterToList(obj.iterator(), obj2::contains);
|
||||
|
||||
@@ -142,7 +142,7 @@ public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
final HashSet<String> set = CollUtil.set(true, "A", "B", "C", "D");
|
||||
final HashSet<String> set = SetUtil.ofLinked("A", "B", "C", "D");
|
||||
final String str = IterUtil.get(set.iterator(), 2);
|
||||
Assert.assertEquals("C", str);
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void editTest() {
|
||||
final List<String> a = ListUtil.toLinkedList("1", "2", "3");
|
||||
final List<String> a = ListUtil.ofLinked("1", "2", "3");
|
||||
final List<String> filter = (List<String>) CollUtil.edit(a, str -> "edit" + str);
|
||||
Assert.assertEquals("edit1", filter.get(0));
|
||||
Assert.assertEquals("edit2", filter.get(1));
|
||||
@@ -96,16 +96,16 @@ public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void indexOfAll() {
|
||||
final List<String> a = ListUtil.toLinkedList("1", "2", "3", "4", "3", "2", "1");
|
||||
final int[] indexArray = ListUtil.indexOfAll(a, "2"::equals);
|
||||
final List<String> a = ListUtil.ofLinked("1", "2", "3", "4", "3", "2", "1");
|
||||
final int[] indexArray = CollUtil.indexOfAll(a, "2"::equals);
|
||||
Assert.assertArrayEquals(new int[]{1,5}, indexArray);
|
||||
final int[] indexArray2 = ListUtil.indexOfAll(a, "1"::equals);
|
||||
final int[] indexArray2 = CollUtil.indexOfAll(a, "1"::equals);
|
||||
Assert.assertArrayEquals(new int[]{0,6}, indexArray2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pageTest() {
|
||||
final List<Integer> a = ListUtil.toLinkedList(1, 2, 3,4,5);
|
||||
final List<Integer> a = ListUtil.ofLinked(1, 2, 3,4,5);
|
||||
|
||||
PageUtil.setFirstPageNo(1);
|
||||
final int[] a_1 = ListUtil.page(1,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
||||
@@ -174,7 +174,7 @@ public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void subTest() {
|
||||
final List<Integer> of = ListUtil.of(1, 2, 3, 4);
|
||||
final List<Integer> of = ListUtil.view(1, 2, 3, 4);
|
||||
final List<Integer> sub = ListUtil.sub(of, 2, 4);
|
||||
sub.remove(0);
|
||||
|
||||
@@ -192,7 +192,7 @@ public class ListUtilTest {
|
||||
private String name;
|
||||
}
|
||||
|
||||
final List<TestBean> beanList = ListUtil.toList(
|
||||
final List<TestBean> beanList = ListUtil.of(
|
||||
new TestBean(2, "test2"),
|
||||
new TestBean(1, "test1"),
|
||||
new TestBean(5, "test5"),
|
||||
|
@@ -22,7 +22,7 @@ public class PartitionIterTest {
|
||||
|
||||
@Test
|
||||
public void iterMaxTest() {
|
||||
final List<Integer> list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 0, 12, 45, 12);
|
||||
final List<Integer> list = ListUtil.view(1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 0, 12, 45, 12);
|
||||
final PartitionIter<Integer> iter = new PartitionIter<>(list.iterator(), 3);
|
||||
int max = 0;
|
||||
for (final List<Integer> lines : iter) {
|
||||
|
@@ -19,10 +19,10 @@ public class CompareUtilTest {
|
||||
|
||||
@Test
|
||||
public void comparingPinyin() {
|
||||
final List<String> list = ListUtil.toList("成都", "北京", "上海", "深圳");
|
||||
final List<String> list = ListUtil.of("成都", "北京", "上海", "深圳");
|
||||
|
||||
final List<String> ascendingOrderResult = ListUtil.of("北京", "成都", "上海", "深圳");
|
||||
final List<String> descendingOrderResult = ListUtil.of("深圳", "上海", "成都", "北京");
|
||||
final List<String> ascendingOrderResult = ListUtil.view("北京", "成都", "上海", "深圳");
|
||||
final List<String> descendingOrderResult = ListUtil.view("深圳", "上海", "成都", "北京");
|
||||
|
||||
// 正序
|
||||
list.sort(CompareUtil.comparingPinyin(e -> e));
|
||||
|
@@ -2,8 +2,10 @@ package cn.hutool.core.compiler;
|
||||
|
||||
import cn.hutool.core.compress.ZipUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.reflect.ConstructorUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -16,6 +18,13 @@ import java.io.InputStream;
|
||||
*/
|
||||
public class JavaSourceCompilerTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void compilerATest(){
|
||||
final boolean compile = CompilerUtil.compile(FileUtil.file("test-compile/a/A.java").getAbsolutePath());
|
||||
Assert.assertTrue(compile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试编译Java源码
|
||||
*/
|
||||
@@ -29,6 +38,7 @@ public class JavaSourceCompilerTest {
|
||||
FileUtil.getInputStream("test-compile/a/A$1.class"),
|
||||
FileUtil.getInputStream("test-compile/a/A$InnerClass.class")
|
||||
});
|
||||
Console.log(libFile.getAbsolutePath());
|
||||
final ClassLoader classLoader = CompilerUtil.getCompiler(null)
|
||||
.addSource(FileUtil.file("test-compile/b/B.java"))
|
||||
.addSource("c.C", FileUtil.readUtf8String("test-compile/c/C.java"))
|
||||
|
@@ -0,0 +1,46 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CastUtilTest {
|
||||
@Test
|
||||
public void testCastToSuper() {
|
||||
Collection<Integer> collection= ListUtil.of(1,2,3);
|
||||
List<Integer> list = ListUtil.of(1, 2, 3);
|
||||
Set<Integer> set = SetUtil.of(1, 2, 3);
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
map.put(1, 1);
|
||||
|
||||
Collection<Number> collection2 = CastUtil.castUp(collection);
|
||||
collection2.add(new Double("123.1"));
|
||||
Assert.assertSame(collection, collection2);
|
||||
|
||||
Collection<Integer> collection3 = CastUtil.castDown(collection2);
|
||||
Assert.assertSame(collection2, collection3);
|
||||
|
||||
List<Number> list2 = CastUtil.castUp(list);
|
||||
Assert.assertSame(list, list2);
|
||||
List<Integer> list3 = CastUtil.castDown(list2);
|
||||
Assert.assertSame(list2, list3);
|
||||
|
||||
Set<Number> set2 = CastUtil.castUp(set);
|
||||
Assert.assertSame(set, set2);
|
||||
Set<Integer> set3 = CastUtil.castDown(set2);
|
||||
Assert.assertSame(set2, set3);
|
||||
|
||||
Map<Number, Serializable> map2 = CastUtil.castUp(map);
|
||||
Assert.assertSame(map, map2);
|
||||
Map<Integer, Number> map3 = CastUtil.castDown(map2);
|
||||
Assert.assertSame(map2, map3);
|
||||
}
|
||||
}
|
@@ -1,12 +1,12 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.date.DateException;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import cn.hutool.core.util.ByteUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
@@ -15,6 +15,8 @@ import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -293,7 +295,7 @@ public class ConvertTest {
|
||||
public void toSetTest(){
|
||||
final Set<Integer> result = Convert.convert(new TypeReference<Set<Integer>>() {
|
||||
}, "1,2,3");
|
||||
Assert.assertEquals(CollUtil.set(false, 1,2,3), result);
|
||||
Assert.assertEquals(SetUtil.of(1,2,3), result);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@@ -383,4 +385,11 @@ public class ConvertTest {
|
||||
final float b = Convert.toFloat(a);
|
||||
Assert.assertEquals(a, b, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localDateTimeToLocalDateTest(){
|
||||
final LocalDateTime localDateTime = LocalDateTime.now();
|
||||
final LocalDate convert = Convert.convert(LocalDate.class, localDateTime);
|
||||
Assert.assertEquals(localDateTime.toLocalDate(), convert);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -128,7 +128,7 @@ public class ConvertToCollectionTest {
|
||||
public void toSetTest() {
|
||||
final Object[] a = { "a", "你", "好", "", 1 };
|
||||
final LinkedHashSet<?> set = Convert.convert(LinkedHashSet.class, a);
|
||||
final ArrayList<?> list = CollUtil.newArrayList(set);
|
||||
final ArrayList<?> list = ListUtil.of(set);
|
||||
Assert.assertEquals("a", list.get(0));
|
||||
Assert.assertEquals("你", list.get(1));
|
||||
Assert.assertEquals("好", list.get(2));
|
||||
|
@@ -31,4 +31,10 @@ public class NumberWordFormatTest {
|
||||
final String format5 = NumberWordFormatter.formatSimple(438);
|
||||
Assert.assertEquals("438", format5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatSimpleTest2(){
|
||||
final String s = NumberWordFormatter.formatSimple(1000);
|
||||
Assert.assertEquals("1k", s);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.BetweenFormatter.Level;
|
||||
import cn.hutool.core.date.format.FastDateFormat;
|
||||
import cn.hutool.core.lang.Console;
|
||||
@@ -800,13 +800,13 @@ public class DateUtilTest {
|
||||
Assert.assertEquals("20184", yearAndQuarter);
|
||||
|
||||
final LinkedHashSet<String> yearAndQuarters = DateUtil.yearAndQuarter(DateUtil.parse("2018-09-10"), DateUtil.parse("2018-12-20"));
|
||||
final List<String> list = CollUtil.list(false, yearAndQuarters);
|
||||
final List<String> list = ListUtil.of(false, yearAndQuarters);
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertEquals("20183", list.get(0));
|
||||
Assert.assertEquals("20184", list.get(1));
|
||||
|
||||
final LinkedHashSet<String> yearAndQuarters2 = DateUtil.yearAndQuarter(DateUtil.parse("2018-10-10"), DateUtil.parse("2018-12-10"));
|
||||
final List<String> list2 = CollUtil.list(false, yearAndQuarters2);
|
||||
final List<String> list2 = ListUtil.of(false, yearAndQuarters2);
|
||||
Assert.assertEquals(1, list2.size());
|
||||
Assert.assertEquals("20184", list2.get(0));
|
||||
}
|
||||
|
@@ -465,7 +465,7 @@ public class FileUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void appendLinesTest(){
|
||||
final List<String> list = ListUtil.toList("a", "b", "c");
|
||||
final List<String> list = ListUtil.of("a", "b", "c");
|
||||
FileUtil.appendLines(list, FileUtil.file("d:/test/appendLines.txt"), CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
|
@@ -37,7 +37,7 @@ public class DictTest {
|
||||
|
||||
@Test
|
||||
public void ofTest(){
|
||||
final Dict dict = Dict.of(
|
||||
final Dict dict = Dict.ofKvs(
|
||||
"RED", "#FF0000",
|
||||
"GREEN", "#00FF00",
|
||||
"BLUE", "#0000FF"
|
||||
@@ -50,11 +50,11 @@ public class DictTest {
|
||||
|
||||
@Test
|
||||
public void removeEqualTest(){
|
||||
final Dict dict = Dict.of(
|
||||
final Dict dict = Dict.ofKvs(
|
||||
"key1", null
|
||||
);
|
||||
|
||||
final Dict dict2 = Dict.of(
|
||||
final Dict dict2 = Dict.ofKvs(
|
||||
"key1", null
|
||||
);
|
||||
|
||||
|
@@ -222,6 +222,7 @@ public class ValidatorTest {
|
||||
public void isCarVinTest(){
|
||||
Assert.assertTrue(Validator.isCarVin("LSJA24U62JG269225"));
|
||||
Assert.assertTrue(Validator.isCarVin("LDC613P23A1305189"));
|
||||
Assert.assertFalse(Validator.isCarVin("LOC613P23A1305189"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package cn.hutool.core.lang;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
||||
public class WeightRandomTest {
|
||||
|
||||
@Test
|
||||
@@ -15,6 +14,6 @@ public class WeightRandomTest {
|
||||
random.add("C", 100);
|
||||
|
||||
final String result = random.next();
|
||||
Assert.assertTrue(CollUtil.newArrayList("A", "B", "C").contains(result));
|
||||
Assert.assertTrue(ListUtil.of("A", "B", "C").contains(result));
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CaseInsensitiveMapTest {
|
||||
|
||||
@Test
|
||||
@@ -25,8 +26,8 @@ public class CaseInsensitiveMapTest {
|
||||
@Test
|
||||
public void mergeTest(){
|
||||
//https://github.com/dromara/hutool/issues/2086
|
||||
final Pair<String, String> b = new Pair<>("a", "value");
|
||||
final Pair<String, String> a = new Pair<>("A", "value");
|
||||
final Map.Entry<String, String> b = MapUtil.entry("a", "value");
|
||||
final Map.Entry<String, String> a = MapUtil.entry("A", "value");
|
||||
final CaseInsensitiveMap<Object, Object> map = new CaseInsensitiveMap<>();
|
||||
map.merge(b.getKey(), b.getValue(), (A, B) -> A);
|
||||
map.merge(a.getKey(), a.getValue(), (A, B) -> A);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -33,8 +33,8 @@ public class StrJoinerTest {
|
||||
@Test
|
||||
public void joinMultiArrayTest(){
|
||||
final StrJoiner append = StrJoiner.of(",");
|
||||
append.append(new Object[]{ListUtil.of("1", "2"),
|
||||
CollUtil.newLinkedHashSet("3", "4")
|
||||
append.append(new Object[]{ListUtil.view("1", "2"),
|
||||
SetUtil.ofLinked("3", "4")
|
||||
});
|
||||
Assert.assertEquals("1,2,3,4", append.toString());
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.text.dfa;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,就不再继续匹配了,因此【大土豆】不匹配
|
||||
// 匹配到【刚出锅】,就跳过这三个字了,因此【出锅】不匹配(由于刚首先被匹配,因此长的被匹配,最短匹配只针对第一个字相同选最短)
|
||||
final List<String> matchAll = tree.matchAll(text, -1, false, false);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ public class DfaTest {
|
||||
// 【大】被匹配,最短匹配原则【大土豆】被跳过,【土豆继续被匹配】
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
final List<String> matchAll = tree.matchAll(text, -1, true, false);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅", "出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅", "出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于非密集匹配,因此从下一个字符开始查找,匹配到【土豆】接着被匹配
|
||||
// 由于【刚出锅】被匹配,由于非密集匹配,【出锅】被跳过
|
||||
final List<String> matchAll = tree.matchAll(text, -1, false, true);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅"));
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配,由于不跳过已经匹配的关键词,土豆继续被匹配
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
final List<String> matchAll = tree.matchAll(text, -1, true, true);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class DfaTest {
|
||||
tree.addWord("tio");
|
||||
|
||||
final List<String> all = tree.matchAll("AAAAAAAt-ioBBBBBBB");
|
||||
Assert.assertEquals(all, CollUtil.newArrayList("t-io"));
|
||||
Assert.assertEquals(all, ListUtil.of("t-io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -34,7 +34,7 @@ public class SensitiveUtilTest {
|
||||
|
||||
@Test
|
||||
public void issue2126(){
|
||||
SensitiveUtil.init(ListUtil.of("赵", "赵阿", "赵阿三"));
|
||||
SensitiveUtil.init(ListUtil.view("赵", "赵阿", "赵阿三"));
|
||||
|
||||
final String result = SensitiveUtil.sensitiveFilter("赵阿三在做什么。", true, null);
|
||||
Assert.assertEquals("***在做什么。", result);
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package cn.hutool.core.tree;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.tree.Tree;
|
||||
import cn.hutool.core.tree.TreeUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -13,7 +11,7 @@ public class Issue2279Test {
|
||||
|
||||
@Test
|
||||
public void buildSingleTest() {
|
||||
final List<TestTree> list = ListUtil.of(
|
||||
final List<TestTree> list = ListUtil.view(
|
||||
// 模拟数据
|
||||
new TestTree(1, 0, 1, 1),
|
||||
new TestTree(2, 1, 2, 2),
|
||||
|
@@ -1,10 +1,6 @@
|
||||
package cn.hutool.core.tree;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.tree.Tree;
|
||||
import cn.hutool.core.tree.TreeNode;
|
||||
import cn.hutool.core.tree.TreeNodeConfig;
|
||||
import cn.hutool.core.tree.TreeUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -18,7 +14,7 @@ import java.util.List;
|
||||
*/
|
||||
public class TreeTest {
|
||||
// 模拟数据
|
||||
static List<TreeNode<String>> nodeList = CollUtil.newArrayList();
|
||||
static List<TreeNode<String>> nodeList = ListUtil.of();
|
||||
|
||||
static {
|
||||
// 模拟数据
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -323,7 +323,7 @@ public class ArrayUtilTest {
|
||||
|
||||
@Test
|
||||
public void toArrayTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("A", "B", "C", "D");
|
||||
final ArrayList<String> list = ListUtil.of("A", "B", "C", "D");
|
||||
final String[] array = ArrayUtil.toArray(list, String.class);
|
||||
Assert.assertEquals("A", array[0]);
|
||||
Assert.assertEquals("B", array[1]);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -18,13 +18,13 @@ public class EnumUtilTest {
|
||||
@Test
|
||||
public void getNamesTest() {
|
||||
final List<String> names = EnumUtil.getNames(TestEnum.class);
|
||||
Assert.assertEquals(CollUtil.newArrayList("TEST1", "TEST2", "TEST3"), names);
|
||||
Assert.assertEquals(ListUtil.of("TEST1", "TEST2", "TEST3"), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFieldValuesTest() {
|
||||
final List<Object> types = EnumUtil.getFieldValues(TestEnum.class, "type");
|
||||
Assert.assertEquals(CollUtil.newArrayList("type1", "type2", "type3"), types);
|
||||
Assert.assertEquals(ListUtil.of("type1", "type2", "type3"), types);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -47,49 +47,49 @@ public class IdcardUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAgeByIdCardTest() {
|
||||
public void getAgeTest() {
|
||||
final DateTime date = DateUtil.parse("2017-04-10");
|
||||
|
||||
final int age = IdcardUtil.getAgeByIdCard(ID_18, date);
|
||||
final int age = IdcardUtil.getAge(ID_18, date);
|
||||
Assert.assertEquals(age, 38);
|
||||
|
||||
final int age2 = IdcardUtil.getAgeByIdCard(ID_15, date);
|
||||
final int age2 = IdcardUtil.getAge(ID_15, date);
|
||||
Assert.assertEquals(age2, 28);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBirthByIdCardTest() {
|
||||
final String birth = IdcardUtil.getBirthByIdCard(ID_18);
|
||||
public void getBirthTest() {
|
||||
final String birth = IdcardUtil.getBirth(ID_18);
|
||||
Assert.assertEquals(birth, "19781216");
|
||||
|
||||
final String birth2 = IdcardUtil.getBirthByIdCard(ID_15);
|
||||
final String birth2 = IdcardUtil.getBirth(ID_15);
|
||||
Assert.assertEquals(birth2, "19880730");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProvinceByIdCardTest() {
|
||||
final String province = IdcardUtil.getProvinceByIdCard(ID_18);
|
||||
public void getProvinceTest() {
|
||||
final String province = IdcardUtil.getProvince(ID_18);
|
||||
Assert.assertEquals(province, "江苏");
|
||||
|
||||
final String province2 = IdcardUtil.getProvinceByIdCard(ID_15);
|
||||
final String province2 = IdcardUtil.getProvince(ID_15);
|
||||
Assert.assertEquals(province2, "内蒙古");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCityCodeByIdCardTest() {
|
||||
final String codeByIdCard = IdcardUtil.getCityCodeByIdCard(ID_18);
|
||||
Assert.assertEquals("3210", codeByIdCard);
|
||||
public void getCityCodeTest() {
|
||||
final String code = IdcardUtil.getCityCode(ID_18);
|
||||
Assert.assertEquals("3210", code);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDistrictCodeByIdCardTest() {
|
||||
final String codeByIdCard = IdcardUtil.getDistrictCodeByIdCard(ID_18);
|
||||
Assert.assertEquals("321083", codeByIdCard);
|
||||
public void getDistrictCodeTest() {
|
||||
final String code = IdcardUtil.getDistrictCode(ID_18);
|
||||
Assert.assertEquals("321083", code);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGenderByIdCardTest() {
|
||||
final int gender = IdcardUtil.getGenderByIdCard(ID_18);
|
||||
public void getGenderTest() {
|
||||
final int gender = IdcardUtil.getGender(ID_18);
|
||||
Assert.assertEquals(1, gender);
|
||||
}
|
||||
|
||||
|
@@ -62,6 +62,9 @@ public class NumberUtilTest {
|
||||
Assert.assertTrue(NumberUtil.isInteger("0256"));
|
||||
Assert.assertTrue(NumberUtil.isInteger("0"));
|
||||
Assert.assertFalse(NumberUtil.isInteger("23.4"));
|
||||
Assert.assertFalse(NumberUtil.isInteger(null));
|
||||
Assert.assertFalse(NumberUtil.isInteger(""));
|
||||
Assert.assertFalse(NumberUtil.isInteger(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,6 +74,9 @@ public class NumberUtilTest {
|
||||
Assert.assertTrue(NumberUtil.isLong("0256"));
|
||||
Assert.assertTrue(NumberUtil.isLong("0"));
|
||||
Assert.assertFalse(NumberUtil.isLong("23.4"));
|
||||
Assert.assertFalse(NumberUtil.isLong(null));
|
||||
Assert.assertFalse(NumberUtil.isLong(""));
|
||||
Assert.assertFalse(NumberUtil.isLong(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,6 +299,13 @@ public class NumberUtilTest {
|
||||
Assert.assertEquals(1482L, v2.longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseHexNumberTest() {
|
||||
// 千位分隔符去掉
|
||||
final int v1 = NumberUtil.parseNumber("0xff").intValue();
|
||||
Assert.assertEquals(255, v1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLongTest() {
|
||||
long number = NumberUtil.parseLong("0xFF");
|
||||
@@ -433,6 +446,25 @@ public class NumberUtilTest {
|
||||
Assert.assertFalse(NumberUtil.isEven(a[4]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toBigIntegerTest(){
|
||||
final Number number=1123123;
|
||||
final Number number2=1123123.123;
|
||||
Assert.assertNotNull(NumberUtil.toBigInteger(number));
|
||||
Assert.assertNotNull(NumberUtil.toBigInteger(number2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void divIntegerTest(){
|
||||
final BigDecimal div = NumberUtil.div(100101300, (Number) 100);
|
||||
Assert.assertEquals(1001013, div.intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTest(){
|
||||
Assert.assertFalse(NumberUtil.isDouble(null));
|
||||
Assert.assertFalse(NumberUtil.isDouble(""));
|
||||
Assert.assertFalse(NumberUtil.isDouble(" "));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,24 +1,46 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.clone.CloneSupport;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ObjectUtilTest {
|
||||
public class ObjUtilTest {
|
||||
|
||||
@Test
|
||||
public void equalsTest(){
|
||||
final Object a = null;
|
||||
final Object b = null;
|
||||
public void equalsTest() {
|
||||
Object a = null;
|
||||
Object b = null;
|
||||
Assert.assertTrue(ObjUtil.equals(a, b));
|
||||
|
||||
a = new BigDecimal("1.1");
|
||||
b = new BigDecimal("1.10");
|
||||
Assert.assertTrue(ObjUtil.equals(a, b));
|
||||
|
||||
a = 127;
|
||||
b = 127;
|
||||
Assert.assertTrue(ObjUtil.equals(a, b));
|
||||
|
||||
a = 128;
|
||||
b = 128;
|
||||
Assert.assertTrue(ObjUtil.equals(a, b));
|
||||
|
||||
a = LocalDateTime.of(2022, 5, 29, 22, 11);
|
||||
b = LocalDateTime.of(2022, 5, 29, 22, 11);
|
||||
Assert.assertTrue(ObjUtil.equals(a, b));
|
||||
|
||||
a = 1;
|
||||
b = 1.0;
|
||||
Assert.assertFalse(ObjUtil.equals(a, b));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -33,6 +55,9 @@ public class ObjectUtilTest {
|
||||
map.put("c", "c1");
|
||||
length = ObjUtil.length(map);
|
||||
Assert.assertEquals(3, length);
|
||||
|
||||
final Iterable<Integer> list = ListUtil.of(1, 2, 3);
|
||||
Assert.assertEquals(3, ObjUtil.length(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +83,7 @@ public class ObjectUtilTest {
|
||||
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
final ArrayList<String> strings = CollUtil.newArrayList("1", "2");
|
||||
final ArrayList<String> strings = ListUtil.of("1", "2");
|
||||
final String result = ObjUtil.toString(strings);
|
||||
Assert.assertEquals("[1, 2]", result);
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@@ -15,13 +15,13 @@ public class RandomUtilTest {
|
||||
|
||||
@Test
|
||||
public void randomEleSetTest(){
|
||||
final Set<Integer> set = RandomUtil.randomEleSet(CollUtil.newArrayList(1, 2, 3, 4, 5, 6), 2);
|
||||
final Set<Integer> set = RandomUtil.randomEleSet(ListUtil.of(1, 2, 3, 4, 5, 6), 2);
|
||||
Assert.assertEquals(set.size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void randomElesTest(){
|
||||
final List<Integer> result = RandomUtil.randomEles(CollUtil.newArrayList(1, 2, 3, 4, 5, 6), 2);
|
||||
final List<Integer> result = RandomUtil.randomEles(ListUtil.of(1, 2, 3, 4, 5, 6), 2);
|
||||
Assert.assertEquals(result.size(), 2);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.regex.PatternPool;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
@@ -82,7 +82,7 @@ public class ReUtilTest {
|
||||
public void findAllTest() {
|
||||
// 查找所有匹配文本
|
||||
final List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<>());
|
||||
final ArrayList<String> expected = CollUtil.newArrayList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
final ArrayList<String> expected = ListUtil.of("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
Assert.assertEquals(expected, resultFindAll);
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
@@ -109,7 +110,7 @@ public class XmlUtilTest {
|
||||
final Map<String, Object> map = XmlUtil.xmlToMap(xml);
|
||||
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertEquals(CollUtil.newArrayList("张三", "李四"), map.get("name"));
|
||||
Assert.assertEquals(ListUtil.of("张三", "李四"), map.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +138,7 @@ public class XmlUtilTest {
|
||||
public void mapToXmlTest2() {
|
||||
// 测试List
|
||||
final Map<String, Object> map = MapBuilder.create(new LinkedHashMap<String, Object>())
|
||||
.put("Town", CollUtil.newArrayList("town1", "town2"))
|
||||
.put("Town", ListUtil.of("town1", "town2"))
|
||||
.build();
|
||||
|
||||
final Document doc = XmlUtil.mapToXml(map, "City");
|
||||
@@ -157,7 +158,7 @@ public class XmlUtilTest {
|
||||
|
||||
@Test
|
||||
public void readBySaxTest(){
|
||||
final Set<String> eles = CollUtil.newHashSet(
|
||||
final Set<String> eles = SetUtil.of(
|
||||
"returnsms", "returnstatus", "message", "remainpoint", "taskID", "successCounts");
|
||||
XmlUtil.readBySax(ResourceUtil.getStream("test.xml"), new DefaultHandler(){
|
||||
@Override
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package a;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.ConsoleTable;
|
||||
import cn.hutool.core.lang.caller.CallerUtil;
|
||||
|
||||
@@ -10,15 +11,12 @@ public class A {
|
||||
public A() {
|
||||
new InnerClass() {{
|
||||
int i = 0;
|
||||
Class<?> caller = CallerUtil.getCaller(i);
|
||||
final ConsoleTable t = new ConsoleTable();
|
||||
t.addHeader("类名", "类加载器");
|
||||
System.out.println("初始化 " + getClass() + " 的调用链为: ");
|
||||
while (caller != null) {
|
||||
t.addBody(caller.toString(), caller.getClassLoader().toString());
|
||||
Console.log("初始化 " + getClass() + " 的调用链为: ");
|
||||
Class<?> caller = CallerUtil.getCaller(i);
|
||||
while (caller != null) {
|
||||
Console.log("{} {}", caller, caller.getClassLoader());
|
||||
caller = CallerUtil.getCaller(++i);
|
||||
}
|
||||
t.print();
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user