Sfoglia il codice sorgente

Convert JUnit assertions to AssertJ

 - We used "convert-junit-assertions-to-assertj.sh" script to launch the automatic conversion.
 - The auto conversion of  assertEquals(<List>, <List>) was wrong.
 - assertThat(result.get("REGISTRATIONTIME")).isEqualTo(new Date(20)) in HandlingEventRepositoryTest.java (in the testSave method) throw an exception, because equals call isn't symmetric between java.util.Date and java.sql.Timestamp. AssertJ and Junit equality assertion doesn't call equals method in the same way. One invoke expected.equals(actual) and the other actual.equals(expected).
Mohamed Gara 9 anni fa
parent
commit
38cb39df51
29 ha cambiato i file con 402 aggiunte e 345 eliminazioni
  1. 6
    0
      pom.xml
  2. 6
    4
      src/test/java/se/citerus/dddsample/application/BookingServiceTest.java
  3. 32
    30
      src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java
  4. 18
    16
      src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java
  5. 14
    12
      src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java
  6. 8
    6
      src/test/java/se/citerus/dddsample/domain/model/cargo/RouteSpecificationTest.java
  7. 18
    16
      src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java
  8. 23
    21
      src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java
  9. 7
    5
      src/test/java/se/citerus/dddsample/domain/model/handling/HandlingHistoryTest.java
  10. 9
    7
      src/test/java/se/citerus/dddsample/domain/model/location/LocationTest.java
  11. 9
    7
      src/test/java/se/citerus/dddsample/domain/model/location/UnLocodeTest.java
  12. 13
    11
      src/test/java/se/citerus/dddsample/domain/model/voyage/CarrierMovementTest.java
  13. 6
    4
      src/test/java/se/citerus/dddsample/domain/shared/AndSpecificationTest.java
  14. 4
    2
      src/test/java/se/citerus/dddsample/domain/shared/NotSpecificationTest.java
  15. 6
    4
      src/test/java/se/citerus/dddsample/domain/shared/OrSpecificationTest.java
  16. 8
    6
      src/test/java/se/citerus/dddsample/domain/shared/experimental/ValueObjectSupportTest.java
  17. 31
    27
      src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java
  18. 7
    8
      src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CarrierMovementRepositoryTest.java
  19. 11
    7
      src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java
  20. 6
    6
      src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/LocationRepositoryTest.java
  21. 10
    8
      src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java
  22. 15
    13
      src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/CargoRoutingDTOAssemblerTest.java
  23. 21
    19
      src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/ItineraryCandidateDTOAssemblerTest.java
  24. 9
    7
      src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/LocationDTOAssemblerTest.java
  25. 9
    9
      src/test/java/se/citerus/dddsample/interfaces/booking/web/ItinerarySelectionCommandTest.java
  26. 5
    5
      src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java
  27. 23
    21
      src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingViewAdapterTest.java
  28. 7
    5
      src/test/java/se/citerus/dddsample/interfaces/tracking/TrackCommandValidatorTest.java
  29. 61
    59
      src/test/java/se/citerus/dddsample/scenario/CargoLifecycleScenarioTest.java

+ 6
- 0
pom.xml Vedi File

70
     <!-- Dependencies -->
70
     <!-- Dependencies -->
71
     <spring.version>4.2.1.RELEASE</spring.version>
71
     <spring.version>4.2.1.RELEASE</spring.version>
72
     <cxf.version>3.0.3</cxf.version>
72
     <cxf.version>3.0.3</cxf.version>
73
+    <assertj.version>3.8.0</assertj.version>
73
     <!-- Plugin versions -->
74
     <!-- Plugin versions -->
74
     <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
75
     <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
75
     <maven-jar-plugin.version>2.6</maven-jar-plugin.version>
76
     <maven-jar-plugin.version>2.6</maven-jar-plugin.version>
141
       <scope>test</scope>
142
       <scope>test</scope>
142
     </dependency>
143
     </dependency>
143
     <dependency>
144
     <dependency>
145
+      <groupId>org.assertj</groupId>
146
+      <artifactId>assertj-core</artifactId>
147
+      <version>${assertj.version}</version>
148
+    </dependency>
149
+    <dependency>
144
       <groupId>org.springframework</groupId>
150
       <groupId>org.springframework</groupId>
145
       <artifactId>spring-webmvc</artifactId>
151
       <artifactId>spring-webmvc</artifactId>
146
       <version>${spring.version}</version>
152
       <version>${spring.version}</version>

+ 6
- 4
src/test/java/se/citerus/dddsample/application/BookingServiceTest.java Vedi File

1
 package se.citerus.dddsample.application;
1
 package se.citerus.dddsample.application;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
 import se.citerus.dddsample.application.impl.BookingServiceImpl;
4
 import se.citerus.dddsample.application.impl.BookingServiceImpl;
6
 import se.citerus.dddsample.domain.model.cargo.Cargo;
5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
7
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
6
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
8
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
9
 import se.citerus.dddsample.domain.model.location.LocationRepository;
8
 import se.citerus.dddsample.domain.model.location.LocationRepository;
10
-import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
11
-import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
12
 import se.citerus.dddsample.domain.model.location.UnLocode;
9
 import se.citerus.dddsample.domain.model.location.UnLocode;
13
 import se.citerus.dddsample.domain.service.RoutingService;
10
 import se.citerus.dddsample.domain.service.RoutingService;
14
 
11
 
15
 import java.util.Date;
12
 import java.util.Date;
16
 
13
 
14
+import static org.assertj.core.api.Assertions.assertThat;
15
+import static org.easymock.EasyMock.*;
16
+import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
17
+import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
18
+
17
 public class BookingServiceTest extends TestCase {
19
 public class BookingServiceTest extends TestCase {
18
 
20
 
19
   BookingServiceImpl bookingService;
21
   BookingServiceImpl bookingService;
42
     replay(cargoRepository, locationRepository);
44
     replay(cargoRepository, locationRepository);
43
 
45
 
44
     TrackingId trackingId = bookingService.bookNewCargo(fromUnlocode, toUnlocode, new Date());
46
     TrackingId trackingId = bookingService.bookNewCargo(fromUnlocode, toUnlocode, new Date());
45
-    assertEquals(expectedTrackingId, trackingId);
47
+    assertThat(trackingId).isEqualTo(expectedTrackingId);
46
   }
48
   }
47
 
49
 
48
   protected void tearDown() throws Exception {
50
   protected void tearDown() throws Exception {

+ 32
- 30
src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 import se.citerus.dddsample.application.util.DateTestUtil;
4
 import se.citerus.dddsample.application.util.DateTestUtil;
5
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
6
-import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
7
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
5
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
8
 import se.citerus.dddsample.domain.model.handling.HandlingHistory;
6
 import se.citerus.dddsample.domain.model.handling.HandlingHistory;
9
 import se.citerus.dddsample.domain.model.location.Location;
7
 import se.citerus.dddsample.domain.model.location.Location;
10
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
11
 import se.citerus.dddsample.domain.model.voyage.Voyage;
8
 import se.citerus.dddsample.domain.model.voyage.Voyage;
12
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
9
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
13
 
10
 
16
 import java.text.SimpleDateFormat;
13
 import java.text.SimpleDateFormat;
17
 import java.util.*;
14
 import java.util.*;
18
 
15
 
16
+import static org.assertj.core.api.Assertions.assertThat;
17
+import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
18
+import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
19
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
20
+
19
 public class CargoTest extends TestCase {
21
 public class CargoTest extends TestCase {
20
 
22
 
21
   private List<HandlingEvent> events;
23
   private List<HandlingEvent> events;
40
 
42
 
41
     final Cargo cargo = new Cargo(trackingId, routeSpecification);
43
     final Cargo cargo = new Cargo(trackingId, routeSpecification);
42
 
44
 
43
-    assertEquals(NOT_ROUTED, cargo.delivery().routingStatus());
44
-    assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
45
-    assertEquals(Location.UNKNOWN, cargo.delivery().lastKnownLocation());
46
-    assertEquals(Voyage.NONE, cargo.delivery().currentVoyage());    
45
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(NOT_ROUTED);
46
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(NOT_RECEIVED);
47
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(Location.UNKNOWN);
48
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(Voyage.NONE);    
47
   }
49
   }
48
 
50
 
49
   public void testRoutingStatus() throws Exception {
51
   public void testRoutingStatus() throws Exception {
59
 
61
 
60
     cargo.specifyNewRoute(acceptOnlyGood);
62
     cargo.specifyNewRoute(acceptOnlyGood);
61
 
63
 
62
-    assertEquals(NOT_ROUTED, cargo.delivery().routingStatus());
64
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(NOT_ROUTED);
63
     
65
     
64
     cargo.assignToRoute(bad);
66
     cargo.assignToRoute(bad);
65
-    assertEquals(MISROUTED, cargo.delivery().routingStatus());
67
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(MISROUTED);
66
 
68
 
67
     cargo.assignToRoute(good);
69
     cargo.assignToRoute(good);
68
-    assertEquals(ROUTED, cargo.delivery().routingStatus());
70
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(ROUTED);
69
   }
71
   }
70
 
72
 
71
   public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
73
   public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
72
     Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
74
     Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
73
 
75
 
74
-    assertEquals(Location.UNKNOWN, cargo.delivery().lastKnownLocation());
76
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(Location.UNKNOWN);
75
   }
77
   }
76
 
78
 
77
   public void testlastKnownLocationReceived() throws Exception {
79
   public void testlastKnownLocationReceived() throws Exception {
78
     Cargo cargo = populateCargoReceivedStockholm();
80
     Cargo cargo = populateCargoReceivedStockholm();
79
 
81
 
80
-    assertEquals(STOCKHOLM, cargo.delivery().lastKnownLocation());
82
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(STOCKHOLM);
81
   }
83
   }
82
 
84
 
83
   public void testlastKnownLocationClaimed() throws Exception {
85
   public void testlastKnownLocationClaimed() throws Exception {
84
     Cargo cargo = populateCargoClaimedMelbourne();
86
     Cargo cargo = populateCargoClaimedMelbourne();
85
 
87
 
86
-    assertEquals(MELBOURNE, cargo.delivery().lastKnownLocation());
88
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(MELBOURNE);
87
   }
89
   }
88
 
90
 
89
   public void testlastKnownLocationUnloaded() throws Exception {
91
   public void testlastKnownLocationUnloaded() throws Exception {
90
     Cargo cargo = populateCargoOffHongKong();
92
     Cargo cargo = populateCargoOffHongKong();
91
 
93
 
92
-    assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
94
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HONGKONG);
93
   }
95
   }
94
 
96
 
95
   public void testlastKnownLocationloaded() throws Exception {
97
   public void testlastKnownLocationloaded() throws Exception {
96
     Cargo cargo = populateCargoOnHamburg();
98
     Cargo cargo = populateCargoOnHamburg();
97
 
99
 
98
-    assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
100
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HAMBURG);
99
   }
101
   }
100
 
102
 
101
   public void testEquality() throws Exception {
103
   public void testEquality() throws Exception {
106
     Cargo c3 = new Cargo(new TrackingId("ABC"), spec2);
108
     Cargo c3 = new Cargo(new TrackingId("ABC"), spec2);
107
     Cargo c4 = new Cargo(new TrackingId("ABC"), spec1);
109
     Cargo c4 = new Cargo(new TrackingId("ABC"), spec1);
108
 
110
 
109
-    assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c4));
110
-    assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c3));
111
-    assertTrue("Cargos should be equal when TrackingIDs are equal", c3.equals(c4));
112
-    assertFalse("Cargos are not equal when TrackingID differ", c1.equals(c2));
111
+    assertThat(c1.equals(c4)).as("Cargos should be equal when TrackingIDs are equal").isTrue();
112
+    assertThat(c1.equals(c3)).as("Cargos should be equal when TrackingIDs are equal").isTrue();
113
+    assertThat(c3.equals(c4)).as("Cargos should be equal when TrackingIDs are equal").isTrue();
114
+    assertThat(c1.equals(c2)).as("Cargos are not equal when TrackingID differ").isFalse();
113
   }
115
   }
114
 
116
 
