-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternTest.java
More file actions
35 lines (31 loc) · 1.19 KB
/
Copy pathPatternTest.java
File metadata and controls
35 lines (31 loc) · 1.19 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
34
35
package com.hanserwei.patterns.mediator;
import static org.junit.jupiter.api.Assertions.assertEquals;
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 routesWithoutPeerReferences() {
ReviewRoom room = new ReviewRoom();
Reviewer ada = room.join("Ada");
Reviewer lin = room.join("Lin");
final Reviewer bo = room.join("Bo");
ada.comment("LGTM");
assertTrue(ada.messages().isEmpty());
assertEquals(List.of("Ada:LGTM"), lin.messages());
assertEquals(lin.messages(), bo.messages());
}
/** 不同评审室之间不会泄漏意见,同名加入也会被拒绝. */
@Test
void isolatesRooms() {
ReviewRoom first = new ReviewRoom();
Reviewer ada = first.join("Ada");
Reviewer lin = new ReviewRoom().join("Lin");
ada.comment("Private");
assertTrue(lin.messages().isEmpty());
assertThrows(IllegalArgumentException.class, () -> first.join("Ada"));
}
}