mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix test
This commit is contained in:
parent
1fba2ca52b
commit
435359b681
@ -17,12 +17,7 @@ import org.dromara.hutool.core.collection.set.SetUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -31,7 +26,7 @@ public class StreamUtilTest {
|
||||
@Test
|
||||
void testIterateHierarchies() {
|
||||
// 创建一个三层的树结构,每个节点都有两个子节点
|
||||
Node node = new Node("1", Arrays.asList(
|
||||
final Node node = new Node("1", Arrays.asList(
|
||||
new Node("1-1", Arrays.asList(
|
||||
new Node("1-1-1", null),
|
||||
new Node("1-1-2", null)
|
||||
@ -43,20 +38,20 @@ public class StreamUtilTest {
|
||||
));
|
||||
|
||||
// 按广度度优先遍历树结构
|
||||
List<String> allNodes = new ArrayList<>();
|
||||
final List<String> allNodes = new ArrayList<>();
|
||||
StreamUtil.iterateHierarchies(node, node1 -> node1.children)
|
||||
.forEach(node1 -> allNodes.add(node1.id));
|
||||
Assertions.assertEquals(Arrays.asList("1", "1-1", "1-2", "1-1-1", "1-1-2", "1-2-1", "1-2-2"), allNodes);
|
||||
|
||||
// 按广度度优先遍历树结构,忽略id为1-1的节点与以其为根节点的子树
|
||||
List<String> filteredNodes = new ArrayList<>();
|
||||
final List<String> filteredNodes = new ArrayList<>();
|
||||
StreamUtil.iterateHierarchies(node, node1 -> node1.children, node1 -> !node1.id.equals("1-1"))
|
||||
.forEach(node1 -> filteredNodes.add(node1.id));
|
||||
Assertions.assertEquals(Arrays.asList("1", "1-2", "1-2-1", "1-2-2"), filteredNodes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofTest(){
|
||||
public void ofTest() {
|
||||
final Stream<Integer> stream = StreamUtil.of(2, x -> x * 2, 4);
|
||||
final String result = stream.collect(CollectorUtil.joining(","));
|
||||
Assertions.assertEquals("2,4,8,16", result);
|
||||
@ -65,7 +60,8 @@ public class StreamUtilTest {
|
||||
// === iterator ===
|
||||
@Test
|
||||
public void streamTestNullIterator() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> StreamUtil.ofIter(null));
|
||||
final Stream<Object> objectStream = StreamUtil.ofIter(null);
|
||||
Assertions.assertEquals(0, objectStream.count());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"RedundantOperationOnEmptyContainer", "RedundantCollectionOperation"})
|
||||
@ -100,11 +96,14 @@ public class StreamUtilTest {
|
||||
private static class Node {
|
||||
private final String id;
|
||||
private List<Node> children;
|
||||
private Node(String id, List<Node> children) {
|
||||
|
||||
private Node(final String id, final List<Node> children) {
|
||||
this.id = id;
|
||||
this.children = children;
|
||||
}
|
||||
public Node(String id) {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public Node(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user