瀏覽代碼

Removed redundant constructor argument for Cargo (origin can be derived from the inital route specification)

peter_backlund 17 年之前
父節點
當前提交
6a38351409
共有 14 個文件被更改,包括 35 次插入34 次删除
  1. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/application/impl/BookingServiceImpl.java
  2. 2
    2
      dddsample/src/main/java/se/citerus/dddsample/application/util/SampleDataGenerator.java
  3. 5
    4
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Cargo.java
  4. 3
    3
      dddsample/src/test/java/se/citerus/dddsample/application/HandlingEventServiceTest.java
  5. 14
    14
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java
  6. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java
  7. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java
  8. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java
  9. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java
  10. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java
  11. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/CargoRepositoryInMem.java
  12. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java
  13. 2
    2
      dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/CargoRoutingDTOAssemblerTest.java
  14. 1
    1
      dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingViewAdapterTest.java

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/application/impl/BookingServiceImpl.java 查看文件

@@ -44,7 +44,7 @@ public final class BookingServiceImpl implements BookingService {
44 44
     final Location destination = locationRepository.find(destinationUnLocode);
45 45
     final RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
46 46
 
47
-    final Cargo cargo = new Cargo(trackingId, origin, routeSpecification);
47
+    final Cargo cargo = new Cargo(trackingId, routeSpecification);
48 48
 
49 49
     cargoRepository.store(cargo);
50 50
     logger.info("Booked new cargo with tracking id " + cargo.trackingId().idString());

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/application/util/SampleDataGenerator.java 查看文件

@@ -224,7 +224,7 @@ public class SampleDataGenerator implements ServletContextListener {
224 224
 
225 225
         RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, toDate("2009-03-15"));
226 226
         TrackingId trackingId = new TrackingId("ABC123");
227
-        Cargo abc123 = new Cargo(trackingId, HELSINKI, routeSpecification);
227
+        Cargo abc123 = new Cargo(trackingId, routeSpecification);
228 228
 
229 229
         Itinerary itinerary = new Itinerary(asList(
230 230
           new Leg(HONGKONG_TO_NEW_YORK, HONGKONG, NEWYORK, toDate("2009-03-02"), toDate("2009-03-05")),
@@ -263,7 +263,7 @@ public class SampleDataGenerator implements ServletContextListener {
263 263
 
264 264
         RouteSpecification routeSpecification1 = new RouteSpecification(HANGZOU, STOCKHOLM, toDate("2009-03-18"));
265 265
         TrackingId trackingId1 = new TrackingId("JKL567");
266
-        Cargo jkl567 = new Cargo(trackingId1, HANGZOU, routeSpecification1);
266
+        Cargo jkl567 = new Cargo(trackingId1, routeSpecification1);
267 267
 
268 268
         Itinerary itinerary1 = new Itinerary(asList(
269 269
           new Leg(HONGKONG_TO_NEW_YORK, HANGZOU, NEWYORK, toDate("2009-03-03"), toDate("2009-03-05")),

+ 5
- 4
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Cargo.java 查看文件

@@ -52,15 +52,16 @@ public class Cargo implements Entity<Cargo> {
52 52
   
53 53
   private static final Date ETA_UNKOWN = null;
54 54
 
55
-  // TODO origin can be taken from route spec on creation, even if the origin never changes
56
-  public Cargo(final TrackingId trackingId, final Location origin, final RouteSpecification routeSpecification) {
55
+  public Cargo(final TrackingId trackingId, final RouteSpecification routeSpecification) {
57 56
     Validate.notNull(trackingId, "Tracking id is required");
58
-    Validate.notNull(origin, "Origin location is required");
59 57
     Validate.notNull(routeSpecification, "Route specification is required");
60 58
 
61 59
     this.trackingId = trackingId;
62
-    this.origin = origin;
60
+    // Cargo origin never changes, even if the route specification changes.
61
+    // However, at creation, cargo orgin can be derived from the initial route specification.
62
+    this.origin = routeSpecification.origin();
63 63
     this.routeSpecification = routeSpecification;
64
+
64 65
     deriveDeliveryProgress(Collections.<HandlingEvent>emptyList());
65 66
   }
66 67
 

+ 3
- 3
dddsample/src/test/java/se/citerus/dddsample/application/HandlingEventServiceTest.java 查看文件

@@ -28,8 +28,8 @@ public class HandlingEventServiceTest extends TestCase {
28 28
   private LocationRepository locationRepository;
29 29
   private HandlingEventFactory handlingEventFactory;
30 30
 
31
-  private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), HAMBURG, new RouteSpecification(HAMBURG, TOKYO, new Date()));
32
-  private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), HONGKONG, new RouteSpecification(HONGKONG, HELSINKI, new Date()));
31
+  private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), new RouteSpecification(HAMBURG, TOKYO, new Date()));
32
+  private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, HELSINKI, new Date()));
33 33
 
34 34
   protected void setUp() throws Exception{
35 35
     cargoRepository = createMock(CargoRepository.class);
@@ -90,7 +90,7 @@ public class HandlingEventServiceTest extends TestCase {
90 90
     expect(voyageRepository.find(voyageNumber)).andReturn(null);
91 91
 
92 92
     final TrackingId trackingId = new TrackingId("XYZ");
93
-    expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, CHICAGO, new RouteSpecification(CHICAGO, STOCKHOLM, new Date())));
93
+    expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, new RouteSpecification(CHICAGO, STOCKHOLM, new Date())));
94 94
 
