-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternTest.java
More file actions
27 lines (23 loc) · 956 Bytes
/
Copy pathPatternTest.java
File metadata and controls
27 lines (23 loc) · 956 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
package com.hanserwei.patterns.builder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List;
import org.junit.jupiter.api.Test;
/** 验证本模式的协作契约与边界行为. */
public final class PatternTest {
/** 重用构建器不会改变已创建对象,返回集合也不能修改. */
@Test
void buildsIndependentSnapshots() {
Article.Builder builder = new Article.Builder("Java").addTag("OOP");
Article first = builder.build();
builder.addTag("Design");
assertEquals(List.of("OOP"), first.tags());
assertEquals(2, builder.build().tags().size());
assertThrows(UnsupportedOperationException.class, () -> first.tags().add("bad"));
}
/** 构建边界拒绝缺失的业务必填值. */
@Test
void rejectsBlankTitle() {
assertThrows(IllegalArgumentException.class, () -> new Article.Builder(" ").build());
}
}