115
   public void testIsUnloadedAtFinalDestination() throws Exception {
117
   public void testIsUnloadedAtFinalDestination() throws Exception {
116
     Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
118
     Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
117
-    assertFalse(cargo.delivery().isUnloadedAtDestination());
119
+    assertThat(cargo.delivery().isUnloadedAtDestination()).isFalse();
118
 
120
 
119
     // Adding an event unrelated to unloading at final destination
121
     // Adding an event unrelated to unloading at final destination
120
     events.add(
122
     events.add(
121
       new HandlingEvent(cargo, new Date(10), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
123
       new HandlingEvent(cargo, new Date(10), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
122
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
124
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
123
-    assertFalse(cargo.delivery().isUnloadedAtDestination());
125
+    assertThat(cargo.delivery().isUnloadedAtDestination()).isFalse();
124
 
126
 
125
     Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
127
     Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
126
       addMovement(NEWYORK, new Date(), new Date()).
128
       addMovement(NEWYORK, new Date(), new Date()).
130
     events.add(
132
     events.add(
131
       new HandlingEvent(cargo, new Date(20), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, voyage));
133
       new HandlingEvent(cargo, new Date(20), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, voyage));
132
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
134
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
133
-    assertFalse(cargo.delivery().isUnloadedAtDestination());
135
+    assertThat(cargo.delivery().isUnloadedAtDestination()).isFalse();
134
 
136
 
135
     // Adding an event in the final destination, but not unload
137
     // Adding an event in the final destination, but not unload
136
     events.add(
138
     events.add(
137
       new HandlingEvent(cargo, new Date(30), new Date(), HandlingEvent.Type.CUSTOMS, NEWYORK));
139
       new HandlingEvent(cargo, new Date(30), new Date(), HandlingEvent.Type.CUSTOMS, NEWYORK));
138
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
140
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
139
-    assertFalse(cargo.delivery().isUnloadedAtDestination());
141
+    assertThat(cargo.delivery().isUnloadedAtDestination()).isFalse();
140
 
142
 
141
     // Finally, cargo is unloaded at final destination
143
     // Finally, cargo is unloaded at final destination
142
     events.add(
144
     events.add(
143
       new HandlingEvent(cargo, new Date(40), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, voyage));
145
       new HandlingEvent(cargo, new Date(40), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, voyage));
144
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
146
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
145
-    assertTrue(cargo.delivery().isUnloadedAtDestination());
147
+    assertThat(cargo.delivery().isUnloadedAtDestination()).isTrue();
146
   }
148
   }
147
 
149
 
148
   // TODO: Generate test data some better way
150
   // TODO: Generate test data some better way
224
   public void testIsMisdirected() throws Exception {
226
   public void testIsMisdirected() throws Exception {
225
     //A cargo with no itinerary is not misdirected
227
     //A cargo with no itinerary is not misdirected
226
     Cargo cargo = new Cargo(new TrackingId("TRKID"), new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
228
     Cargo cargo = new Cargo(new TrackingId("TRKID"), new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
227
-    assertFalse(cargo.delivery().isMisdirected());
229
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
228
 
230
 
229
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
231
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
230
 
232
 
231
     //A cargo with no handling events is not misdirected
233
     //A cargo with no handling events is not misdirected
232
-    assertFalse(cargo.delivery().isMisdirected());
234
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
233
 
235
 
234
     Collection<HandlingEvent> handlingEvents = new ArrayList<HandlingEvent>();
236
     Collection<HandlingEvent> handlingEvents = new ArrayList<HandlingEvent>();
235
 
237
 
244
 
246
 
245
     events.addAll(handlingEvents);
247
     events.addAll(handlingEvents);
246
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
248
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
247
-    assertFalse(cargo.delivery().isMisdirected());
249
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
248
 
250
 
249
     //Try a couple of failing ones
251
     //Try a couple of failing ones
250
 
252
 
255
     events.addAll(handlingEvents);
257
     events.addAll(handlingEvents);
256
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
258
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
257
 
259
 
258
-    assertTrue(cargo.delivery().isMisdirected());
260
+    assertThat(cargo.delivery().isMisdirected()).isTrue();
259
 
261
 
260
 
262
 
261
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
263
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
269
     events.addAll(handlingEvents);
271
     events.addAll(handlingEvents);
270
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
272
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
271
 
273
 
272
-    assertTrue(cargo.delivery().isMisdirected());
274
+    assertThat(cargo.delivery().isMisdirected()).isTrue();
273
 
275
 
274
 
276
 
275
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
277
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
283
     events.addAll(handlingEvents);
285
     events.addAll(handlingEvents);
284
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
286
     cargo.deriveDeliveryProgress(new HandlingHistory(events));
285
 
287
 
286
-    assertTrue(cargo.delivery().isMisdirected());
288
+    assertThat(cargo.delivery().isMisdirected()).isTrue();
287
   }
289
   }
288
 
290
 
289
   private Cargo setUpCargoWithItinerary(Location origin, Location midpoint, Location destination) {
291
   private Cargo setUpCargoWithItinerary(Location origin, Location midpoint, Location destination) {

+ 18
- 16
src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java Vedi File

1
 package se.citerus.dddsample.domain.model.cargo;
1
 package se.citerus.dddsample.domain.model.cargo;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;
6
 
4
 
7
 import java.util.Date;
5
 import java.util.Date;
8
 
6
 
7
+import static org.assertj.core.api.Assertions.assertThat;
8
+import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
9
+import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;
10
+
9
 public class DeliveryTest extends TestCase {
11
 public class DeliveryTest extends TestCase {
10
 
12
 
11
   private Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, NEWYORK, new Date()));
13
   private Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, NEWYORK, new Date()));
12
 
14
 
13
   public void testToSilenceWarnings() throws Exception {
15
   public void testToSilenceWarnings() throws Exception {
14
-    assertTrue(true);
16
+    assertThat(true).isTrue();
15
   }
17
   }
16
   
18
   
17
   /*
19
   /*
24
     Delivery dh = new Delivery(Arrays.asList(he1, he2, he3, he4));
26
     Delivery dh = new Delivery(Arrays.asList(he1, he2, he3, he4));
25
 
27
 
26
     List<HandlingEvent> orderEvents = dh.history();
28
     List<HandlingEvent> orderEvents = dh.history();
27
-    assertEquals(4, orderEvents.size());
28
-    assertSame(he2, orderEvents.get(0));
29
-    assertSame(he4, orderEvents.get(1));
30
-    assertSame(he1, orderEvents.get(2));
31
-    assertSame(he3, orderEvents.get(3));
29
+    assertThat(orderEvents).hasSize(4);
30
+    assertThat(orderEvents.get(0)).isSameAs(he2);
31
+    assertThat(orderEvents.get(1)).isSameAs(he4);
32
+    assertThat(orderEvents.get(2)).isSameAs(he1);
33
+    assertThat(orderEvents.get(3)).isSameAs(he3);
32
   }
34
   }
33
 
35
 
34
   public void testCargoStatusFromLastHandlingEvent() {
36
   public void testCargoStatusFromLastHandlingEvent() {
35
     Set<HandlingEvent> events = new HashSet<HandlingEvent>();
37
     Set<HandlingEvent> events = new HashSet<HandlingEvent>();
36
     Delivery delivery = new Delivery(events);
38
     Delivery delivery = new Delivery(events);
37
 
39
 
38
-    assertEquals(TransportStatus.NOT_RECEIVED, delivery.transportStatus());
40
+    assertThat(delivery.transportStatus()).isEqualTo(TransportStatus.NOT_RECEIVED);
39
 
41
 
40
     events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
42
     events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
41
     delivery = new Delivery(events);
43
     delivery = new Delivery(events);
42
-    assertEquals(TransportStatus.IN_PORT, delivery.transportStatus());
44
+    assertThat(delivery.transportStatus()).isEqualTo(TransportStatus.IN_PORT);
43
 
45
 
44
     events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, CM005));
46
     events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, CM005));
45
     delivery = new Delivery(events);
47
     delivery = new Delivery(events);
46
-    assertEquals(TransportStatus.ONBOARD_CARRIER, delivery.transportStatus());
48
+    assertThat(delivery.transportStatus()).isEqualTo(TransportStatus.ONBOARD_CARRIER);
47
 
49
 
48
     events.add(new HandlingEvent(cargo, new Date(30), new Date(31), HandlingEvent.Type.UNLOAD, HAMBURG, CM006));
50
     events.add(new HandlingEvent(cargo, new Date(30), new Date(31), HandlingEvent.Type.UNLOAD, HAMBURG, CM006));
49
     delivery = new Delivery(events);
51
     delivery = new Delivery(events);
50
-    assertEquals(TransportStatus.IN_PORT, delivery.transportStatus());
52
+    assertThat(delivery.transportStatus()).isEqualTo(TransportStatus.IN_PORT);
51
 
53
 
52
     events.add(new HandlingEvent(cargo, new Date(40), new Date(41), HandlingEvent.Type.CLAIM, HAMBURG));
54
     events.add(new HandlingEvent(cargo, new Date(40), new Date(41), HandlingEvent.Type.CLAIM, HAMBURG));
53
     delivery = new Delivery(events);
55
     delivery = new Delivery(events);
54
-    assertEquals(TransportStatus.CLAIMED, delivery.transportStatus());
56
+    assertThat(delivery.transportStatus()).isEqualTo(TransportStatus.CLAIMED);
55
   }
57
   }
56
 
58
 
57
   public void testLastKnownLocation() throws Exception {
59
   public void testLastKnownLocation() throws Exception {
58
     Set<HandlingEvent> events = new HashSet<HandlingEvent>();
60
     Set<HandlingEvent> events = new HashSet<HandlingEvent>();
59
     Delivery delivery = new Delivery(events);
61
     Delivery delivery = new Delivery(events);
60
 
62
 
61
-    assertEquals(Location.UNKNOWN, delivery.lastKnownLocation());
63
+    assertThat(delivery.lastKnownLocation()).isEqualTo(Location.UNKNOWN);
62
 
64
 
63
     events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
65
     events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
64
     delivery = new Delivery(events);
66
     delivery = new Delivery(events);
65
 
67
 
66
-    assertEquals(HAMBURG, delivery.lastKnownLocation());
68
+    assertThat(delivery.lastKnownLocation()).isEqualTo(HAMBURG);
67
 
69
 
68
     events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, CM003));
70
     events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, CM003));
69
     delivery = new Delivery(events);
71
     delivery = new Delivery(events);
70
 
72
 
71
-    assertEquals(HAMBURG, delivery.lastKnownLocation());
73
+    assertThat(delivery.lastKnownLocation()).isEqualTo(HAMBURG);
72
   }
74
   }
73
   */
75
   */
74
   
76
   

+ 14
- 12
src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
4
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
6
 import se.citerus.dddsample.domain.model.voyage.CarrierMovement;
5
 import se.citerus.dddsample.domain.model.voyage.CarrierMovement;
7
 import se.citerus.dddsample.domain.model.voyage.Voyage;
6
 import se.citerus.dddsample.domain.model.voyage.Voyage;
8
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
7
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
12
 import java.util.Date;
11
 import java.util.Date;
13
 import java.util.List;
12
 import java.util.List;
14
 
13
 
14
+import static org.assertj.core.api.Assertions.assertThat;
15
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
16
+
15
 public class ItineraryTest extends TestCase {
17
 public class ItineraryTest extends TestCase {
16
   private final CarrierMovement abc = new CarrierMovement(SHANGHAI, ROTTERDAM, new Date(), new Date());
18
   private final CarrierMovement abc = new CarrierMovement(SHANGHAI, ROTTERDAM, new Date(), new Date());
17
   private final CarrierMovement def = new CarrierMovement(ROTTERDAM, GOTHENBURG, new Date(), new Date());
19
   private final CarrierMovement def = new CarrierMovement(ROTTERDAM, GOTHENBURG, new Date(), new Date());
47
 
49
 
48
     //Happy path
50
     //Happy path
49
     HandlingEvent event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, SHANGHAI);
51
     HandlingEvent event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, SHANGHAI);
50
-    assertTrue(itinerary.isExpected(event));
52
+    assertThat(itinerary.isExpected(event)).isTrue();
51
 
53
 
52
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, SHANGHAI, voyage);
54
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, SHANGHAI, voyage);
53
-    assertTrue(itinerary.isExpected(event));
55
+    assertThat(itinerary.isExpected(event)).isTrue();
54
 
56
 
55
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, ROTTERDAM, voyage);
57
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, ROTTERDAM, voyage);
56
-    assertTrue(itinerary.isExpected(event));
58
+    assertThat(itinerary.isExpected(event)).isTrue();
57
 
59
 
58
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, voyage);
60
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, voyage);
59
-    assertTrue(itinerary.isExpected(event));
61
+    assertThat(itinerary.isExpected(event)).isTrue();
60
 
62
 
61
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, GOTHENBURG, voyage);
63
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, GOTHENBURG, voyage);
62
-    assertTrue(itinerary.isExpected(event));
64
+    assertThat(itinerary.isExpected(event)).isTrue();
63
 
65
 
64
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, GOTHENBURG);
66
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, GOTHENBURG);
65
-    assertTrue(itinerary.isExpected(event));
67
+    assertThat(itinerary.isExpected(event)).isTrue();
66
 
68
 
67
     //Customs event changes nothing
69
     //Customs event changes nothing
68
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CUSTOMS, GOTHENBURG);
70
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CUSTOMS, GOTHENBURG);
69
-    assertTrue(itinerary.isExpected(event));
71
+    assertThat(itinerary.isExpected(event)).isTrue();
70
 
72
 
71
     //Received at the wrong location
73
     //Received at the wrong location
72
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU);
74
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU);
73
-    assertFalse(itinerary.isExpected(event));
75
+    assertThat(itinerary.isExpected(event)).isFalse();
74
 
76
 
75
     //Loaded to onto the wrong ship, correct location
77
     //Loaded to onto the wrong ship, correct location
76
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, wrongVoyage);
78
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, wrongVoyage);
77
-    assertFalse(itinerary.isExpected(event));
79
+    assertThat(itinerary.isExpected(event)).isFalse();
78
 
80
 
79
     //Unloaded from the wrong ship in the wrong location
81
     //Unloaded from the wrong ship in the wrong location
80
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, HELSINKI, wrongVoyage);
82
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, HELSINKI, wrongVoyage);
81
-    assertFalse(itinerary.isExpected(event));
83
+    assertThat(itinerary.isExpected(event)).isFalse();
82
 
84
 
83
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, ROTTERDAM);
85
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, ROTTERDAM);
84
-    assertFalse(itinerary.isExpected(event));
86
+    assertThat(itinerary.isExpected(event)).isFalse();
85
 
87
 
86
   }
88
   }
87
 
89
 

+ 8
- 6
src/test/java/se/citerus/dddsample/domain/model/cargo/RouteSpecificationTest.java Vedi File

1
 package se.citerus.dddsample.domain.model.cargo;
1
 package se.citerus.dddsample.domain.model.cargo;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
6
 import se.citerus.dddsample.domain.model.voyage.Voyage;
4
 import se.citerus.dddsample.domain.model.voyage.Voyage;
7
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
5
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
8
 
6
 
9
 import java.util.Arrays;
7
 import java.util.Arrays;
10
 
8
 
