Просмотр исходного кода

Renamed Location null object to NONE

peter_backlund 16 лет назад
Родитель
Сommit
306125d233

+ 1
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Cargo.java Просмотреть файл

@@ -200,7 +200,7 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
200 200
    */
201 201
   public Location customsClearancePoint() {
202 202
     if (itinerary == null) {
203
-      return Location.UNKNOWN;
203
+      return Location.NONE;
204 204
     } else {
205 205
       return customsZone().entryPoint(itinerary.locations());
206 206
     }

+ 1
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Delivery.java Просмотреть файл

@@ -83,7 +83,7 @@ class Delivery extends ValueObjectSupport<Delivery> {
83 83
     if (hasBeenHandled()) {
84 84
       return mostRecentHandlingActivity.location();
85 85
     } else {
86
-      return Location.UNKNOWN;
86
+      return Location.NONE;
87 87
     }
88 88
   }
89 89
 

+ 2
- 2
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/location/CustomsZone.java Просмотреть файл

@@ -27,7 +27,7 @@ public class CustomsZone extends EntitySupport<CustomsZone,String> {
27 27
    * @param code code
28 28
    * @param name name
29 29
    */
30
-  public CustomsZone(final String code, final String name) {
30
+  CustomsZone(final String code, final String name) {
31 31
     Validate.notNull(code, "Code is required");
32 32
     Validate.isTrue(VALID_PATTERN.matcher(code).matches(), code + " is not a valid customs zone code (does not match pattern)");
33 33
     Validate.notNull(name, "Name is required");
@@ -35,7 +35,7 @@ public class CustomsZone extends EntitySupport<CustomsZone,String> {
35 35
     this.code = code.toUpperCase();
36 36
     this.name = name;
37 37
   }
38
-
38
+  
39 39
   @Override
40 40
   public String identity() {
41 41
     return code;

+ 3
- 3
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/location/Location.java Просмотреть файл

@@ -11,7 +11,7 @@ import java.util.TimeZone;
11 11
  * <p/>
12 12
  * It is uniquely identified by a UN Locode.
13 13
  */
14
-public final class Location extends EntitySupport<Location, UnLocode> {
14
+public class Location extends EntitySupport<Location, UnLocode> {
15 15
 
16 16
   private final UnLocode unLocode;
17 17
   private final String name;
@@ -21,8 +21,8 @@ public final class Location extends EntitySupport<Location, UnLocode> {
21 21
   /**
22 22
    * Special Location object that marks an unknown location.
23 23
    */
24
-  public static final Location UNKNOWN = new Location(
25
-    new UnLocode("XXXXX"), "Unknown location", TimeZone.getTimeZone("Zulu"), null
24
+  public static final Location NONE = new Location(
25
+    new UnLocode("XXXXX"), "-", TimeZone.getTimeZone("Zulu"), null
26 26
   );
27 27
 
28 28
   /**

+ 61
- 61
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/CargoTest.java Просмотреть файл

@@ -55,7 +55,7 @@ public class CargoTest extends TestCase {
55 55
 
56 56
     assertEquals(NOT_ROUTED, cargo.routingStatus());
57 57
     assertEquals(NOT_RECEIVED, cargo.transportStatus());
58
-    assertEquals(Location.UNKNOWN, cargo.lastKnownLocation());
58
+    assertEquals(Location.NONE, cargo.lastKnownLocation());
59 59
     assertEquals(Voyage.NONE, cargo.currentVoyage());
60 60
   }
61 61
 
@@ -75,7 +75,6 @@ public class CargoTest extends TestCase {
75 75
     };
76 76
 
77 77
     cargo.specifyNewRoute(acceptOnlyGood);
78
-
79 78
     assertEquals(NOT_ROUTED, cargo.routingStatus());
80 79
 
81 80
     cargo.assignToRoute(bad);
@@ -109,7 +108,7 @@ public class CargoTest extends TestCase {
109 108
   public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
110 109
     Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
111 110
 
112
-    assertEquals(Location.UNKNOWN, cargo.lastKnownLocation());
111
+    assertEquals(Location.NONE, cargo.lastKnownLocation());
113 112
   }
114 113
 
115 114
   public void testlastKnownLocationReceived() throws Exception {
@@ -189,49 +188,6 @@ public class CargoTest extends TestCase {
189 188
     assertFalse(cargo.isReadyToClaim());
190 189
   }
191 190
 
192
-  private Cargo populateCargoReceivedStockholm() throws Exception {
193
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
194
-    cargo.handled(new HandlingActivity(RECEIVE, STOCKHOLM));
195
-    return cargo;
196
-  }
197
-
198
-  private Cargo populateCargoClaimedMelbourne() throws Exception {
199
-    final Cargo cargo = populateCargoOffMelbourne();
200
-
201
-    cargo.handled(new HandlingActivity(CLAIM, MELBOURNE));
202
-    return cargo;
203
-  }
204
-
205
-  private Cargo populateCargoOffHongKong() throws Exception {
206
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
207
-
208
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
209
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
210
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
211
-    cargo.handled(new HandlingActivity(UNLOAD, MELBOURNE, crazyVoyage));
212
-    return cargo;
213
-  }
214
-
215
-  private Cargo populateCargoOnHamburg() throws Exception {
216
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
217
-
218
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
219
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
220
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
221
-    return cargo;
222
-  }
223
-
224
-  private Cargo populateCargoOffMelbourne() throws Exception {
225
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
226
-
227
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
228
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
229
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
230
-    cargo.handled(new HandlingActivity(UNLOAD, MELBOURNE, crazyVoyage));
231
-
232
-    return cargo;
233
-  }
234
-
235 191
   public void testIsMisdirectedHappyPath() throws Exception {
236 192
     Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
237 193
 
@@ -335,26 +291,12 @@ public class CargoTest extends TestCase {
335 291
     assertFalse(cargo.isMisdirected());
336 292
   }
337 293
 
338
-  private Cargo shanghaiSeattleChicagoOnPacific2AndContinental3() {
339
-    Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(SHANGHAI, CHICAGO, toDate("2009-12-24")));
340
-
341
-    // A cargo with no itinerary is not misdirected
342
-    assertFalse(cargo.isMisdirected());
343
-
344
-    Itinerary itinerary = new Itinerary(
345
-        Leg.deriveLeg(pacific2, SHANGHAI, SEATTLE),
346
-        Leg.deriveLeg(continental3, SEATTLE, CHICAGO)
347
-    );
348
-    cargo.assignToRoute(itinerary);
349
-    return cargo;
350
-  }
351
-
352 294
   public void testCustomsClearancePoint() {
353 295
     //cargo destination NYC
354 296
     final Cargo cargo = new Cargo(new TrackingId("XYZ"),
355 297
         new RouteSpecification(SHANGHAI, NEWYORK, new Date()));
356 298
 
357
-    assertThat(cargo.customsClearancePoint(), is(Location.UNKNOWN));
299
+    assertThat(cargo.customsClearancePoint(), is(Location.NONE));
358 300
 
359 301
     //SHA-LGB-NYC
360 302
     cargo.assignToRoute(new Itinerary(
@@ -395,6 +337,20 @@ public class CargoTest extends TestCase {
395 337
 
396 338
   }
397 339
 
340
+  private Cargo shanghaiSeattleChicagoOnPacific2AndContinental3() {
341
+    Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(SHANGHAI, CHICAGO, toDate("2009-12-24")));
342
+
343
+    // A cargo with no itinerary is not misdirected
344
+    assertFalse(cargo.isMisdirected());
345
+
346
+    Itinerary itinerary = new Itinerary(
347
+        Leg.deriveLeg(pacific2, SHANGHAI, SEATTLE),
348
+        Leg.deriveLeg(continental3, SEATTLE, CHICAGO)
349
+    );
350
+    cargo.assignToRoute(itinerary);
351
+    return cargo;
352
+  }
353
+
398 354
   private Cargo setUpCargoWithItinerary(Location origin, Location midpoint, Location destination) {
399 355
     Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(origin, destination, new Date()));
400 356
 
@@ -407,4 +363,48 @@ public class CargoTest extends TestCase {
407 363
     return cargo;
408 364
   }
409 365
 
366
+  private Cargo populateCargoReceivedStockholm() throws Exception {
367
+    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
368
+    cargo.handled(new HandlingActivity(RECEIVE, STOCKHOLM));
369
+    return cargo;
370
+  }
371
+
372
+  private Cargo populateCargoClaimedMelbourne() throws Exception {
373
+    final Cargo cargo = populateCargoOffMelbourne();
374
+
375
+    cargo.handled(new HandlingActivity(CLAIM, MELBOURNE));
376
+    return cargo;
377
+  }
378
+
379
+  private Cargo populateCargoOffHongKong() throws Exception {
380
+    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
381
+
382
+    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
383
+    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
384
+    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
385
+    cargo.handled(new HandlingActivity(UNLOAD, MELBOURNE, crazyVoyage));
386
+    return cargo;
387
+  }
388
+
389
+  private Cargo populateCargoOnHamburg() throws Exception {
390
+    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
391
+
392
+    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
393
+    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
394
+    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
395
+    return cargo;
396
+  }
397
+
398
+  private Cargo populateCargoOffMelbourne() throws Exception {
399
+    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
400
+
401
+    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
402
+    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
403
+    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
404
+    cargo.handled(new HandlingActivity(UNLOAD, MELBOURNE, crazyVoyage));
405
+
406
+    return cargo;
407
+  }
408
+
409
+
410 410
 }

+ 1
- 1
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/DeliveryTest.java Просмотреть файл

@@ -62,7 +62,7 @@ public class DeliveryTest extends TestCase {
62 62
     assertEquals(ROUTED, delivery.routingStatus(itinerary, routeSpecification));
63 63
     assertEquals(Voyage.NONE, delivery.currentVoyage());
64 64
     assertFalse(delivery.onTheGroundAtDestination(routeSpecification));
65
-    assertEquals(Location.UNKNOWN, delivery.lastKnownLocation());
65
+    assertEquals(Location.NONE, delivery.lastKnownLocation());
66 66
     assertEquals(NOT_RECEIVED, delivery.transportStatus());
67 67
     assertTrue(delivery.lastUpdatedOn().before(new Date()));
68 68
   }

+ 2
- 2
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/location/LocationTest.java Просмотреть файл

@@ -24,8 +24,8 @@ public class LocationTest extends TestCase {
24 24
     // Never equal to null
25 25
     assertFalse(location.equals(null));
26 26
 
27
-    // Special UNKNOWN location is equal to itself
28
-    assertTrue(Location.UNKNOWN.equals(Location.UNKNOWN));
27
+    // Special NONE location is equal to itself
28
+    assertTrue(Location.NONE.equals(Location.NONE));
29 29
 
30 30
     try {
31 31
       new Location(null, null, null, null);