|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+package se.citerus.dddsample.tracking.core.domain.model.cargo;
|
|
|
2
|
+
|
|
|
3
|
+import org.junit.Test;
|
|
|
4
|
+import org.junit.internal.runners.JUnit4ClassRunner;
|
|
|
5
|
+import org.junit.runner.RunWith;
|
|
|
6
|
+
|
|
|
7
|
+import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
8
|
+import static org.hamcrest.CoreMatchers.is;
|
|
|
9
|
+import static org.junit.Assert.assertThat;
|
|
|
10
|
+import static se.citerus.dddsample.tracking.core.domain.model.cargo.Leg.deriveLeg;
|
|
|
11
|
+import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
|
|
|
12
|
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.loadOnto;
|
|
|
13
|
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.unloadOff;
|
|
|
14
|
+import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.continental2;
|
|
|
15
|
+import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.pacific1;
|
|
|
16
|
+
|
|
|
17
|
+@RunWith(JUnit4ClassRunner.class)
|
|
|
18
|
+public class LegMatchTest {
|
|
|
19
|
+
|
|
|
20
|
+ @Test
|
|
|
21
|
+ public void compareMatches() {
|
|
|
22
|
+ Itinerary itinerary = new Itinerary(
|
|
|
23
|
+ deriveLeg(pacific1, TOKYO, LONGBEACH),
|
|
|
24
|
+ deriveLeg(continental2, LONGBEACH, DALLAS)
|
|
|
25
|
+ );
|
|
|
26
|
+
|
|
|
27
|
+ LegMatch startMatch = LegMatch.match(
|
|
|
28
|
+ deriveLeg(pacific1, TOKYO, LONGBEACH),
|
|
|
29
|
+ loadOnto(pacific1).in(TOKYO), itinerary);
|
|
|
30
|
+
|
|
|
31
|
+ assertThat(startMatch.handlingActivity(), equalTo(loadOnto(pacific1).in(TOKYO)));
|
|
|
32
|
+ assertThat(startMatch.leg(), equalTo(deriveLeg(pacific1, TOKYO, LONGBEACH)));
|
|
|
33
|
+
|
|
|
34
|
+ LegMatch endMatch = LegMatch.match(
|
|
|
35
|
+ deriveLeg(pacific1, TOKYO, LONGBEACH),
|
|
|
36
|
+ unloadOff(pacific1).in(LONGBEACH), itinerary);
|
|
|
37
|
+
|
|
|
38
|
+ assertThat(endMatch.handlingActivity(), equalTo(unloadOff(pacific1).in(LONGBEACH)));
|
|
|
39
|
+ assertThat(endMatch.leg(), equalTo(deriveLeg(pacific1, TOKYO, LONGBEACH)));
|
|
|
40
|
+
|
|
|
41
|
+ LegMatch nextMatch = LegMatch.match(
|
|
|
42
|
+ deriveLeg(continental2, LONGBEACH, DALLAS),
|
|
|
43
|
+ loadOnto(continental2).in(LONGBEACH), itinerary);
|
|
|
44
|
+
|
|
|
45
|
+ assertThat(nextMatch.handlingActivity(), equalTo(loadOnto(continental2).in(LONGBEACH)));
|
|
|
46
|
+ assertThat(nextMatch.leg(), equalTo(deriveLeg(continental2, LONGBEACH, DALLAS)));
|
|
|
47
|
+
|
|
|
48
|
+ assertThat(startMatch.compareTo(endMatch), is(-1));
|
|
|
49
|
+ assertThat(endMatch.compareTo(startMatch), is(1));
|
|
|
50
|
+ assertThat(endMatch.compareTo(nextMatch), is(-1));
|
|
|
51
|
+ assertThat(nextMatch.compareTo(endMatch), is(1));
|
|
|
52
|
+
|
|
|
53
|
+ assertThat(startMatch.compareTo(startMatch), is(0));
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+}
|