9
+import static org.assertj.core.api.Assertions.assertThat;
10
+import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
11
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
12
+
11
 public class RouteSpecificationTest extends TestCase {
13
 public class RouteSpecificationTest extends TestCase {
12
 
14
 
13
   final Voyage hongKongTokyoNewYork = new Voyage.Builder(
15
   final Voyage hongKongTokyoNewYork = new Voyage.Builder(
38
       HONGKONG, CHICAGO, toDate("2009-03-01")
40
       HONGKONG, CHICAGO, toDate("2009-03-01")
39
     );
41
     );
40
 
42
 
41
-    assertTrue(routeSpecification.isSatisfiedBy(itinerary));
43
+    assertThat(routeSpecification.isSatisfiedBy(itinerary)).isTrue();
42
   }
44
   }
43
 
45
 
44
   public void testIsSatisfiedBy_WrongOrigin() {
46
   public void testIsSatisfiedBy_WrongOrigin() {
46
       HANGZOU, CHICAGO, toDate("2009-03-01")
48
       HANGZOU, CHICAGO, toDate("2009-03-01")
47
     );
49
     );
48
 
50
 
49
-    assertFalse(routeSpecification.isSatisfiedBy(itinerary));
51
+    assertThat(routeSpecification.isSatisfiedBy(itinerary)).isFalse();
50
   }
52
   }
51
 
53
 
52
   public void testIsSatisfiedBy_WrongDestination() {
54
   public void testIsSatisfiedBy_WrongDestination() {
54
       HONGKONG, DALLAS, toDate("2009-03-01")
56
       HONGKONG, DALLAS, toDate("2009-03-01")
55
     );
57
     );
56
 
58
 
57
-    assertFalse(routeSpecification.isSatisfiedBy(itinerary));
59
+    assertThat(routeSpecification.isSatisfiedBy(itinerary)).isFalse();
58
   }
60
   }
59
 
61
 
60
   public void testIsSatisfiedBy_MissedDeadline() {
62
   public void testIsSatisfiedBy_MissedDeadline() {
62
       HONGKONG, CHICAGO, toDate("2009-02-15")
64
       HONGKONG, CHICAGO, toDate("2009-02-15")
63
     );
65
     );
64
 
66
 
65
-    assertFalse(routeSpecification.isSatisfiedBy(itinerary));
67
+    assertThat(routeSpecification.isSatisfiedBy(itinerary)).isFalse();
66
   }
68
   }
67
 
69
 
68
 }
70
 }

+ 18
- 16
src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java Vedi File

1
 package se.citerus.dddsample.domain.model.handling;
1
 package se.citerus.dddsample.domain.model.handling;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
4
 import se.citerus.dddsample.domain.model.cargo.Cargo;
6
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
5
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
7
 import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
6
 import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
8
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
9
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type;
10
 import se.citerus.dddsample.domain.model.location.LocationRepository;
8
 import se.citerus.dddsample.domain.model.location.LocationRepository;
11
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
12
 import se.citerus.dddsample.domain.model.location.UnLocode;
9
 import se.citerus.dddsample.domain.model.location.UnLocode;
13
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
14
 import se.citerus.dddsample.domain.model.voyage.Voyage;
10
 import se.citerus.dddsample.domain.model.voyage.Voyage;
15
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
11
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
16
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
12
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
19
 
15
 
20
 import java.util.Date;
16
 import java.util.Date;
21
 
17
 
18
+import static org.assertj.core.api.Assertions.assertThat;
19
+import static org.easymock.EasyMock.*;
20
+import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type;
21
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
22
+import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
23
+
22
 public class HandlingEventFactoryTest extends TestCase {
24
 public class HandlingEventFactoryTest extends TestCase {
23
 
25
 
24
   HandlingEventFactory factory;
26
   HandlingEventFactory factory;
53
       new Date(), new Date(100), trackingId, voyageNumber, unLocode, Type.LOAD
55
       new Date(), new Date(100), trackingId, voyageNumber, unLocode, Type.LOAD
54
     );
56
     );
55
 
57
 
56
-    assertNotNull(handlingEvent);
57
-    assertEquals(STOCKHOLM, handlingEvent.location());
58
-    assertEquals(CM001, handlingEvent.voyage());
59
-    assertEquals(cargo, handlingEvent.cargo());
60
-    assertEquals(new Date(100), handlingEvent.completionTime());
61
-    assertTrue(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1)));
58
+    assertThat(handlingEvent).isNotNull();
59
+    assertThat(handlingEvent.location()).isEqualTo(STOCKHOLM);
60
+    assertThat(handlingEvent.voyage()).isEqualTo(CM001);
61
+    assertThat(handlingEvent.cargo()).isEqualTo(cargo);
62
+    assertThat(handlingEvent.completionTime()).isEqualTo(new Date(100));
63
+    assertThat(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1))).isTrue();
62
   }
64
   }
63
 
65
 
64
   public void testCreateHandlingEventWithoutCarrierMovement() throws Exception {
66
   public void testCreateHandlingEventWithoutCarrierMovement() throws Exception {
71
       new Date(), new Date(100), trackingId, null, unLocode, Type.CLAIM
73
       new Date(), new Date(100), trackingId, null, unLocode, Type.CLAIM
72
     );
74
     );
73
 
75
 
74
-    assertNotNull(handlingEvent);
75
-    assertEquals(STOCKHOLM, handlingEvent.location());
76
-    assertEquals(Voyage.NONE, handlingEvent.voyage());
77
-    assertEquals(cargo, handlingEvent.cargo());
78
-    assertEquals(new Date(100), handlingEvent.completionTime());
79
-    assertTrue(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1)));
76
+    assertThat(handlingEvent).isNotNull();
77
+    assertThat(handlingEvent.location()).isEqualTo(STOCKHOLM);
78
+    assertThat(handlingEvent.voyage()).isEqualTo(Voyage.NONE);
79
+    assertThat(handlingEvent.cargo()).isEqualTo(cargo);
80
+    assertThat(handlingEvent.completionTime()).isEqualTo(new Date(100));
81
+    assertThat(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1))).isTrue();
80
   }
82
   }
81
 
83
 
82
   public void testCreateHandlingEventUnknownLocation() throws Exception {
84
   public void testCreateHandlingEventUnknownLocation() throws Exception {

+ 23
- 21
src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java Vedi File

4
 import se.citerus.dddsample.domain.model.cargo.Cargo;
4
 import se.citerus.dddsample.domain.model.cargo.Cargo;
5
 import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
5
 import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
6
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
6
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
+import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
8
+
9
+import java.util.Date;
10
+
11
+import static java.util.Arrays.asList;
12
+import static org.assertj.core.api.Assertions.assertThat;
7
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
13
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
8
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
14
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
9
-import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
10
 import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM003;
15
 import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM003;
11
 import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM004;
16
 import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM004;
12
 
17
 
13
-import static java.util.Arrays.asList;
14
-import java.util.Date;
15
-
16
 public class HandlingEventTest extends TestCase {
18
 public class HandlingEventTest extends TestCase {
17
   private Cargo cargo;
19
   private Cargo cargo;
18
 
20
 
25
   public void testNewWithCarrierMovement() throws Exception {
27
   public void testNewWithCarrierMovement() throws Exception {
26
 
28
 
27
     HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, HONGKONG, CM003);
29
     HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, HONGKONG, CM003);
28
-    assertEquals(HONGKONG, e1.location());
30
+    assertThat(e1.location()).isEqualTo(HONGKONG);
29
 
31
 
30
     HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, NEWYORK, CM003);
32
     HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, NEWYORK, CM003);
31
-    assertEquals(NEWYORK, e2.location());
33
+    assertThat(e2.location()).isEqualTo(NEWYORK);
32
 
34
 
33
       // These event types prohibit a carrier movement association
35
       // These event types prohibit a carrier movement association
34
     for (HandlingEvent.Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
36
     for (HandlingEvent.Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
49
 
51
 
50
   public void testNewWithLocation() throws Exception {
52
   public void testNewWithLocation() throws Exception {
51
     HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, HELSINKI);
53
     HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, HELSINKI);
52
-    assertEquals(HELSINKI, e1.location());
54
+    assertThat(e1.location()).isEqualTo(HELSINKI);
53
   }
55
   }
54
 
56
 
55
   public void testCurrentLocationLoadEvent() throws Exception {
57
   public void testCurrentLocationLoadEvent() throws Exception {
56
 
58
 
57
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, CM004);
59
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, CM004);
58
     
60
     
59
-    assertEquals(CHICAGO, ev.location());
61
+    assertThat(ev.location()).isEqualTo(CHICAGO);
60
   }
62
   }
61
   
63
   
62
   public void testCurrentLocationUnloadEvent() throws Exception {
64
   public void testCurrentLocationUnloadEvent() throws Exception {
63
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, CM004);
65
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, CM004);
64
     
66
     
65
-    assertEquals(HAMBURG, ev.location());
67
+    assertThat(ev.location()).isEqualTo(HAMBURG);
66
   }
68
   }
67
   
69
   
68
   public void testCurrentLocationReceivedEvent() throws Exception {
70
   public void testCurrentLocationReceivedEvent() throws Exception {
69
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), RECEIVE, CHICAGO);
71
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), RECEIVE, CHICAGO);
70
 
72
 
71
-    assertEquals(CHICAGO, ev.location());
73
+    assertThat(ev.location()).isEqualTo(CHICAGO);
72
   }
74
   }
73
   public void testCurrentLocationClaimedEvent() throws Exception {
75
   public void testCurrentLocationClaimedEvent() throws Exception {
74
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), CLAIM, CHICAGO);
76
     HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), CLAIM, CHICAGO);
75
 
77
 
76
-    assertEquals(CHICAGO, ev.location());
78
+    assertThat(ev.location()).isEqualTo(CHICAGO);
77
   }
79
   }
78
   
80
   
79
   public void testParseType() throws Exception {
81
   public void testParseType() throws Exception {
80
-    assertEquals(CLAIM, valueOf("CLAIM"));
81
-    assertEquals(LOAD, valueOf("LOAD"));
82
-    assertEquals(UNLOAD, valueOf("UNLOAD"));
83
-    assertEquals(RECEIVE, valueOf("RECEIVE"));
82
+    assertThat(valueOf("CLAIM")).isEqualTo(CLAIM);
83
+    assertThat(valueOf("LOAD")).isEqualTo(LOAD);
84
+    assertThat(valueOf("UNLOAD")).isEqualTo(UNLOAD);
85
+    assertThat(valueOf("RECEIVE")).isEqualTo(RECEIVE);
84
   }
86
   }
85
   
87
   
86
   public void testParseTypeIllegal() throws Exception {
88
   public void testParseTypeIllegal() throws Exception {
87
     try {
89
     try {
88
       valueOf("NOT_A_HANDLING_EVENT_TYPE");
90
       valueOf("NOT_A_HANDLING_EVENT_TYPE");
89
-      assertTrue("Expected IllegaArgumentException to be thrown", false);
91
+      assertThat(false).as("Expected IllegaArgumentException to be thrown").isTrue();
90
     } catch (IllegalArgumentException e) {
92
     } catch (IllegalArgumentException e) {
91
       // All's well
93
       // All's well
92
     }
94
     }
100
     HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
102
     HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
101
 
103
 
102
     // Two handling events are not equal() even if all non-uuid fields are identical
104
     // Two handling events are not equal() even if all non-uuid fields are identical
103
-    assertTrue(ev1.equals(ev2));
104
-    assertTrue(ev2.equals(ev1));
105
+    assertThat(ev1.equals(ev2)).isTrue();
106
+    assertThat(ev2.equals(ev1)).isTrue();
105
 
107
 
106
-    assertTrue(ev1.equals(ev1));
108
+    assertThat(ev1.equals(ev1)).isTrue();
107
 
109
 
108
-    assertFalse(ev2.equals(null));
109
-    assertFalse(ev2.equals(new Object()));
110
+    assertThat(ev2.equals(null)).isFalse();
111
+    assertThat(ev2.equals(new Object())).isFalse();
110
   }
112
   }
111
 
113
 
112
 }
114
 }

+ 7
- 5
src/test/java/se/citerus/dddsample/domain/model/handling/HandlingHistoryTest.java Vedi File

1
 package se.citerus.dddsample.domain.model.handling;
1
 package se.citerus.dddsample.domain.model.handling;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
4
 import se.citerus.dddsample.domain.model.cargo.Cargo;
6
 import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
5
 import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
6
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
9
 import se.citerus.dddsample.domain.model.voyage.Voyage;
7
 import se.citerus.dddsample.domain.model.voyage.Voyage;
10
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
8
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
11
 
9
 
12
-import static java.util.Arrays.asList;
13
 import java.util.Date;
10
 import java.util.Date;
14
 
11
 
12
+import static java.util.Arrays.asList;
13
+import static org.assertj.core.api.Assertions.assertThat;
14
+import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
15
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
16
+
15
 
17
 
16
 public class HandlingHistoryTest extends TestCase {
18
 public class HandlingHistoryTest extends TestCase {
17
   Cargo cargo;
19
   Cargo cargo;
35
   }
37
   }
36
 
38
 
37
   public void testDistinctEventsByCompletionTime() {
39
   public void testDistinctEventsByCompletionTime() {
38
-    assertEquals(asList(event1, event2), handlingHistory.distinctEventsByCompletionTime());
40
+    assertThat(handlingHistory.distinctEventsByCompletionTime()).isEqualTo(asList(event1, event2));
39
   }
41
   }
40
 
42
 
41
   public void testMostRecentlyCompletedEvent() {
43
   public void testMostRecentlyCompletedEvent() {
42
-    assertEquals(event2, handlingHistory.mostRecentlyCompletedEvent());
44
+    assertThat(handlingHistory.mostRecentlyCompletedEvent()).isEqualTo(event2);
43
   }
45
   }
44
   
46
   
45
 }
47
 }

+ 9
- 7
src/test/java/se/citerus/dddsample/domain/model/location/LocationTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 
4
 
