-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternTest.java
More file actions
29 lines (25 loc) · 909 Bytes
/
Copy pathPatternTest.java
File metadata and controls
29 lines (25 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.hanserwei.patterns.composite;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
/** 验证本模式的协作契约与边界行为. */
public final class PatternTest {
/** 相同接口支持任意层次的栏目统计. */
@Test
void countsNestedStructure() {
ContentNode root =
new Section(List.of(new ArticleNode(), new Section(List.of(new ArticleNode()))));
assertEquals(2, root.articleCount());
assertEquals(0, new Section(List.of()).articleCount());
}
/** 输入列表变化不会改变已经构造好的栏目结构. */
@Test
void freezesChildren() {
List<ContentNode> children = new ArrayList<>();
children.add(new ArticleNode());
Section section = new Section(children);
children.clear();
assertEquals(1, section.articleCount());
}
}