Преглед на файлове

Added first shot at scenario test.

Patrik Fredriksson преди 19 години
родител
ревизия
2833649b46

+ 29
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java Целия файл

@@ -0,0 +1,29 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+public class Cargo {
4
+  private final String trackingId;
5
+  private final Location from;
6
+  private final Location to;
7
+
8
+  public Cargo(String trackingId, Location origin, Location finalDestination) {
9
+    this.trackingId = trackingId;
10
+    this.from = origin;
11
+    this.to = finalDestination;
12
+  }
13
+
14
+  public DeliveryHistory deliveryHistory() {
15
+    return null;  //To change body of created methods use File | Settings | File Templates.
16
+  }
17
+
18
+  public void handle(HandlingEvent event) {
19
+    //To change body of created methods use File | Settings | File Templates.
20
+  }
21
+
22
+  public boolean atFinalDestiation() {
23
+    return false;  //To change body of created methods use File | Settings | File Templates.
24
+  }
25
+
26
+  public Location currentLocation() {
27
+    return null;  //To change body of created methods use File | Settings | File Templates.
28
+  }
29
+}

+ 7
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/CarrierMovement.java Целия файл

@@ -0,0 +1,7 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+public class CarrierMovement {
4
+  public CarrierMovement(Location from, Location to) {
5
+    //To change body of created methods use File | Settings | File Templates.
6
+  }
7
+}

+ 9
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java Целия файл

@@ -0,0 +1,9 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+import java.util.SortedSet;
4
+
5
+public class DeliveryHistory {
6
+  public SortedSet<HandlingEvent> events() {
7
+    return null;  //To change body of created methods use File | Settings | File Templates.
8
+  }
9
+}

+ 15
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java Целия файл

@@ -0,0 +1,15 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+public class HandlingEvent {
4
+  public HandlingEvent(Type type, CarrierMovement carrierMovement) {
5
+    //To change body of created methods use File | Settings | File Templates.
6
+  }
7
+
8
+  public Type type() {
9
+    return null;  //To change body of created methods use File | Settings | File Templates.
10
+  }
11
+
12
+  public enum Type {
13
+    ON, OFF;
14
+  }
15
+}

+ 14
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/Location.java Целия файл

@@ -0,0 +1,14 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+public class Location {
4
+  private final String unlocode;
5
+
6
+  public Location(String unlocode) {
7
+    this.unlocode = unlocode;
8
+  }
9
+
10
+
11
+  public String unlocode() {
12
+    return null;
13
+  }
14
+}

+ 43
- 0
dddsample/src/test/java/se/citerus/dddsample/domain/TrackingScenarioTest.java Целия файл

@@ -0,0 +1,43 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+import junit.framework.TestCase;
4
+
5
+import java.util.SortedSet;
6
+
7
+public class TrackingScenarioTest extends TestCase {
8
+
9
+  public void testTrackingScenarioStage1() {
10
+
11
+    Cargo cargo = populateCargo();
12
+
13
+    DeliveryHistory deliveryHistory = cargo.deliveryHistory();
14
+
15
+    SortedSet<HandlingEvent> handlingEvents = deliveryHistory.events();
16
+
17
+    assertEquals(4, handlingEvents.size());
18
+    final HandlingEvent event = handlingEvents.last();
19
+    assertSame(HandlingEvent.Type.OFF, event.type());
20
+    assertFalse(cargo.atFinalDestiation());
21
+    assertEquals("CNHKG", cargo.currentLocation().unlocode());
22
+
23
+  }
24
+
25
+  private Cargo populateCargo() {
26
+    final Cargo cargo = new Cargo("XYZ", new Location("SESTO"), new Location("AUMEL"));
27
+
28
+    final CarrierMovement stockholmToHamburg =
29
+       new CarrierMovement(new Location("SESTO"), new Location("DEHAM"));
30
+
31
+    cargo.handle(new HandlingEvent(HandlingEvent.Type.ON, stockholmToHamburg));
32
+    cargo.handle(new HandlingEvent(HandlingEvent.Type.OFF, stockholmToHamburg));
33
+
34
+    final CarrierMovement hamburgToHongKong =
35
+       new CarrierMovement(new Location("DEHAM"), new Location("CNHGK"));
36
+
37
+    cargo.handle(new HandlingEvent(HandlingEvent.Type.ON, hamburgToHongKong));
38
+    cargo.handle(new HandlingEvent(HandlingEvent.Type.OFF, hamburgToHongKong));
39
+
40
+    return cargo;
41
+  }
42
+
43
+}