5
+import static org.assertj.core.api.Assertions.assertThat;
6
+
5
 public class LocationTest extends TestCase {
7
 public class LocationTest extends TestCase {
6
 
8
 
7
   public void testEquals() {
9
   public void testEquals() {
8
     // Same UN locode - equal
10
     // Same UN locode - equal
9
-    assertTrue(new Location(new UnLocode("ATEST"),"test-name").
10
-        equals(new Location(new UnLocode("ATEST"),"test-name")));
11
+    assertThat(new Location(new UnLocode("ATEST"),"test-name").
12
+        equals(new Location(new UnLocode("ATEST"),"test-name"))).isTrue();
11
 
13
 
12
     // Different UN locodes - not equal
14
     // Different UN locodes - not equal
13
-    assertFalse(new Location(new UnLocode("ATEST"),"test-name").
14
-         equals(new Location(new UnLocode("TESTB"), "test-name")));
15
+    assertThat(new Location(new UnLocode("ATEST"),"test-name").
16
+         equals(new Location(new UnLocode("TESTB"), "test-name"))).isFalse();
15
 
17
 
16
     // Always equal to itself
18
     // Always equal to itself
17
     Location location = new Location(new UnLocode("ATEST"),"test-name");
19
     Location location = new Location(new UnLocode("ATEST"),"test-name");
18
-    assertTrue(location.equals(location));
20
+    assertThat(location.equals(location)).isTrue();
19
 
21
 
20
     // Never equal to null
22
     // Never equal to null
21
-    assertFalse(location.equals(null));
23
+    assertThat(location.equals(null)).isFalse();
22
 
24
 
23
     // Special UNKNOWN location is equal to itself
25
     // Special UNKNOWN location is equal to itself
24
-    assertTrue(Location.UNKNOWN.equals(Location.UNKNOWN));
26
+    assertThat(Location.UNKNOWN.equals(Location.UNKNOWN)).isTrue();
25
 
27
 
26
     try {
28
     try {
27
       new Location(null, null);
29
       new Location(null, null);

+ 9
- 7
src/test/java/se/citerus/dddsample/domain/model/location/UnLocodeTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 
4
 
5
+import static org.assertj.core.api.Assertions.assertThat;
6
+
5
 public class UnLocodeTest extends TestCase {
7
 public class UnLocodeTest extends TestCase {
6
 
8
 
7
   public void testNew() throws Exception {
9
   public void testNew() throws Exception {
19
   }
21
   }
20
 
22
 
21
   public void testIdString() throws Exception {
23
   public void testIdString() throws Exception {
22
-    assertEquals("ABCDE", new UnLocode("AbcDe").idString());
24
+    assertThat(new UnLocode("AbcDe").idString()).isEqualTo("ABCDE");
23
   }
25
   }
24
 
26
 
25
   public void testEquals() throws Exception {
27
   public void testEquals() throws Exception {
26
     UnLocode allCaps = new UnLocode("ABCDE");
28
     UnLocode allCaps = new UnLocode("ABCDE");
27
     UnLocode mixedCase = new UnLocode("aBcDe");
29
     UnLocode mixedCase = new UnLocode("aBcDe");
28
 
30
 
29
-    assertTrue(allCaps.equals(mixedCase));
30
-    assertTrue(mixedCase.equals(allCaps));
31
-    assertTrue(allCaps.equals(allCaps));
31
+    assertThat(allCaps.equals(mixedCase)).isTrue();
32
+    assertThat(mixedCase.equals(allCaps)).isTrue();
33
+    assertThat(allCaps.equals(allCaps)).isTrue();
32
 
34
 
33
-    assertFalse(allCaps.equals(null));
34
-    assertFalse(allCaps.equals(new UnLocode("FGHIJ")));
35
+    assertThat(allCaps.equals(null)).isFalse();
36
+    assertThat(allCaps.equals(new UnLocode("FGHIJ"))).isFalse();
35
   }
37
   }
36
 
38
 
37
   public void testHashCode() throws Exception {
39
   public void testHashCode() throws Exception {
38
     UnLocode allCaps = new UnLocode("ABCDE");
40
     UnLocode allCaps = new UnLocode("ABCDE");
39
     UnLocode mixedCase = new UnLocode("aBcDe");
41
     UnLocode mixedCase = new UnLocode("aBcDe");
40
 
42
 
41
-    assertEquals(allCaps.hashCode(), mixedCase.hashCode());  
43
+    assertThat(mixedCase.hashCode()).isEqualTo(allCaps.hashCode());  
42
   }
44
   }
43
   
45
   
44
   private void assertValid(String unlocode) {
46
   private void assertValid(String unlocode) {

+ 13
- 11
src/test/java/se/citerus/dddsample/domain/model/voyage/CarrierMovementTest.java Vedi File

1
 package se.citerus.dddsample.domain.model.voyage;
1
 package se.citerus.dddsample.domain.model.voyage;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
6
 
4
 
7
 import java.util.Date;
5
 import java.util.Date;
8
 
6
 
7
+import static org.assertj.core.api.Assertions.assertThat;
8
+import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
9
+import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
10
+
9
 public class CarrierMovementTest extends TestCase {
11
 public class CarrierMovementTest extends TestCase {
10
 
12
 
11
   public void testConstructor() throws Exception {
13
   public void testConstructor() throws Exception {
29
     CarrierMovement cm3 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
31
     CarrierMovement cm3 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
30
     CarrierMovement cm4 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
32
     CarrierMovement cm4 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
31
 
33
 
32
-    assertTrue(cm1.sameValueAs(cm2));
33
-    assertFalse(cm2.sameValueAs(cm3));
34
-    assertTrue(cm3.sameValueAs(cm4));
34
+    assertThat(cm1.sameValueAs(cm2)).isTrue();
35
+    assertThat(cm2.sameValueAs(cm3)).isFalse();
36
+    assertThat(cm3.sameValueAs(cm4)).isTrue();
35
     
37
     
36
-    assertTrue(cm1.equals(cm2));
37
-    assertFalse(cm2.equals(cm3));
38
-    assertTrue(cm3.equals(cm4));
38
+    assertThat(cm1.equals(cm2)).isTrue();
39
+    assertThat(cm2.equals(cm3)).isFalse();
40
+    assertThat(cm3.equals(cm4)).isTrue();
39
 
41
 
40
-    assertTrue(cm1.hashCode() == cm2.hashCode());
41
-    assertFalse(cm2.hashCode() == cm3.hashCode());
42
-    assertTrue(cm3.hashCode() == cm4.hashCode());
42
+    assertThat(cm1.hashCode() == cm2.hashCode()).isTrue();
43
+    assertThat(cm2.hashCode() == cm3.hashCode()).isFalse();
44
+    assertThat(cm3.hashCode() == cm4.hashCode()).isTrue();
43
   }
45
   }
44
 
46
 
45
 }
47
 }

+ 6
- 4
src/test/java/se/citerus/dddsample/domain/shared/AndSpecificationTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 
4
 
5
+import static org.assertj.core.api.Assertions.assertThat;
6
+
5
 public class AndSpecificationTest extends TestCase {
7
 public class AndSpecificationTest extends TestCase {
6
 
8
 
7
   public void testAndIsSatisifedBy() throws Exception {
9
   public void testAndIsSatisifedBy() throws Exception {
9
     AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
11
     AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
10
 
12
 
11
     AndSpecification<Object> andSpecification = new AndSpecification<Object>(trueSpec, trueSpec);
13
     AndSpecification<Object> andSpecification = new AndSpecification<Object>(trueSpec, trueSpec);
12
-    assertTrue(andSpecification.isSatisfiedBy(new Object()));
14
+    assertThat(andSpecification.isSatisfiedBy(new Object())).isTrue();
13
 
15
 
14
     andSpecification = new AndSpecification<Object>(falseSpec, trueSpec);
16
     andSpecification = new AndSpecification<Object>(falseSpec, trueSpec);
15
-    assertFalse(andSpecification.isSatisfiedBy(new Object()));
17
+    assertThat(andSpecification.isSatisfiedBy(new Object())).isFalse();
16
 
18
 
17
     andSpecification = new AndSpecification<Object>(trueSpec, falseSpec);
19
     andSpecification = new AndSpecification<Object>(trueSpec, falseSpec);
18
-    assertFalse(andSpecification.isSatisfiedBy(new Object()));
20
+    assertThat(andSpecification.isSatisfiedBy(new Object())).isFalse();
19
 
21
 
20
     andSpecification = new AndSpecification<Object>(falseSpec, falseSpec);
22
     andSpecification = new AndSpecification<Object>(falseSpec, falseSpec);
21
-    assertFalse(andSpecification.isSatisfiedBy(new Object()));
23
+    assertThat(andSpecification.isSatisfiedBy(new Object())).isFalse();
22
 
24
 
23
   }
25
   }
24
 }
26
 }

+ 4
- 2
src/test/java/se/citerus/dddsample/domain/shared/NotSpecificationTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 
4
 
5
+import static org.assertj.core.api.Assertions.assertThat;
6
+
5
 public class NotSpecificationTest extends TestCase {
7
 public class NotSpecificationTest extends TestCase {
6
 
8
 
7
   public void testAndIsSatisifedBy() throws Exception {
9
   public void testAndIsSatisifedBy() throws Exception {
9
     AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
11
     AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
10
 
12
 
11
     NotSpecification<Object> notSpecification = new NotSpecification<Object>(trueSpec);
13
     NotSpecification<Object> notSpecification = new NotSpecification<Object>(trueSpec);
12
-    assertFalse(notSpecification.isSatisfiedBy(new Object()));
14
+    assertThat(notSpecification.isSatisfiedBy(new Object())).isFalse();
13
 
15
 
14
     notSpecification = new NotSpecification<Object>(falseSpec);
16
     notSpecification = new NotSpecification<Object>(falseSpec);
15
-    assertTrue(notSpecification.isSatisfiedBy(new Object()));
17
+    assertThat(notSpecification.isSatisfiedBy(new Object())).isTrue();
16
 
18
 
17
   }
19
   }
18
 }
20
 }

+ 6
- 4
src/test/java/se/citerus/dddsample/domain/shared/OrSpecificationTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 
4
 
5
+import static org.assertj.core.api.Assertions.assertThat;
6
+
5
 public class OrSpecificationTest extends TestCase {
7
 public class OrSpecificationTest extends TestCase {
6
 
8
 
7
   public void testAndIsSatisifedBy() throws Exception {
9
   public void testAndIsSatisifedBy() throws Exception {
9
     AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
11
     AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
10
 
12
 
11
     OrSpecification<Object> orSpecification = new OrSpecification<Object>(trueSpec, trueSpec);
13
     OrSpecification<Object> orSpecification = new OrSpecification<Object>(trueSpec, trueSpec);
12
-    assertTrue(orSpecification.isSatisfiedBy(new Object()));
14
+    assertThat(orSpecification.isSatisfiedBy(new Object())).isTrue();
13
 
15
 
14
     orSpecification = new OrSpecification<Object>(falseSpec, trueSpec);
16
     orSpecification = new OrSpecification<Object>(falseSpec, trueSpec);
15
-    assertTrue(orSpecification.isSatisfiedBy(new Object()));
17
+    assertThat(orSpecification.isSatisfiedBy(new Object())).isTrue();
16
 
18
 
17
     orSpecification = new OrSpecification<Object>(trueSpec, falseSpec);
19
     orSpecification = new OrSpecification<Object>(trueSpec, falseSpec);
18
-    assertTrue(orSpecification.isSatisfiedBy(new Object()));
20
+    assertThat(orSpecification.isSatisfiedBy(new Object())).isTrue();
19
 
21
 
20
     orSpecification = new OrSpecification<Object>(falseSpec, falseSpec);
22
     orSpecification = new OrSpecification<Object>(falseSpec, falseSpec);
21
-    assertFalse(orSpecification.isSatisfiedBy(new Object()));
23
+    assertThat(orSpecification.isSatisfiedBy(new Object())).isFalse();
22
 
24
 
23
   }
25
   }
24
 }
26
 }

+ 8
- 6
src/test/java/se/citerus/dddsample/domain/shared/experimental/ValueObjectSupportTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 
4
 
5
+import static org.assertj.core.api.Assertions.assertThat;
6
+
5
 
7
 
6
 public class ValueObjectSupportTest extends TestCase {
8
 public class ValueObjectSupportTest extends TestCase {
7
 
9
 
10
         final AValueObject vo2 = new AValueObject("A");
12
         final AValueObject vo2 = new AValueObject("A");
11
         final BValueObject vo3 = new BValueObject("A", 1);
13
         final BValueObject vo3 = new BValueObject("A", 1);
12
 
14
 
13
-        assertEquals(vo1, vo2);
14
-        assertEquals(vo2, vo1);
15
-        assertFalse(vo2.equals(vo3));
16
-        assertFalse(vo3.equals(vo2));
15
+        assertThat(vo2).isEqualTo(vo1);
16
+        assertThat(vo1).isEqualTo(vo2);
17
+        assertThat(vo2.equals(vo3)).isFalse();
18
+        assertThat(vo3.equals(vo2)).isFalse();
17
 
19
 
18
-        assertTrue(vo1.sameValueAs(vo2));
19
-        assertFalse(vo2.sameValueAs(vo3));
20
+        assertThat(vo1.sameValueAs(vo2)).isTrue();
21
+        assertThat(vo2.sameValueAs(vo3)).isFalse();
20
     }
22
     }
21
 
23
 
22
     class AValueObject extends ValueObjectSupport<AValueObject> {
24
     class AValueObject extends ValueObjectSupport<AValueObject> {

+ 31
- 27
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java Vedi File

1
 package se.citerus.dddsample.infrastructure.persistence.hibernate;
1
 package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
 
2
 
3
-import org.hibernate.SessionFactory;
4
 import org.hibernate.Session;
3
 import org.hibernate.Session;
4
+import org.hibernate.SessionFactory;
5
 import org.junit.Before;
5
 import org.junit.Before;
6
 import org.junit.Test;
6
 import org.junit.Test;
7
 import org.junit.runner.RunWith;
7
 import org.junit.runner.RunWith;
31
 import java.util.List;
31
 import java.util.List;
32
 import java.util.Map;
32
 import java.util.Map;
33
 
33
 
34
-import static org.junit.Assert.*;
34
+import static org.assertj.core.api.Assertions.assertThat;
35
+import static org.junit.Assert.assertEquals;
35
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.LOAD;
36
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.LOAD;
36
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.RECEIVE;
37
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.RECEIVE;
37
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
38
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
76
     public void testFindByCargoId() {
77
     public void testFindByCargoId() {
77
         final TrackingId trackingId = new TrackingId("FGH");
78
         final TrackingId trackingId = new TrackingId("FGH");
78
         final Cargo cargo = cargoRepository.find(trackingId);
79
         final Cargo cargo = cargoRepository.find(trackingId);
79
-        assertEquals(STOCKHOLM, cargo.origin());
80
-        assertEquals(HONGKONG, cargo.routeSpecification().origin());
81
-        assertEquals(HELSINKI, cargo.routeSpecification().destination());
80
+        assertThat(cargo.origin()).isEqualTo(STOCKHOLM);
81
+        assertThat(cargo.routeSpecification().origin()).isEqualTo(HONGKONG);
82
+        assertThat(cargo.routeSpecification().destination()).isEqualTo(HELSINKI);
82
 
83
 
83
-        assertNotNull(cargo.delivery());
84
+        assertThat(cargo.delivery()).isNotNull();
84
 
85
 
85
         final List<HandlingEvent> events = handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId).distinctEventsByCompletionTime();
86
         final List<HandlingEvent> events = handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId).distinctEventsByCompletionTime();
86
-        assertEquals(2, events.size());
87
+        assertThat(events).hasSize(2);
87
 
88
 
88
         HandlingEvent firstEvent = events.get(0);
89
         HandlingEvent firstEvent = events.get(0);
89
         assertHandlingEvent(cargo, firstEvent, RECEIVE, HONGKONG, 100, 160, Voyage.NONE);
90
         assertHandlingEvent(cargo, firstEvent, RECEIVE, HONGKONG, 100, 160, Voyage.NONE);
100
         assertHandlingEvent(cargo, secondEvent, LOAD, HONGKONG, 150, 110, hongkongMelbourneTokyoAndBack);
101
         assertHandlingEvent(cargo, secondEvent, LOAD, HONGKONG, 150, 110, hongkongMelbourneTokyoAndBack);
101
 
102
 
102
         List<Leg> legs = cargo.itinerary().legs();
103
         List<Leg> legs = cargo.itinerary().legs();
103
-        assertEquals(3, legs.size());
104
+        assertThat(legs).hasSize(3);
104
 
105
 
105
         Leg firstLeg = legs.get(0);
106
         Leg firstLeg = legs.get(0);
106
         assertLeg(firstLeg, "0101", HONGKONG, MELBOURNE);
107
         assertLeg(firstLeg, "0101", HONGKONG, MELBOURNE);
113
     }
114
     }
114
 
115
 
115
     private void assertHandlingEvent(Cargo cargo, HandlingEvent event, HandlingEvent.Type expectedEventType, Location expectedLocation, int completionTimeMs, int registrationTimeMs, Voyage voyage) {
116
     private void assertHandlingEvent(Cargo cargo, HandlingEvent event, HandlingEvent.Type expectedEventType, Location expectedLocation, int completionTimeMs, int registrationTimeMs, Voyage voyage) {
116
-        assertEquals(expectedEventType, event.type());
117
-        assertEquals(expectedLocation, event.location());
117
+        assertThat(event.type()).isEqualTo(expectedEventType);
118
+        assertThat(event.location()).isEqualTo(expectedLocation);
118
 
119
 
119
         Date expectedCompletionTime = SampleDataGenerator.offset(completionTimeMs);
120
         Date expectedCompletionTime = SampleDataGenerator.offset(completionTimeMs);
120
-        assertEquals(expectedCompletionTime, event.completionTime());
121
+        assertThat(event.completionTime()).isEqualTo(expectedCompletionTime);
121
 
122
 
122
         Date expectedRegistrationTime = SampleDataGenerator.offset(registrationTimeMs);
123
         Date expectedRegistrationTime = SampleDataGenerator.offset(registrationTimeMs);
123
-        assertEquals(expectedRegistrationTime, event.registrationTime());
124
+        assertThat(event.registrationTime()).isEqualTo(expectedRegistrationTime);
124
 
125
 
125
-        assertEquals(voyage, event.voyage());
126
-        assertEquals(cargo, event.cargo());
126
+        assertThat(event.voyage()).isEqualTo(voyage);
127
+        assertThat(event.cargo()).isEqualTo(cargo);
127
     }
128
     }
128
 
129
 
129
     @Test
130
     @Test
130
     public void testFindByCargoIdUnknownId() {
131
     public void testFindByCargoIdUnknownId() {
131
-        assertNull(cargoRepository.find(new TrackingId("UNKNOWN")));
132
+        assertThat(cargoRepository.find(new TrackingId("UNKNOWN"))).isNull();
132
     }
133
     }
133
 
134
 
134
     private void assertLeg(Leg firstLeg, String vn, Location expectedFrom, Location expectedTo) {
135
     private void assertLeg(Leg firstLeg, String vn, Location expectedFrom, Location expectedTo) {
135
-        assertEquals(new VoyageNumber(vn), firstLeg.voyage().voyageNumber());
136
-        assertEquals(expectedFrom, firstLeg.loadLocation());
137
-        assertEquals(expectedTo, firstLeg.unloadLocation());
136
+        assertThat(firstLeg.voyage().voyageNumber()).isEqualTo(new VoyageNumber(vn));
137
+        assertThat(firstLeg.loadLocation()).isEqualTo(expectedFrom);
138
+        assertThat(firstLeg.unloadLocation()).isEqualTo(expectedTo);
138
     }
139
     }
139
 
140
 
140
     @Test
141
     @Test
159
         Map<String, Object> map = jdbcTemplate.queryForMap(
160
         Map<String, Object> map = jdbcTemplate.queryForMap(
160
                 "select * from Cargo where tracking_id = ?", trackingId.idString());
161
                 "select * from Cargo where tracking_id = ?", trackingId.idString());
161
 
162
 
162
-        assertEquals("AAA", map.get("TRACKING_ID"));
163
+        assertThat(map.get("TRACKING_ID")).isEqualTo("AAA");
163
 
164
 
164
         Long originId = getLongId(origin);
165
         Long originId = getLongId(origin);
165
-        assertEquals(originId, map.get("SPEC_ORIGIN_ID"));
166
+        assertThat(map.get("SPEC_ORIGIN_ID")).isEqualTo(originId);
166
 
167
 
167
         Long destinationId = getLongId(destination);
168
         Long destinationId = getLongId(destination);
168
-        assertEquals(destinationId, map.get("SPEC_DESTINATION_ID"));
169
+        assertThat(map.get("SPEC_DESTINATION_ID")).isEqualTo(destinationId);
169
 
170
 
170
         sessionFactory.getCurrentSession().clear();
171
         sessionFactory.getCurrentSession().clear();
171
 
172
 
172
         final Cargo loadedCargo = cargoRepository.find(trackingId);
173
         final Cargo loadedCargo = cargoRepository.find(trackingId);
173
-        assertEquals(1, loadedCargo.itinerary().legs().size());
174
+        assertThat(loadedCargo.itinerary().legs()).hasSize(1);
174
     }
175
     }
175
 
176
 
176
     @Test
177
     @Test
177
     public void testReplaceItinerary() {
178
     public void testReplaceItinerary() {
178
         Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
179
         Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
179
         Long cargoId = getLongId(cargo);
180
         Long cargoId = getLongId(cargo);
181
+        //assertThat(Integer.class).intValue()).isEqualTo(3, jdbcTemplate.queryForObject("select count(*) from Leg where cargo_id = ?", new Object[]{cargoId});
180
         assertEquals(3, jdbcTemplate.queryForObject("select count(*) from Leg where cargo_id = ?", new Object[]{cargoId}, Integer.class).intValue());
182
         assertEquals(3, jdbcTemplate.queryForObject("select count(*) from Leg where cargo_id = ?", new Object[]{cargoId}, Integer.class).intValue());
181
 
183
 
182
         Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
184
         Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
188
         cargoRepository.store(cargo);
190
         cargoRepository.store(cargo);
189
         flush();
191
         flush();
190
 
192
 
193
+        //assertThat(Integer.class).intValue()).isEqualTo(1, jdbcTemplate.queryForObject("select count(*) from Leg where cargo_id = ?", new Object[]{cargoId});
191
         assertEquals(1, jdbcTemplate.queryForObject("select count(*) from Leg where cargo_id = ?", new Object[]{cargoId}, Integer.class).intValue());
194
         assertEquals(1, jdbcTemplate.queryForObject("select count(*) from Leg where cargo_id = ?", new Object[]{cargoId}, Integer.class).intValue());
195
+
192
     }
196
     }
193
 
197
 
194
     @Test
198
     @Test
195
     public void testFindAll() {
199
     public void testFindAll() {
196
         List<Cargo> all = cargoRepository.findAll();
200
         List<Cargo> all = cargoRepository.findAll();
197
-        assertNotNull(all);
198
-        assertEquals(6, all.size());
201
+        assertThat(all).isNotNull();
202
+        assertThat(all).hasSize(6);
199
     }
203
     }
200
 
204
 
201
     @Test
205
     @Test
202
     public void testNextTrackingId() {
206
     public void testNextTrackingId() {
203
         TrackingId trackingId = cargoRepository.nextTrackingId();
207
         TrackingId trackingId = cargoRepository.nextTrackingId();
204
-        assertNotNull(trackingId);
208
+        assertThat(trackingId).isNotNull();
205
 
209
 
206
         TrackingId trackingId2 = cargoRepository.nextTrackingId();
210
         TrackingId trackingId2 = cargoRepository.nextTrackingId();
207
-        assertNotNull(trackingId2);
208
-        assertFalse(trackingId.equals(trackingId2));
211
+        assertThat(trackingId2).isNotNull();
212
+        assertThat(trackingId.equals(trackingId2)).isFalse();
209
     }
213
     }
210
 
214
 
211
 
215
 

+ 7
- 8
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CarrierMovementRepositoryTest.java Vedi File

19
 
19
 
20
 import javax.sql.DataSource;
20
 import javax.sql.DataSource;
21
 
21
 
22
-import static org.junit.Assert.assertEquals;
23
-import static org.junit.Assert.assertNotNull;
22
+import static org.assertj.core.api.Assertions.assertThat;
24
 
23
 
25
 @RunWith(SpringJUnit4ClassRunner.class)
24
 @RunWith(SpringJUnit4ClassRunner.class)
26
 @ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
25
 @ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
51
     @Test
50
     @Test
52
     public void testFind() throws Exception {
51
     public void testFind() throws Exception {
53
         Voyage voyage = voyageRepository.find(new VoyageNumber("0101"));
52
         Voyage voyage = voyageRepository.find(new VoyageNumber("0101"));
54
-        assertNotNull(voyage);
55
-        assertEquals("0101", voyage.voyageNumber().idString());
53
+        assertThat(voyage).isNotNull();
54
+        assertThat(voyage.voyageNumber().idString()).isEqualTo("0101");
56
     /* TODO adapt
55
     /* TODO adapt
57
-    assertEquals(STOCKHOLM, carrierMovement.departureLocation());
58
-    assertEquals(HELSINKI, carrierMovement.arrivalLocation());
59
-    assertEquals(DateTestUtil.toDate("2007-09-23", "02:00"), carrierMovement.departureTime());
60
-    assertEquals(DateTestUtil.toDate("2007-09-23", "03:00"), carrierMovement.arrivalTime());
56
+    assertThat(carrierMovement.departureLocation()).isEqualTo(STOCKHOLM);
57
+    assertThat(carrierMovement.arrivalLocation()).isEqualTo(HELSINKI);
58
+    assertThat(carrierMovement.departureTime()).isEqualTo(DateTestUtil.toDate("2007-09-23", "02:00"));
59
+    assertThat(carrierMovement.arrivalTime()).isEqualTo(DateTestUtil.toDate("2007-09-23", "03:00"));
61
     */
60
     */
62
     }
61
     }
63
 
62
 

+ 11
- 7
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java Vedi File

1
 package se.citerus.dddsample.infrastructure.persistence.hibernate;
1
 package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
 
2
 
3
-import org.hibernate.SessionFactory;
4
 import org.hibernate.Session;
3
 import org.hibernate.Session;
4
+import org.hibernate.SessionFactory;
5
 import org.junit.Before;
5
 import org.junit.Before;
6
 import org.junit.Test;
6
 import org.junit.Test;
7
 import org.junit.runner.RunWith;
7
 import org.junit.runner.RunWith;
25
 
25
 
26
 import javax.sql.DataSource;
26
 import javax.sql.DataSource;
27
 import java.lang.reflect.Field;
27
 import java.lang.reflect.Field;
28
+import java.sql.Timestamp;
28
 import java.util.Date;
29
 import java.util.Date;
29
 import java.util.List;
30
 import java.util.List;
30
 import java.util.Map;
31
 import java.util.Map;
31
 
32
 
32
-import static org.junit.Assert.assertEquals;
33
+import static org.assertj.core.api.Assertions.assertThat;
33
 
34
 
34
 @RunWith(SpringJUnit4ClassRunner.class)
35
 @RunWith(SpringJUnit4ClassRunner.class)
35
 @ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
36
 @ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
77
         flush();
78
         flush();
78
 
79
 
79
         Map<String, Object> result = jdbcTemplate.queryForMap("select * from HandlingEvent where id = ?", getLongId(event));
80
         Map<String, Object> result = jdbcTemplate.queryForMap("select * from HandlingEvent where id = ?", getLongId(event));
80
-        assertEquals(1L, result.get("CARGO_ID"));
81
-        assertEquals(new Date(10), result.get("COMPLETIONTIME"));
82
-        assertEquals(new Date(20), result.get("REGISTRATIONTIME"));
83
-        assertEquals("CLAIM", result.get("TYPE"));
81
+
82
+        assertThat(result.get("CARGO_ID")).isEqualTo(1L);
83
+        Date completionDate = new Date(((Timestamp) result.get("COMPLETIONTIME")).getTime()); // equals call is not symmetric between java.sql.Timestamp and java.util.Date, so we should convert Timestamp Date
84
+        assertThat(completionDate).isEqualTo(new Date(10));
85
+        Date registrationDate = new Date(((Timestamp) result.get("REGISTRATIONTIME")).getTime()); // equals call is not symmetric between java.sql.Timestamp and java.util.Date, so we should convert Timestamp Date
86
+        assertThat(registrationDate).isEqualTo(new Date(20));
87
+        assertThat(result.get("TYPE")).isEqualTo("CLAIM");
84
         // TODO: the rest of the columns
88
         // TODO: the rest of the columns
85
     }
89
     }
86
 
90
 
107
     public void testFindEventsForCargo() throws Exception {
111
     public void testFindEventsForCargo() throws Exception {
108
         TrackingId trackingId = new TrackingId("XYZ");
112
         TrackingId trackingId = new TrackingId("XYZ");
109
         List<HandlingEvent> handlingEvents = handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId).distinctEventsByCompletionTime();
113
         List<HandlingEvent> handlingEvents = handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId).distinctEventsByCompletionTime();
110
-        assertEquals(12, handlingEvents.size());
114
+        assertThat(handlingEvents).hasSize(12);
111
     }
115
     }
112
 
116
 
113
 }
117
 }

+ 6
- 6
src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/LocationRepositoryTest.java Vedi File

19
 import javax.sql.DataSource;
19
 import javax.sql.DataSource;
20
 import java.util.List;
20
 import java.util.List;
21
 
21
 
22
-import static org.junit.Assert.*;
22
+import static org.assertj.core.api.Assertions.assertThat;
23
 
23
 
24
 @RunWith(SpringJUnit4ClassRunner.class)
24
 @RunWith(SpringJUnit4ClassRunner.class)
25
 @ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
25
 @ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
45
     public void testFind() throws Exception {
45
     public void testFind() throws Exception {
46
         final UnLocode melbourne = new UnLocode("AUMEL");
46
         final UnLocode melbourne = new UnLocode("AUMEL");
47
         Location location = locationRepository.find(melbourne);
47
         Location location = locationRepository.find(melbourne);
48
-        assertNotNull(location);
49
-        assertEquals(melbourne, location.unLocode());
48
+        assertThat(location).isNotNull();
49
+        assertThat(location.unLocode()).isEqualTo(melbourne);
50
 
50
 
51
-        assertNull(locationRepository.find(new UnLocode("NOLOC")));
51
+        assertThat(locationRepository.find(new UnLocode("NOLOC"))).isNull();
52
     }
52
     }
53
 
53
 
54
     @Test
54
     @Test
55
     public void testFindAll() throws Exception {
55
     public void testFindAll() throws Exception {
56
         List<Location> allLocations = locationRepository.findAll();
56
         List<Location> allLocations = locationRepository.findAll();
57
 
57
 
58
-        assertNotNull(allLocations);
59
-        assertEquals(7, allLocations.size());
58
+        assertThat(allLocations).isNotNull();
59
+        assertThat(allLocations).hasSize(7);
60
     }
60
     }
61
 
61
 
62
 }
62
 }

