mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
处理了CollStreamUtil.toMap中,如果value为空时,发生NPE异常问题
This commit is contained in:
@@ -6,13 +6,7 @@ import lombok.ToString;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* CollectionStream测试方法
|
||||
@@ -51,6 +45,11 @@ public class CollStreamUtilTest {
|
||||
Assert.assertEquals(map.get(2L), "李四");
|
||||
Assert.assertEquals(map.get(3L), "王五");
|
||||
Assert.assertNull(map.get(4L));
|
||||
|
||||
// 测试value为空时
|
||||
list.add(new Student(1, 1, 4, null));
|
||||
map = CollStreamUtil.toMap(list, Student::getStudentId, Student::getName);
|
||||
Assert.assertNull(map.get(4L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user