-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrategyTest.java
46 lines (40 loc) · 1.32 KB
/
StrategyTest.java
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
package tests.behavioural;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import patterns.behavioural.strategy.Lidar;
import patterns.behavioural.strategy.Radar;
import patterns.behavioural.strategy.Sensor;
import space.Planet;
/**
* STRATEGY PATTERN defines interchangeable behaviors, each in a separate class, allowing easy
* replacement and extension at runtime while following SOLID principles.
*/
class StrategyTest {
/**
* Our mission requires a sensor to analyze the surface of each planet. The sensor must use a
* radar to analyze planets with a max temperature above 150 Kelvin and a lidar for the rest.
*
* @param planet to analyze
*/
@ParameterizedTest
@MethodSource("space.Planet#values")
void strategyPattern(Planet planet) {
var sensor = new Sensor();
if (planet.getMaxTempKelvin() > 150) {
sensor.setStrategy(new Radar());
} else {
sensor.setStrategy(new Lidar());
}
assertThatCode(() -> sensor.analyze(planet)).doesNotThrowAnyException();
}
@Test
void todo() {
/*
* todo:
* rings represent a hazard to orbiters
* create a visual strategy for planets with rings
* */
}
}