+ 10
- 8
src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java Vedi File

4
 import com.pathfinder.internal.GraphDAO;
4
 import com.pathfinder.internal.GraphDAO;
5
 import com.pathfinder.internal.GraphTraversalServiceImpl;
5
 import com.pathfinder.internal.GraphTraversalServiceImpl;
6
 import junit.framework.TestCase;
6
 import junit.framework.TestCase;
7
-import static org.easymock.EasyMock.*;
8
 import se.citerus.dddsample.domain.model.cargo.*;
7
 import se.citerus.dddsample.domain.model.cargo.*;
9
 import se.citerus.dddsample.domain.model.location.Location;
8
 import se.citerus.dddsample.domain.model.location.Location;
10
 import se.citerus.dddsample.domain.model.location.LocationRepository;
9
 import se.citerus.dddsample.domain.model.location.LocationRepository;
11
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
12
 import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
10
 import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
13
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
11
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
14
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
12
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
18
 import java.util.Date;
16
 import java.util.Date;
19
 import java.util.List;
17
 import java.util.List;
20
 
18
 
19
+import static org.assertj.core.api.Assertions.assertThat;
20
+import static org.easymock.EasyMock.*;
21
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
22
+
21
 public class ExternalRoutingServiceTest extends TestCase {
23
 public class ExternalRoutingServiceTest extends TestCase {
22
 
24
 
23
   private ExternalRoutingService externalRoutingService;
25
   private ExternalRoutingService externalRoutingService;
54
     replay(voyageRepository);
56
     replay(voyageRepository);
55
 
57
 
56
     List<Itinerary> candidates = externalRoutingService.fetchRoutesForSpecification(routeSpecification);
58
     List<Itinerary> candidates = externalRoutingService.fetchRoutesForSpecification(routeSpecification);
57
-    assertNotNull(candidates);
59
+    assertThat(candidates).isNotNull();
58
 
60
 
59
     for (Itinerary itinerary : candidates) {
61
     for (Itinerary itinerary : candidates) {
60
       List<Leg> legs = itinerary.legs();
62
       List<Leg> legs = itinerary.legs();
61
-      assertNotNull(legs);
62
-      assertFalse(legs.isEmpty());
63
+      assertThat(legs).isNotNull();
64
+      assertThat(legs.isEmpty()).isFalse();
63
 
65
 
64
       // Cargo origin and start of first leg should match
66
       // Cargo origin and start of first leg should match
65
-      assertEquals(cargo.origin(), legs.get(0).loadLocation());
67
+      assertThat(legs.get(0).loadLocation()).isEqualTo(cargo.origin());
66
 
68
 
67
       // Cargo final destination and last leg stop should match
69
       // Cargo final destination and last leg stop should match
68
       Location lastLegStop = legs.get(legs.size() - 1).unloadLocation();
70
       Location lastLegStop = legs.get(legs.size() - 1).unloadLocation();
69
-      assertEquals(cargo.routeSpecification().destination(), lastLegStop);
71
+      assertThat(lastLegStop).isEqualTo(cargo.routeSpecification().destination());
70
 
72
 
71
       for (int i = 0; i < legs.size() - 1; i++) {
73
       for (int i = 0; i < legs.size() - 1; i++) {
72
         // Assert that all legs are connected
74
         // Assert that all legs are connected
73
-        assertEquals(legs.get(i).unloadLocation(), legs.get(i + 1).loadLocation());
75
+        assertThat(legs.get(i + 1).loadLocation()).isEqualTo(legs.get(i).unloadLocation());
74
       }
76
       }
75
     }
77
     }
76
 
78
 

+ 15
- 13
src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/CargoRoutingDTOAssemblerTest.java Vedi File

3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 import se.citerus.dddsample.domain.model.cargo.*;
4
 import se.citerus.dddsample.domain.model.cargo.*;
5
 import se.citerus.dddsample.domain.model.location.Location;
5
 import se.citerus.dddsample.domain.model.location.Location;
6
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
7
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
8
 import se.citerus.dddsample.interfaces.booking.facade.dto.CargoRoutingDTO;
6
 import se.citerus.dddsample.interfaces.booking.facade.dto.CargoRoutingDTO;
9
 import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
7
 import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
10
 
8
 
11
 import java.util.Arrays;
9
 import java.util.Arrays;
12
 import java.util.Date;
10
 import java.util.Date;
13
 
11
 
12
+import static org.assertj.core.api.Assertions.assertThat;
13
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
14
+import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
15
+
14
 public class CargoRoutingDTOAssemblerTest extends TestCase {
16
 public class CargoRoutingDTOAssemblerTest extends TestCase {
15
 
17
 
16
   public void testToDTO() throws Exception {
18
   public void testToDTO() throws Exception {
31
 
33
 
32
     final CargoRoutingDTO dto = assembler.toDTO(cargo);
34
     final CargoRoutingDTO dto = assembler.toDTO(cargo);
33
 
35
 
34
-    assertEquals(2, dto.getLegs().size());
36
+    assertThat(dto.getLegs()).hasSize(2);
35
 
37
 
36
     LegDTO legDTO = dto.getLegs().get(0);
38
     LegDTO legDTO = dto.getLegs().get(0);
37
-    assertEquals("CM001", legDTO.getVoyageNumber());
38
-    assertEquals("SESTO", legDTO.getFrom());
39
-    assertEquals("CNSHA", legDTO.getTo());
39
+    assertThat(legDTO.getVoyageNumber()).isEqualTo("CM001");
40
+    assertThat(legDTO.getFrom()).isEqualTo("SESTO");
41
+    assertThat(legDTO.getTo()).isEqualTo("CNSHA");
40
 
42
 
41
     legDTO = dto.getLegs().get(1);
43
     legDTO = dto.getLegs().get(1);
42
-    assertEquals("CM001", legDTO.getVoyageNumber());
43
-    assertEquals("NLRTM", legDTO.getFrom());
44
-    assertEquals("AUMEL", legDTO.getTo());
44
+    assertThat(legDTO.getVoyageNumber()).isEqualTo("CM001");
45
+    assertThat(legDTO.getFrom()).isEqualTo("NLRTM");
46
+    assertThat(legDTO.getTo()).isEqualTo("AUMEL");
45
   }
47
   }
46
 
48
 
47
   public void testToDTO_NoItinerary() throws Exception {
49
   public void testToDTO_NoItinerary() throws Exception {
50
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
52
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
51
     final CargoRoutingDTO dto = assembler.toDTO(cargo);
53
     final CargoRoutingDTO dto = assembler.toDTO(cargo);
52
 
54
 
53
-    assertEquals("XYZ", dto.getTrackingId());
54
-    assertEquals("SESTO", dto.getOrigin());
55
-    assertEquals("AUMEL", dto.getFinalDestination());
56
-    assertTrue(dto.getLegs().isEmpty());
55
+    assertThat(dto.getTrackingId()).isEqualTo("XYZ");
56
+    assertThat(dto.getOrigin()).isEqualTo("SESTO");
57
+    assertThat(dto.getFinalDestination()).isEqualTo("AUMEL");
58
+    assertThat(dto.getLegs().isEmpty()).isTrue();
57
   }
59
   }
58
 }
60
 }

+ 21
- 19
src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/ItineraryCandidateDTOAssemblerTest.java Vedi File

1
 package se.citerus.dddsample.interfaces.booking.facade.internal.assembler;
1
 package se.citerus.dddsample.interfaces.booking.facade.internal.assembler;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
 import se.citerus.dddsample.domain.model.cargo.Itinerary;
4
 import se.citerus.dddsample.domain.model.cargo.Itinerary;
6
 import se.citerus.dddsample.domain.model.cargo.Leg;
5
 import se.citerus.dddsample.domain.model.cargo.Leg;
7
 import se.citerus.dddsample.domain.model.location.Location;
6
 import se.citerus.dddsample.domain.model.location.Location;
8
 import se.citerus.dddsample.domain.model.location.LocationRepository;
7
 import se.citerus.dddsample.domain.model.location.LocationRepository;
9
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
10
 import se.citerus.dddsample.domain.model.location.UnLocode;
8
 import se.citerus.dddsample.domain.model.location.UnLocode;
11
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
12
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
9
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
13
 import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
10
 import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
14
 import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
11
 import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
19
 import java.util.Date;
16
 import java.util.Date;
20
 import java.util.List;
17
 import java.util.List;
21
 
18
 
19
+import static org.assertj.core.api.Assertions.assertThat;
20
+import static org.easymock.EasyMock.*;
21
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
22
+import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
23
+
22
 public class ItineraryCandidateDTOAssemblerTest extends TestCase {
24
 public class ItineraryCandidateDTOAssemblerTest extends TestCase {
23
 
25
 
24
   public void testToDTO() throws Exception {
26
   public void testToDTO() throws Exception {
36
 
38
 
37
     final RouteCandidateDTO dto = assembler.toDTO(itinerary);
39
     final RouteCandidateDTO dto = assembler.toDTO(itinerary);
38
 
40
 
39
-    assertEquals(2, dto.getLegs().size());
41
+    assertThat(dto.getLegs()).hasSize(2);
40
     LegDTO legDTO = dto.getLegs().get(0);
42
     LegDTO legDTO = dto.getLegs().get(0);
41
-    assertEquals("CM001", legDTO.getVoyageNumber());
42
-    assertEquals("SESTO", legDTO.getFrom());
43
-    assertEquals("CNSHA", legDTO.getTo());
43
+    assertThat(legDTO.getVoyageNumber()).isEqualTo("CM001");
44
+    assertThat(legDTO.getFrom()).isEqualTo("SESTO");
45
+    assertThat(legDTO.getTo()).isEqualTo("CNSHA");
44
 
46
 
45
     legDTO = dto.getLegs().get(1);
47
     legDTO = dto.getLegs().get(1);
46
-    assertEquals("CM001", legDTO.getVoyageNumber());
47
-    assertEquals("NLRTM", legDTO.getFrom());
48
-    assertEquals("AUMEL", legDTO.getTo());
48
+    assertThat(legDTO.getVoyageNumber()).isEqualTo("CM001");
49
+    assertThat(legDTO.getFrom()).isEqualTo("NLRTM");
50
+    assertThat(legDTO.getTo()).isEqualTo("AUMEL");
49
   }
51
   }
50
 
52
 
51
   public void testFromDTO() throws Exception {
53
   public void testFromDTO() throws Exception {
69
     final Itinerary itinerary = assembler.fromDTO(new RouteCandidateDTO(legs), voyageRepository, locationRepository);
71
     final Itinerary itinerary = assembler.fromDTO(new RouteCandidateDTO(legs), voyageRepository, locationRepository);
70
 
72
 
71
     
73
     
72
-    assertNotNull(itinerary);
73
-    assertNotNull(itinerary.legs());
74
-    assertEquals(2, itinerary.legs().size());
74
+    assertThat(itinerary).isNotNull();
75
+    assertThat(itinerary.legs()).isNotNull();
76
+    assertThat(itinerary.legs()).hasSize(2);
75
 
77
 
76
     final Leg leg1 = itinerary.legs().get(0);
78
     final Leg leg1 = itinerary.legs().get(0);
77
-    assertNotNull(leg1);
78
-    assertEquals(HONGKONG, leg1.loadLocation());
79
-    assertEquals(TOKYO, leg1.unloadLocation());
79
+    assertThat(leg1).isNotNull();
80
+    assertThat(leg1.loadLocation()).isEqualTo(HONGKONG);
81
+    assertThat(leg1.unloadLocation()).isEqualTo(TOKYO);
80
 
82
 
81
     final Leg leg2 = itinerary.legs().get(1);
83
     final Leg leg2 = itinerary.legs().get(1);
82
-    assertNotNull(leg2);
83
-    assertEquals(TOKYO, leg2.loadLocation());
84
-    assertEquals(CHICAGO, leg2.unloadLocation());
84
+    assertThat(leg2).isNotNull();
85
+    assertThat(leg2.loadLocation()).isEqualTo(TOKYO);
86
+    assertThat(leg2.unloadLocation()).isEqualTo(CHICAGO);
85
   }
87
   }
86
 }
88
 }

+ 9
- 7
src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/LocationDTOAssemblerTest.java Vedi File

2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 import se.citerus.dddsample.domain.model.location.Location;
4
 import se.citerus.dddsample.domain.model.location.Location;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
6
-import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
7
 import se.citerus.dddsample.interfaces.booking.facade.dto.LocationDTO;
5
 import se.citerus.dddsample.interfaces.booking.facade.dto.LocationDTO;
8
 
6
 
9
 import java.util.Arrays;
7
 import java.util.Arrays;
10
 import java.util.List;
8
 import java.util.List;
11
 
9
 
10
+import static org.assertj.core.api.Assertions.assertThat;
11
+import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
12
+import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
13
+
12
 public class LocationDTOAssemblerTest extends TestCase {
14
 public class LocationDTOAssemblerTest extends TestCase {
13
 
15
 
14
   public void testToDTOList() {
16
   public void testToDTOList() {
17
 
19
 
18
     final List<LocationDTO> dtos = assembler.toDTOList(locationList);
20
     final List<LocationDTO> dtos = assembler.toDTOList(locationList);
19
 
21
 
20
-    assertEquals(2, dtos.size());
22
+    assertThat(dtos).hasSize(2);
21
 
23
 
22
     LocationDTO dto = dtos.get(0);
24
     LocationDTO dto = dtos.get(0);
23
-    assertEquals("SESTO", dto.getUnLocode());
24
-    assertEquals("Stockholm", dto.getName());
25
+    assertThat(dto.getUnLocode()).isEqualTo("SESTO");
26
+    assertThat(dto.getName()).isEqualTo("Stockholm");
25
 
27
 
26
     dto = dtos.get(1);
28
     dto = dtos.get(1);
27
-    assertEquals("DEHAM", dto.getUnLocode());
28
-    assertEquals("Hamburg", dto.getName());
29
+    assertThat(dto.getUnLocode()).isEqualTo("DEHAM");
30
+    assertThat(dto.getName()).isEqualTo("Hamburg");
29
   }
31
   }
30
 
32
 
31
 }
33
 }

+ 9
- 9
src/test/java/se/citerus/dddsample/interfaces/booking/web/ItinerarySelectionCommandTest.java Vedi File

6
 
6
 
7
 import java.util.List;
7
 import java.util.List;
8
 
8
 
9
-import static org.junit.Assert.assertEquals;
9
+import static org.assertj.core.api.Assertions.assertThat;
10
 
10
 
11
 public class ItinerarySelectionCommandTest {
11
 public class ItinerarySelectionCommandTest {
12
 
12
 
32
         binder.bind(request);
32
         binder.bind(request);
33
 
33
 
34
         List<RouteAssignmentCommand.LegCommand> legs = command.getLegs();
34
         List<RouteAssignmentCommand.LegCommand> legs = command.getLegs();
35
-        assertEquals(2, legs.size());
35
+        assertThat(legs).hasSize(2);
36
 
36
 
37
         RouteAssignmentCommand.LegCommand leg = legs.get(0);
37
         RouteAssignmentCommand.LegCommand leg = legs.get(0);
38
-        assertEquals("CM01", leg.getVoyageNumber());
39
-        assertEquals("AAAAA", leg.getFromUnLocode());
40
-        assertEquals("BBBBB", leg.getToUnLocode());
38
+        assertThat(leg.getVoyageNumber()).isEqualTo("CM01");
39
+        assertThat(leg.getFromUnLocode()).isEqualTo("AAAAA");
40
+        assertThat(leg.getToUnLocode()).isEqualTo("BBBBB");
41
 
41
 
42
         leg = legs.get(1);
42
         leg = legs.get(1);
43
-        assertEquals("CM02", leg.getVoyageNumber());
44
-        assertEquals("CCCCC", leg.getFromUnLocode());
45
-        assertEquals("DDDDD", leg.getToUnLocode());
43
+        assertThat(leg.getVoyageNumber()).isEqualTo("CM02");
44
+        assertThat(leg.getFromUnLocode()).isEqualTo("CCCCC");
45
+        assertThat(leg.getToUnLocode()).isEqualTo("DDDDD");
46
 
46
 
47
-        assertEquals("XYZ", command.getTrackingId());
47
+        assertThat(command.getTrackingId()).isEqualTo("XYZ");
48
     }
48
     }
49
 }
49
 }