95 95
     expect(locationRepository.find(MELBOURNE.unLocode())).andReturn(MELBOURNE);
96 96
 

+ 14
- 14
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java 查看文件

@@ -37,7 +37,7 @@ public class CargoTest extends TestCase {
37 37
       STOCKHOLM, MELBOURNE, arrivalDeadline
38 38
     );
39 39
 
40
-    final Cargo cargo = new Cargo(trackingId, STOCKHOLM, routeSpecification);
40
+    final Cargo cargo = new Cargo(trackingId, routeSpecification);
41 41
 
42 42
     assertEquals(NOT_ROUTED, cargo.routingStatus());
43 43
     assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
@@ -46,7 +46,7 @@ public class CargoTest extends TestCase {
46 46
   }
47 47
 
48 48
   public void testRoutingStatus() throws Exception {
49
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
49
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
50 50
     final Itinerary good = new Itinerary();
51 51
     final Itinerary bad = new Itinerary();
52 52
     final RouteSpecification acceptOnlyGood = new RouteSpecification(cargo.origin(), cargo.routeSpecification().destination(), new Date()) {
@@ -68,7 +68,7 @@ public class CargoTest extends TestCase {
68 68
   }
69 69
 
70 70
   public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
71
-    Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
71
+    Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
72 72
 
73 73
     assertEquals(Location.UNKNOWN, cargo.delivery().lastKnownLocation());
74 74
   }
@@ -100,10 +100,10 @@ public class CargoTest extends TestCase {
100 100
   public void testEquality() throws Exception {
101 101
     RouteSpecification spec1 = new RouteSpecification(STOCKHOLM, HONGKONG, new Date());
102 102
     RouteSpecification spec2 = new RouteSpecification(STOCKHOLM, MELBOURNE, new Date());
103
-    Cargo c1 = new Cargo(new TrackingId("ABC"), STOCKHOLM, spec1);
104
-    Cargo c2 = new Cargo(new TrackingId("CBA"), STOCKHOLM, spec1);
105
-    Cargo c3 = new Cargo(new TrackingId("ABC"), STOCKHOLM, spec2);
106
-    Cargo c4 = new Cargo(new TrackingId("ABC"), STOCKHOLM, spec1);
103
+    Cargo c1 = new Cargo(new TrackingId("ABC"), spec1);
104
+    Cargo c2 = new Cargo(new TrackingId("CBA"), spec1);
105
+    Cargo c3 = new Cargo(new TrackingId("ABC"), spec2);
106
+    Cargo c4 = new Cargo(new TrackingId("ABC"), spec1);
107 107
 
108 108
     assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c4));
109 109
     assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c3));
