Parcourir la source

A few minor refactorings.

peter_backlund il y a 16 ans
Parent
révision
096953269c

+ 6
- 12
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Cargo.java Voir le fichier

@@ -12,7 +12,6 @@ import java.util.Date;
12 12
 
13 13
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.NOT_ROUTED;
14 14
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.ONBOARD_CARRIER;
15
-import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.UNLOAD;
16 15
 import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.customsIn;
17 16
 
18 17
 /**
@@ -106,18 +105,19 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
106 105
   }
107 106
 
108 107
   /**
109
-   * @return Next expected activity.
108
+   * @return Next expected activity. If the cargo is not on route (misdirected and/or misrouted),
109
+   * it cannot be determined and null is returned.
110 110
    */
111 111
   public HandlingActivity nextExpectedActivity() {
112 112
     if (!delivery.isOnRoute(itinerary, routeSpecification)) {
113 113
       return null;
114 114
     }
115 115
 
116
-    if (unloadedInCustomsClearancePoint()) {
116
+    if (delivery.isUnloadedIn(customsClearancePoint())) {
117 117
       return customsIn(customsClearancePoint());
118
+    } else {
119
+      return itinerary.activitySucceding(delivery.mostRecentPhysicalHandlingActivity());
118 120
     }
119
-
120
-    return itinerary.activitySucceding(delivery.mostRecentPhysicalHandlingActivity());
121 121
   }
122 122
 
123 123
   /**
@@ -228,7 +228,7 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
228 228
     if (customsClearancePoint().sameAs(routeSpecification.destination())) {
229 229
       return customsIn(customsClearancePoint()).sameValueAs(mostRecentHandlingActivity());
230 230
     } else {
231
-      return delivery.onTheGroundAtDestination(routeSpecification);
231
+      return delivery.isUnloadedIn(routeSpecification.destination());
232 232
     }
233 233
   }
234 234
 
@@ -287,12 +287,6 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
287 287
     }
288 288
   }
289 289
 
290
-  private boolean unloadedInCustomsClearancePoint() {
291
-    return mostRecentHandlingActivity() != null &&
292
-           mostRecentHandlingActivity().location().sameAs(customsClearancePoint()) &&
293
-           mostRecentHandlingActivity().type() == UNLOAD;
294
-  }
295
-
296 290
   @Override
297 291
   public String toString() {
298 292
     return trackingId + " (" + routeSpecification + ")";

+ 12
- 17
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Delivery.java Voir le fichier

@@ -23,6 +23,13 @@ class Delivery extends ValueObjectSupport<Delivery> {
23 23
   private final Date lastUpdatedOn;
24 24
 
25 25
   /**
26
+   * @return Initial delivery, before any handling has taken place
27
+   */
28
+  static Delivery beforeHandling() {
29
+    return new Delivery(null, null);
30
+  }
31
+
32
+  /**
26 33
    * Derives a new delivery when a cargo has been handled.
27 34
    *
28 35
    * @param newHandlingActivity  handling activity
@@ -45,13 +52,6 @@ class Delivery extends ValueObjectSupport<Delivery> {
45 52
     return new Delivery(mostRecentHandlingActivity, mostRecentPhysicalHandlingActivity);
46 53
   }
47 54
 
48
-  /**
49
-   * @return Initial delivery, before any handling has taken place
50
-   */
51
-  static Delivery beforeHandling() {
52
-    return new Delivery(null, null);
53
-  }
54
-
55 55
   private Delivery(final HandlingActivity mostRecentHandlingActivity,
56 56
                    final HandlingActivity mostRecentPhysicalHandlingActivity) {
57 57
     this.mostRecentHandlingActivity = mostRecentHandlingActivity;
@@ -120,16 +120,6 @@ class Delivery extends ValueObjectSupport<Delivery> {
120 120
   }
121 121
 
122 122
   /**
123
-   * @return True if the cargo has been unloaded at the final destination.
124
-   * @param routeSpecification route specification
125
-   */
126
-  boolean onTheGroundAtDestination(final RouteSpecification routeSpecification) {
127
-    return hasBeenHandled() &&
128
-           mostRecentHandlingActivity.type() == UNLOAD &&
129
-           routeSpecification.destination().sameAs(mostRecentHandlingActivity.location());
130
-  }
131
-
132
-  /**
133 123
    * @return Routing status.
134 124
    * @param itinerary itinerary
135 125
    * @param routeSpecification route specification
@@ -168,4 +158,9 @@ class Delivery extends ValueObjectSupport<Delivery> {
168 158
     mostRecentHandlingActivity = mostRecentPhysicalHandlingActivity = null;
169 159
   }
170 160
 
161
+  boolean isUnloadedIn(Location customsClearancePoint) {
162
+    return hasBeenHandled() &&
163
+           mostRecentHandlingActivity.location().sameAs(customsClearancePoint) &&
164
+           mostRecentHandlingActivity().type() == UNLOAD;
165
+  }
171 166
 }

+ 12
- 11
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/DeliveryTest.java Voir le fichier

@@ -1,6 +1,12 @@
1 1
 package se.citerus.dddsample.tracking.core.domain.model.cargo;
2 2
 
3 3
 import junit.framework.TestCase;
4
+import se.citerus.dddsample.tracking.core.domain.model.location.Location;
5
+import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
6
+import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
7
+
8
+import java.util.Date;
9
+
4 10
 import static org.hamcrest.core.Is.is;
5 11
 import static org.junit.Assert.assertThat;
6 12
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
@@ -8,15 +14,10 @@ import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatu
8 14
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.ROUTED;
9 15
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.*;
10 16
 import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
11
-import se.citerus.dddsample.tracking.core.domain.model.location.Location;
12 17
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
13
-import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
14 18
 import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.customsIn;
15 19
 import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.loadOnto;
16 20
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
17
-import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
18
-
19
-import java.util.Date;
20 21
 
21 22
 public class DeliveryTest extends TestCase {
22 23
 
@@ -61,7 +62,7 @@ public class DeliveryTest extends TestCase {
61 62
   public void testDerivedFromRouteSpecificationAndItinerary() throws Exception {
62 63
     assertEquals(ROUTED, delivery.routingStatus(itinerary, routeSpecification));
63 64
     assertEquals(Voyage.NONE, delivery.currentVoyage());
64
-    assertFalse(delivery.onTheGroundAtDestination(routeSpecification));
65
+    assertFalse(delivery.isUnloadedIn(routeSpecification.destination()));
65 66
     assertEquals(Location.NONE, delivery.lastKnownLocation());
66 67
     assertEquals(NOT_RECEIVED, delivery.transportStatus());
67 68
     assertTrue(delivery.lastUpdatedOn().before(new Date()));
@@ -79,7 +80,7 @@ public class DeliveryTest extends TestCase {
79 80
     assertEquals(IN_PORT, newDelivery.transportStatus());
80 81
 
81 82
     // Changed on handling and/or (re-)routing
82
-    assertFalse(newDelivery.onTheGroundAtDestination(routeSpecification));
83
+    assertFalse(newDelivery.isUnloadedIn(routeSpecification.destination()));
83 84
 
84 85
     // Changed on (re-)routing
85 86
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
@@ -96,7 +97,7 @@ public class DeliveryTest extends TestCase {
96 97
     assertEquals(HANGZOU, newDelivery.lastKnownLocation());
97 98
     assertEquals(ONBOARD_CARRIER, newDelivery.transportStatus());
98 99
 
99
-    assertFalse(newDelivery.onTheGroundAtDestination(routeSpecification));
100
+    assertFalse(newDelivery.isUnloadedIn(routeSpecification.destination()));
100 101
 
101 102
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
102 103
 
@@ -113,7 +114,7 @@ public class DeliveryTest extends TestCase {
113 114
     assertEquals(STOCKHOLM, newDelivery.lastKnownLocation());
114 115
     assertEquals(IN_PORT, newDelivery.transportStatus());
115 116
 
116
-    assertTrue(newDelivery.onTheGroundAtDestination(routeSpecification));
117
+    assertTrue(newDelivery.isUnloadedIn(routeSpecification.destination()));
117 118
 
118 119
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
119 120
 
@@ -128,7 +129,7 @@ public class DeliveryTest extends TestCase {
128 129
     assertEquals(STOCKHOLM, newDelivery.lastKnownLocation());
129 130
     assertEquals(CLAIMED, newDelivery.transportStatus());
130 131
 
131
-    assertFalse(newDelivery.onTheGroundAtDestination(routeSpecification));
132
+    assertFalse(newDelivery.isUnloadedIn(routeSpecification.destination()));
132 133
 
133 134
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
134 135
 
@@ -146,7 +147,7 @@ public class DeliveryTest extends TestCase {
146 147
 
147 148
     // Next handling activity is undefined. Need a new itinerary to know what to do.
148 149
 
149
-    assertFalse(newDelivery.onTheGroundAtDestination(routeSpecification));
150
+    assertFalse(newDelivery.isUnloadedIn(routeSpecification.destination()));
150 151
 
151 152
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
152 153