+ 5
- 5
src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java Vedi File

17
 
17
 
18
 import java.util.Map;
18
 import java.util.Map;
19
 
19
 
20
-import static org.junit.Assert.assertEquals;
20
+import static org.assertj.core.api.Assertions.assertThat;
21
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
21
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
22
 
22
 
23
 
23
 
52
         String trackingId = "ABC";
52
         String trackingId = "ABC";
53
         Map<String, Object> model = mockMvc.perform(post("/track").param("trackingId", trackingId)).andReturn().getModelAndView().getModel();
53
         Map<String, Object> model = mockMvc.perform(post("/track").param("trackingId", trackingId)).andReturn().getModelAndView().getModel();
54
         CargoTrackingViewAdapter cargoTrackingViewAdapter = (CargoTrackingViewAdapter) model.get("cargo");
54
         CargoTrackingViewAdapter cargoTrackingViewAdapter = (CargoTrackingViewAdapter) model.get("cargo");
55
-        assertEquals(trackingId, cargoTrackingViewAdapter.getTrackingId());
55
+        assertThat(cargoTrackingViewAdapter.getTrackingId()).isEqualTo(trackingId);
56
     }
56
     }
57
 
57
 
58
     @Test
58
     @Test
61
         Map<String, Object> model = mockMvc.perform(post("/track").param("trackingId", trackingId)).andReturn().getModelAndView().getModel();
