-
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) · 1010 Bytes
/
Copy pathPatternTest.java
File metadata and controls
29 lines (25 loc) · 1010 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.flyweight;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import org.junit.jupiter.api.Test;
/** 验证本模式的协作契约与边界行为. */
public final class PatternTest {
/** 同键共享身份,不同键独立创建. */
@Test
void reusesIntrinsicState() {
StyleFactory factory = new StyleFactory();
assertSame(factory.get("Serif"), factory.get("Serif"));
assertNotSame(factory.get("Serif"), factory.get("Mono"));
}
/** 共享样式不能覆盖另一个字形的坐标. */
@Test
void keepsCoordinatesExternal() {
TextStyle style = new StyleFactory().get("Serif");
Glyph first = new Glyph('A', 10, style);
Glyph second = new Glyph('B', 20, style);
assertEquals("Serif:A@10", first.draw());
assertEquals("Serif:B@20", second.draw());
assertEquals("Serif:A@10", first.draw());
}
}