@@ -146,7 +146,7 @@ public class CargoTest extends TestCase {
146 146
 
147 147
   // TODO: Generate test data some better way
148 148
   private Cargo populateCargoReceivedStockholm() throws Exception {
149
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
149
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
150 150
 
151 151
     HandlingEvent he = new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, STOCKHOLM);
152 152
     events.add(he);
@@ -165,7 +165,7 @@ public class CargoTest extends TestCase {
165 165
   }
166 166
 
167 167
   private Cargo populateCargoOffHongKong() throws Exception {
168
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
168
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
169 169
 
170 170
 
171 171
     events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
@@ -179,7 +179,7 @@ public class CargoTest extends TestCase {
179 179
   }
180 180
 
181 181
   private Cargo populateCargoOnHamburg() throws Exception {
182
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
182
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
183 183
 
184 184
     events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
185 185
     events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
@@ -190,7 +190,7 @@ public class CargoTest extends TestCase {
190 190
   }
191 191
 
192 192
   private Cargo populateCargoOffMelbourne() throws Exception {
193
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
193
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
194 194
 
195 195
     events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
196 196
     events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
@@ -206,7 +206,7 @@ public class CargoTest extends TestCase {
206 206
   }
207 207
 
208 208
   private Cargo populateCargoOnHongKong() throws Exception {
209
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
209
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
210 210
 
211 211
     events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
212 212
     events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
@@ -222,7 +222,7 @@ public class CargoTest extends TestCase {
222 222
 
223 223
   public void testIsMisdirected() throws Exception {
224 224
     //A cargo with no itinerary is not misdirected
225
-    Cargo cargo = new Cargo(new TrackingId("TRKID"), SHANGHAI, new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
225
+    Cargo cargo = new Cargo(new TrackingId("TRKID"), new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
226 226
     assertFalse(cargo.isMisdirected());
227 227
 
228 228
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
@@ -286,7 +286,7 @@ public class CargoTest extends TestCase {
286 286
   }
287 287
 
288 288
   private Cargo setUpCargoWithItinerary(Location origin, Location midpoint, Location destination) {
289
-    Cargo cargo = new Cargo(new TrackingId("CARGO1"), origin, new RouteSpecification(origin, destination, new Date()));
289
+    Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(origin, destination, new Date()));
290 290
 
291 291
     Itinerary itinerary = new Itinerary(
292 292
       Arrays.asList(

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java 查看文件

@@ -8,7 +8,7 @@ import java.util.Date;
8 8
 
9 9
 public class DeliveryTest extends TestCase {
10 10
 
11
-  private Cargo cargo = new Cargo(new TrackingId("XYZ"), HONGKONG, new RouteSpecification(HONGKONG, NEWYORK, new Date()));
11
+  private Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, NEWYORK, new Date()));
12 12
 
13 13
   public void testToSilenceWarnings() throws Exception {
14 14
     assertTrue(true);

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java 查看文件

@@ -36,7 +36,7 @@ public class ItineraryTest extends TestCase {
36 36
 
37 37
     TrackingId trackingId = new TrackingId("CARGO1");
38 38
     RouteSpecification routeSpecification = new RouteSpecification(SHANGHAI, GOTHENBURG, new Date());
39
-    Cargo cargo = new Cargo(trackingId, SHANGHAI, routeSpecification);
39
+    Cargo cargo = new Cargo(trackingId, routeSpecification);
40 40
 
41 41
     Itinerary itinerary = new Itinerary(
42 42
       Arrays.asList(

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java 查看文件

@@ -39,7 +39,7 @@ public class HandlingEventFactoryTest extends TestCase {
39 39
 
40 40
     trackingId = new TrackingId("ABC");
41 41
     RouteSpecification routeSpecification = new RouteSpecification(TOKYO, HELSINKI, new Date());
42
-    cargo = new Cargo(trackingId, TOKYO, routeSpecification);
42
+    cargo = new Cargo(trackingId, routeSpecification);
43 43
   }
44 44
 
45 45
   public void testCreateHandlingEventWithCarrierMovement() throws Exception {

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java 查看文件

@@ -19,7 +19,7 @@ public class HandlingEventTest extends TestCase {
19 19
   protected void setUp() throws Exception {
20 20
     TrackingId trackingId = new TrackingId("XYZ");
21 21
     RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, NEWYORK, new Date());
22
-    cargo = new Cargo(trackingId, HONGKONG, routeSpecification);
22
+    cargo = new Cargo(trackingId, routeSpecification);
23 23
   }
24 24
 
25 25
   public void testNewWithCarrierMovement() throws Exception {

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java 查看文件

@@ -105,7 +105,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
105 105
     Location origin = locationRepository.find(STOCKHOLM.unLocode());
106 106
     Location destination = locationRepository.find(MELBOURNE.unLocode());
107 107
 
108
-    Cargo cargo = new Cargo(trackingId, origin, new RouteSpecification(origin, destination, new Date()));
108
+    Cargo cargo = new Cargo(trackingId, new RouteSpecification(origin, destination, new Date()));
109 109
     cargoRepository.store(cargo);
110 110
 
111 111
     cargo.assignToRoute(new Itinerary(Arrays.asList(

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/CargoRepositoryInMem.java 查看文件

@@ -88,7 +88,7 @@ public class CargoRepositoryInMem implements CargoRepository {
88 88
                                                      Collection<HandlingEvent> events) {
89 89
 
90 90
     final RouteSpecification routeSpecification = new RouteSpecification(origin, destination, new Date());
91
-    final Cargo cargo = new Cargo(trackingId, origin, routeSpecification);
91
+    final Cargo cargo = new Cargo(trackingId, routeSpecification);
92 92
     cargo.deriveDeliveryProgress(new ArrayList<HandlingEvent>(events));
93 93
 
94 94
     return cargo;

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java 查看文件

@@ -47,7 +47,7 @@ public class ExternalRoutingServiceTest extends TestCase {
47 47
   public void testCalculatePossibleRoutes() {
48 48
     TrackingId trackingId = new TrackingId("ABC");
49 49
     RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, new Date());
50
-    Cargo cargo = new Cargo(trackingId, HONGKONG, routeSpecification);
50
+    Cargo cargo = new Cargo(trackingId, routeSpecification);
51 51
 
52 52
     expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.CM002);
53 53
     

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/CargoRoutingDTOAssemblerTest.java 查看文件

@@ -18,7 +18,7 @@ public class CargoRoutingDTOAssemblerTest extends TestCase {
18 18
 
19 19
     final Location origin = STOCKHOLM;
20 20
     final Location destination = MELBOURNE;
21
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, new RouteSpecification(origin, destination, new Date()));
21
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(origin, destination, new Date()));
22 22
 
23 23
     final Itinerary itinerary = new Itinerary(
24 24
       Arrays.asList(
@@ -47,7 +47,7 @@ public class CargoRoutingDTOAssemblerTest extends TestCase {
47 47
   public void testToDTO_NoItinerary() throws Exception {
48 48
     final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
49 49
 
50
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
50
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
51 51
     final CargoRoutingDTO dto = assembler.toDTO(cargo);
52 52
 
53 53
     assertEquals("XYZ", dto.getTrackingId());

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingViewAdapterTest.java 查看文件

@@ -15,7 +15,7 @@ import java.util.*;
15 15
 public class CargoTrackingViewAdapterTest extends TestCase {
16 16
 
17 17
   public void testCreate() {
18
-    Cargo cargo = new Cargo(new TrackingId("XYZ"), HANGZOU, new RouteSpecification(HANGZOU, HELSINKI, new Date()));
18
+    Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HANGZOU, HELSINKI, new Date()));
19 19
 
20 20
     List<HandlingEvent> events = new ArrayList<HandlingEvent>();
21 21
     events.add(new HandlingEvent(cargo, new Date(1), new Date(2), HandlingEvent.Type.RECEIVE, HANGZOU));