提交测试用例

This commit is contained in:
VampireAchao 2022-01-08 21:35:34 +08:00
parent 56129cba7b
commit 554c2bdb64

View File

@ -203,6 +203,20 @@ public class CollStreamUtilTest {
groupThen);
// 总之如果你是想要group分组后还要进行别的操作用它就对了
// 并且对null值进行了友好处理例如
List<Student> students = Arrays.asList(null, null, new Student(1, 1, 1, "张三"),
new Student(1, 2, 1, "李四"));
Map<Long, List<Student>> termIdStudentsMap = CollStreamUtil.groupBy(students, Student::getTermId, Collectors.toList());
Map<Long, List<Student>> termIdStudentsCompareMap = new HashMap<>();
termIdStudentsCompareMap.put(null, Arrays.asList(null, null));
termIdStudentsCompareMap.put(1L, Arrays.asList(new Student(1L, 1, 1, "张三"), new Student(1L, 2, 1, "李四")));
Assert.assertEquals(termIdStudentsCompareMap, termIdStudentsMap);
Map<Long, Long> termIdCountMap = CollStreamUtil.groupBy(students, Student::getTermId, Collectors.counting());
Map<Long, Long> termIdCountCompareMap = new HashMap<>();
termIdCountCompareMap.put(null, 2L);
termIdCountCompareMap.put(1L, 2L);
Assert.assertEquals(termIdCountCompareMap, termIdCountMap);
}