-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponsibilityChainTest.java
More file actions
58 lines (51 loc) · 1.6 KB
/
ResponsibilityChainTest.java
File metadata and controls
58 lines (51 loc) · 1.6 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package tests.behavioural;
import static org.assertj.core.api.AssertionsForClassTypes.*;
import static space.Planet.*;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import patterns.behavioural.responsabilitychain.*;
/**
* CHAIN OF RESPONSIBILITY PATTERN
*
* <p>Purpose: Passes requests through a chain of handlers, each deciding to process or pass to the next handler.
*
* <p>When to use:
* <ul>
* <li>When more than one object may handle a request</li>
* <li>When you want to issue a request to one of several objects without specifying the receiver explicitly</li>
* <li>When the set of handlers can be dynamically defined</li>
* </ul>
*
* <p>Common Pitfalls:
* <ul>
* <li>Requests with no handler</li>
* <li>Breaking the chain accidentally</li>
* <li>Circularity in chains</li>
* </ul>
*/
class ResponsibilityChainTest {
/**
* We must minimize the risk to our orbiters. We need to check the gravity and temperature of each
* planet before sending an orbiter.
*
* <p>Use the Responsibility Chain pattern to implement the {@link Chain} class.
*/
@Test
void example() {
var checklist = Chain.of(new GravityCheck(), new TempCheck());
assertThat(checklist.doCheck(MARS)).isTrue();
assertThat(checklist.doCheck(MERCURY)).isFalse();
assertThat(checklist.doCheck(JUPITER)).isFalse();
}
@Test
@Disabled
void todo() {
/*
* todo:
* rings represent a hazard to orbiters
* expand the chain to check if the planet has rings
* create a custom chain with custom checks
* */
}
}