61
         Map<String, Object> model = mockMvc.perform(post("/track").param("trackingId", trackingId)).andReturn().getModelAndView().getModel();
62
         Errors errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "trackCommand");
62
         Errors errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "trackCommand");
63
         FieldError fe = errors.getFieldError("trackingId");
63
         FieldError fe = errors.getFieldError("trackingId");
64
-        assertEquals("cargo.unknown_id", fe.getCode());
65
-        assertEquals(1, fe.getArguments().length);
66
-        assertEquals(trackingId, fe.getArguments()[0]);
64
+        assertThat(fe.getCode()).isEqualTo("cargo.unknown_id");
65
+        assertThat(fe.getArguments().length).isEqualTo(1);
66
+        assertThat(fe.getArguments()[0]).isEqualTo(trackingId);
67
     }
67
     }
68
 
68
 
69
 }
69
 }

+ 23
- 21
src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingViewAdapterTest.java Vedi File

7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
8
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
9
 import se.citerus.dddsample.domain.model.handling.HandlingHistory;
9
 import se.citerus.dddsample.domain.model.handling.HandlingHistory;
10
+
11
+import java.util.*;
12
+
13
+import static org.assertj.core.api.Assertions.assertThat;
10
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
14
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
11
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
15
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
12
 import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
16
 import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
13
 
17
 
14
-import java.util.*;
15
-
16
 public class CargoTrackingViewAdapterTest extends TestCase {
18
 public class CargoTrackingViewAdapterTest extends TestCase {
17
 
19
 
18
   public void testCreate() {
20
   public void testCreate() {
32
 
34
 
33
     CargoTrackingViewAdapter adapter = new CargoTrackingViewAdapter(cargo, applicationContext, Locale.GERMAN, events, TimeZone.getTimeZone("Europe/Stockholm"));
35
     CargoTrackingViewAdapter adapter = new CargoTrackingViewAdapter(cargo, applicationContext, Locale.GERMAN, events, TimeZone.getTimeZone("Europe/Stockholm"));
34
 
36
 
35
-    assertEquals("XYZ", adapter.getTrackingId());
36
-    assertEquals("Hangzhou", adapter.getOrigin());
37
-    assertEquals("Helsinki", adapter.getDestination());
38
-    assertEquals("In port Helsinki", adapter.getStatusText());
37
+    assertThat(adapter.getTrackingId()).isEqualTo("XYZ");
38
+    assertThat(adapter.getOrigin()).isEqualTo("Hangzhou");
39
+    assertThat(adapter.getDestination()).isEqualTo("Helsinki");
40
+    assertThat(adapter.getStatusText()).isEqualTo("In port Helsinki");
39
 
41
 
40
     Iterator<CargoTrackingViewAdapter.HandlingEventViewAdapter> it = adapter.getEvents().iterator();
42
     Iterator<CargoTrackingViewAdapter.HandlingEventViewAdapter> it = adapter.getEvents().iterator();
41
 
43
 
42
     CargoTrackingViewAdapter.HandlingEventViewAdapter event = it.next();
44
     CargoTrackingViewAdapter.HandlingEventViewAdapter event = it.next();
43
-    assertEquals("RECEIVE", event.getType());
44
-    assertEquals("Hangzhou", event.getLocation());
45
-    assertEquals("1970-01-01 01:00", event.getTime());
46
-    assertEquals("", event.getVoyageNumber());
47
-    assertTrue(event.isExpected());
45
+    assertThat(event.getType()).isEqualTo("RECEIVE");
46
+    assertThat(event.getLocation()).isEqualTo("Hangzhou");
47
+    assertThat(event.getTime()).isEqualTo("1970-01-01 01:00");
48
+    assertThat(event.getVoyageNumber()).isEqualTo("");
49
+    assertThat(event.isExpected()).isTrue();
48
 
50
 
49
     event = it.next();
51
     event = it.next();
50
-    assertEquals("LOAD", event.getType());
51
-    assertEquals("Hangzhou", event.getLocation());
52
-    assertEquals("1970-01-01 01:00", event.getTime());
53
-    assertEquals("CM001", event.getVoyageNumber());
54
-    assertTrue(event.isExpected());
52
+    assertThat(event.getType()).isEqualTo("LOAD");
53
+    assertThat(event.getLocation()).isEqualTo("Hangzhou");
54
+    assertThat(event.getTime()).isEqualTo("1970-01-01 01:00");
55
+    assertThat(event.getVoyageNumber()).isEqualTo("CM001");
56
+    assertThat(event.isExpected()).isTrue();
55
 
57
 
56
     event = it.next();
58
     event = it.next();
57
-    assertEquals("UNLOAD", event.getType());
58
-    assertEquals("Helsinki", event.getLocation());
59
-    assertEquals("1970-01-01 01:00", event.getTime());
60
-    assertEquals("CM001", event.getVoyageNumber());
61
-    assertTrue(event.isExpected());
59
+    assertThat(event.getType()).isEqualTo("UNLOAD");
60
+    assertThat(event.getLocation()).isEqualTo("Helsinki");
61
+    assertThat(event.getTime()).isEqualTo("1970-01-01 01:00");
62
+    assertThat(event.getVoyageNumber()).isEqualTo("CM001");
63
+    assertThat(event.isExpected()).isTrue();
62
   }
64
   }
63
 
65
 
64
 }
66
 }

+ 7
- 5
src/test/java/se/citerus/dddsample/interfaces/tracking/TrackCommandValidatorTest.java Vedi File

5
 import org.springframework.validation.BindingResult;
5
 import org.springframework.validation.BindingResult;
6
 import org.springframework.validation.FieldError;
6
 import org.springframework.validation.FieldError;
7
 
7
 
