-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternTest.java
More file actions
33 lines (29 loc) · 1.15 KB
/
Copy pathPatternTest.java
File metadata and controls
33 lines (29 loc) · 1.15 KB
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
30
31
32
33
package com.hanserwei.patterns.facade;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.junit.jupiter.api.Test;
/** 验证本模式的协作契约与边界行为. */
public final class PatternTest {
/** 一次高层调用协调保存和建立索引. */
@Test
void coordinatesSubsystems() {
DraftStore store = new DraftStore();
SearchIndex index = new SearchIndex();
new PublishingFacade(store, index).publish("Java");
assertEquals(List.of("Java"), store.titles());
assertTrue(index.contains("Java"));
}
/** 校验失败时不能先留下部分存储结果. */
@Test
void validatesBeforeSideEffects() {
DraftStore store = new DraftStore();
SearchIndex index = new SearchIndex();
PublishingFacade facade = new PublishingFacade(store, index);
assertThrows(IllegalArgumentException.class, () -> facade.publish(" "));
assertTrue(store.titles().isEmpty());
assertFalse(index.contains(" "));
}
}