8
+import static org.assertj.core.api.Assertions.assertThat;
9
+
8
 public class TrackCommandValidatorTest extends TestCase {
10
 public class TrackCommandValidatorTest extends TestCase {
9
 
11
 
10
   TrackCommandValidator validator;
12
   TrackCommandValidator validator;
20
   public void testValidateIllegalId() throws Exception {
22
   public void testValidateIllegalId() throws Exception {
21
     validator.validate(command, errors);
23
     validator.validate(command, errors);
22
 
24
 
23
-    assertEquals(1, errors.getErrorCount());
25
+    assertThat(errors.getErrorCount()).isEqualTo(1);
24
     FieldError error = errors.getFieldError("trackingId");
26
     FieldError error = errors.getFieldError("trackingId");
25
-    assertNotNull(error);
26
-    assertNull(error.getRejectedValue());
27
-    assertEquals("error.required", error.getCode());
27
+    assertThat(error).isNotNull();
28
+    assertThat(error.getRejectedValue()).isNull();
29
+    assertThat(error.getCode()).isEqualTo("error.required");
28
   }
30
   }
29
     
31
     
30
   public void testValidateSuccess() throws Exception {
32
   public void testValidateSuccess() throws Exception {
31
     command.setTrackingId("non-empty");
33
     command.setTrackingId("non-empty");
32
     validator.validate(command, errors);
34
     validator.validate(command, errors);
33
 
35
 
34
-    assertFalse(errors.hasErrors());
36
+    assertThat(errors.hasErrors()).isFalse();
35
   }
37
   }
36
 
38
 
37
 }
39
 }

+ 61
- 59
src/test/java/se/citerus/dddsample/scenario/CargoLifecycleScenarioTest.java Vedi File

8
 import se.citerus.dddsample.application.impl.BookingServiceImpl;
8
 import se.citerus.dddsample.application.impl.BookingServiceImpl;
9
 import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
9
 import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
10
 import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
10
 import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
11
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
12
 import se.citerus.dddsample.domain.model.cargo.*;
11
 import se.citerus.dddsample.domain.model.cargo.*;
13
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
14
-import static se.citerus.dddsample.domain.model.cargo.TransportStatus.*;
15
 import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
12
 import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
16
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
17
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
13
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
18
 import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
14
 import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
19
 import se.citerus.dddsample.domain.model.location.Location;
15
 import se.citerus.dddsample.domain.model.location.Location;
20
 import se.citerus.dddsample.domain.model.location.LocationRepository;
16
 import se.citerus.dddsample.domain.model.location.LocationRepository;
21
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
22
 import se.citerus.dddsample.domain.model.location.UnLocode;
17
 import se.citerus.dddsample.domain.model.location.UnLocode;
23
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
24
-import static se.citerus.dddsample.domain.model.voyage.Voyage.NONE;
25
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
18
 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
26
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
19
 import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
27
 import se.citerus.dddsample.domain.service.RoutingService;
20
 import se.citerus.dddsample.domain.service.RoutingService;
35
 import java.util.Date;
28
 import java.util.Date;
36
 import java.util.List;
29
 import java.util.List;
37
 
30
 
31
+import static org.assertj.core.api.Assertions.assertThat;
32
+import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
33
+import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
34
+import static se.citerus.dddsample.domain.model.cargo.TransportStatus.*;
35
+import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
36
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
37
+import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
38
+import static se.citerus.dddsample.domain.model.voyage.Voyage.NONE;
39
+
38
 public class CargoLifecycleScenarioTest extends TestCase {
40
 public class CargoLifecycleScenarioTest extends TestCase {
39
 
41
 
40
   /**
42
   /**
105
        Tracking the cargo basically amounts to presenting information extracted from
107
        Tracking the cargo basically amounts to presenting information extracted from
106
        the cargo aggregate in a suitable way. */
108
        the cargo aggregate in a suitable way. */
107
     Cargo cargo = cargoRepository.find(trackingId);
109
     Cargo cargo = cargoRepository.find(trackingId);
108
-    assertNotNull(cargo);
109
-    assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
110
-    assertEquals(NOT_ROUTED, cargo.delivery().routingStatus());
111
-    assertFalse(cargo.delivery().isMisdirected());
112
-    assertNull(cargo.delivery().estimatedTimeOfArrival());
113
-    assertNull(cargo.delivery().nextExpectedActivity());
110
+    assertThat(cargo).isNotNull();
111
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(NOT_RECEIVED);
112
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(NOT_ROUTED);
113
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
114
+    assertThat(cargo.delivery().estimatedTimeOfArrival()).isNull();
115
+    assertThat(cargo.delivery().nextExpectedActivity()).isNull();
114
 
116
 
115
     /* Use case 2: routing
117
     /* Use case 2: routing
116
 
118
 
124
     Itinerary itinerary = selectPreferedItinerary(itineraries);
126
     Itinerary itinerary = selectPreferedItinerary(itineraries);
125
     cargo.assignToRoute(itinerary);
127
     cargo.assignToRoute(itinerary);
126
 
128
 
127
-    assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
128
-    assertEquals(ROUTED, cargo.delivery().routingStatus());
129
-    assertNotNull(cargo.delivery().estimatedTimeOfArrival());
130
-    assertEquals(new HandlingActivity(RECEIVE, HONGKONG), cargo.delivery().nextExpectedActivity());
129
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(NOT_RECEIVED);
130
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(ROUTED);
131
+    assertThat(cargo.delivery().estimatedTimeOfArrival()).isNotNull();
132
+    assertThat(cargo.delivery().nextExpectedActivity()).isEqualTo(new HandlingActivity(RECEIVE, HONGKONG));
131
 
133
 
132
     /*
134
     /*
133
       Use case 3: handling
135
       Use case 3: handling
147
       toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), RECEIVE
149
       toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), RECEIVE
148
     );
150
     );
149
 
151
 
150
-    assertEquals(IN_PORT, cargo.delivery().transportStatus());
151
-    assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
152
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(IN_PORT);
153
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HONGKONG);
152
     
154
     
153
     // Next event: Load onto voyage CM003 in Hongkong
155
     // Next event: Load onto voyage CM003 in Hongkong
154
     handlingEventService.registerHandlingEvent(
156
     handlingEventService.registerHandlingEvent(
156
     );
158
     );
157
 
159
 
158
     // Check current state - should be ok
160
     // Check current state - should be ok
159
-    assertEquals(v100, cargo.delivery().currentVoyage());
160
-    assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
161
-    assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
162
-    assertFalse(cargo.delivery().isMisdirected());
163
-    assertEquals(new HandlingActivity(UNLOAD, NEWYORK, v100), cargo.delivery().nextExpectedActivity());
161
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(v100);
162
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HONGKONG);
163
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(ONBOARD_CARRIER);
164
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
165
+    assertThat(cargo.delivery().nextExpectedActivity()).isEqualTo(new HandlingActivity(UNLOAD, NEWYORK, v100));
164
 
166
 
165
 
167
 
166
     /*
168
     /*
187
     );
189
     );
188
 
190
 
189
     // Check current state - cargo is misdirected!
191
     // Check current state - cargo is misdirected!
190
-    assertEquals(NONE, cargo.delivery().currentVoyage());
191
-    assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
192
-    assertEquals(IN_PORT, cargo.delivery().transportStatus());
193
-    assertTrue(cargo.delivery().isMisdirected());
194
-    assertNull(cargo.delivery().nextExpectedActivity());
192
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(NONE);
193
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(TOKYO);
194
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(IN_PORT);
195
+    assertThat(cargo.delivery().isMisdirected()).isTrue();
196
+    assertThat(cargo.delivery().nextExpectedActivity()).isNull();
195
 
197
 
196
 
198
 
197
     // -- Cargo needs to be rerouted --
199
     // -- Cargo needs to be rerouted --
203
     cargo.specifyNewRoute(fromTokyo);
205
     cargo.specifyNewRoute(fromTokyo);
204
 
206
 
205
     // The old itinerary does not satisfy the new specification
207
     // The old itinerary does not satisfy the new specification
206
-    assertEquals(MISROUTED, cargo.delivery().routingStatus());
207
-    assertNull(cargo.delivery().nextExpectedActivity());
208
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(MISROUTED);
209
+    assertThat(cargo.delivery().nextExpectedActivity()).isNull();
208
 
210
 
209
     // Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
211
     // Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
210
     List<Itinerary> newItineraries = bookingService.requestPossibleRoutesForCargo(cargo.trackingId());
212
     List<Itinerary> newItineraries = bookingService.requestPossibleRoutesForCargo(cargo.trackingId());
212
     cargo.assignToRoute(newItinerary);
214
     cargo.assignToRoute(newItinerary);
213
 
215
 
214
     // New itinerary should satisfy new route
216
     // New itinerary should satisfy new route
215
-    assertEquals(ROUTED, cargo.delivery().routingStatus());
217
+    assertThat(cargo.delivery().routingStatus()).isEqualTo(ROUTED);
216
 
218
 
217
     // TODO we can't handle the face that after a reroute, the cargo isn't misdirected anymore
219
     // TODO we can't handle the face that after a reroute, the cargo isn't misdirected anymore
218
-    //assertFalse(cargo.isMisdirected());
219
-    //assertEquals(new HandlingActivity(LOAD, TOKYO), cargo.nextExpectedActivity());
220
+    //assertThat(cargo.isMisdirected()).isFalse();
221
+    //assertThat(, cargo.nextExpectedActivity()).isEqualTo(new HandlingActivity(LOAD, TOKYO));
220
 
222
 
221
 
223
 
222
     // -- Cargo has been rerouted, shipping continues --
224
     // -- Cargo has been rerouted, shipping continues --
228
     );
230
     );
229
 
231
 
230
     // Check current state - should be ok
232
     // Check current state - should be ok
231
-    assertEquals(v300, cargo.delivery().currentVoyage());
232
-    assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
233
-    assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
234
-    assertFalse(cargo.delivery().isMisdirected());
235
-    assertEquals(new HandlingActivity(UNLOAD, HAMBURG, v300), cargo.delivery().nextExpectedActivity());
233
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(v300);
234
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(TOKYO);
235
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(ONBOARD_CARRIER);
236
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
237
+    assertThat(cargo.delivery().nextExpectedActivity()).isEqualTo(new HandlingActivity(UNLOAD, HAMBURG, v300));
236
 
238
 
237
     // Unload in Hamburg
239
     // Unload in Hamburg
238
     handlingEventService.registerHandlingEvent(
240
     handlingEventService.registerHandlingEvent(
240
     );
242
     );
241
 
243
 
242
     // Check current state - should be ok
244
     // Check current state - should be ok
243
-    assertEquals(NONE, cargo.delivery().currentVoyage());
244
-    assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
245
-    assertEquals(IN_PORT, cargo.delivery().transportStatus());
246
-    assertFalse(cargo.delivery().isMisdirected());
247
-    assertEquals(new HandlingActivity(LOAD, HAMBURG, v400), cargo.delivery().nextExpectedActivity());
245
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(NONE);
246
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HAMBURG);
247
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(IN_PORT);
248
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
249
+    assertThat(cargo.delivery().nextExpectedActivity()).isEqualTo(new HandlingActivity(LOAD, HAMBURG, v400));
248
 
250
 
249
 
251
 
250
     // Load in Hamburg
252
     // Load in Hamburg
253
     );
255
     );
254
 
256
 
255
     // Check current state - should be ok
257
     // Check current state - should be ok
256
-    assertEquals(v400, cargo.delivery().currentVoyage());
257
-    assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
258
-    assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
259
-    assertFalse(cargo.delivery().isMisdirected());
260
-    assertEquals(new HandlingActivity(UNLOAD, STOCKHOLM, v400), cargo.delivery().nextExpectedActivity());
258
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(v400);
259
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HAMBURG);
260
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(ONBOARD_CARRIER);
261
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
262
+    assertThat(cargo.delivery().nextExpectedActivity()).isEqualTo(new HandlingActivity(UNLOAD, STOCKHOLM, v400));
261
 
263
 
262
 
264
 
263
     // Unload in Stockholm
265
     // Unload in Stockholm
266
     );
268
     );
267
 
269
 
268
     // Check current state - should be ok
270
     // Check current state - should be ok
269
-    assertEquals(NONE, cargo.delivery().currentVoyage());
270
-    assertEquals(STOCKHOLM, cargo.delivery().lastKnownLocation());
271
-    assertEquals(IN_PORT, cargo.delivery().transportStatus());
272
-    assertFalse(cargo.delivery().isMisdirected());
273
-    assertEquals(new HandlingActivity(CLAIM, STOCKHOLM), cargo.delivery().nextExpectedActivity());
271
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(NONE);
272
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(STOCKHOLM);
273
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(IN_PORT);
274
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
275
+    assertThat(cargo.delivery().nextExpectedActivity()).isEqualTo(new HandlingActivity(CLAIM, STOCKHOLM));
274
 
276
 
275
     // Finally, cargo is claimed in Stockholm. This ends the cargo lifecycle from our perspective.
277
     // Finally, cargo is claimed in Stockholm. This ends the cargo lifecycle from our perspective.
276
     handlingEventService.registerHandlingEvent(
278
     handlingEventService.registerHandlingEvent(
278
     );
280
     );
279
 
281
 
280
     // Check current state - should be ok
282
     // Check current state - should be ok
281
-    assertEquals(NONE, cargo.delivery().currentVoyage());
282
-    assertEquals(STOCKHOLM, cargo.delivery().lastKnownLocation());
283
-    assertEquals(CLAIMED, cargo.delivery().transportStatus());
284
-    assertFalse(cargo.delivery().isMisdirected());
285
-    assertNull(cargo.delivery().nextExpectedActivity());
283
+    assertThat(cargo.delivery().currentVoyage()).isEqualTo(NONE);
284
+    assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(STOCKHOLM);
285
+    assertThat(cargo.delivery().transportStatus()).isEqualTo(CLAIMED);
286
+    assertThat(cargo.delivery().isMisdirected()).isFalse();
287
+    assertThat(cargo.delivery().nextExpectedActivity()).isNull();
286
   }
288
   }
287
 
289
 
288
 
290