|
|
@@ -2,10 +2,8 @@ package se.citerus.dddsample.domain.model.handling;
|
|
2
|
2
|
|
|
3
|
3
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
4
|
4
|
import static org.assertj.core.api.Assertions.fail;
|
|
5
|
|
-import static org.easymock.EasyMock.createMock;
|
|
6
|
|
-import static org.easymock.EasyMock.expect;
|
|
7
|
|
-import static org.easymock.EasyMock.replay;
|
|
8
|
|
-import static org.easymock.EasyMock.verify;
|
|
|
5
|
+import static org.mockito.Mockito.mock;
|
|
|
6
|
+import static org.mockito.Mockito.when;
|
|
9
|
7
|
import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type;
|
|
10
|
8
|
import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
|
|
11
|
9
|
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
|
|
|
@@ -14,7 +12,6 @@ import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
|
|
14
|
12
|
|
|
15
|
13
|
import java.util.Date;
|
|
16
|
14
|
|
|
17
|
|
-import org.junit.After;
|
|
18
|
15
|
import org.junit.Before;
|
|
19
|
16
|
import org.junit.Test;
|
|
20
|
17
|
|
|
|
@@ -32,23 +29,21 @@ import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepository
|
|
32
|
29
|
|
|
33
|
30
|
public class HandlingEventFactoryTest {
|
|
34
|
31
|
|
|
35
|
|
- HandlingEventFactory factory;
|
|
36
|
|
- CargoRepository cargoRepository;
|
|
37
|
|
- VoyageRepository voyageRepository;
|
|
38
|
|
- LocationRepository locationRepository;
|
|
39
|
|
- TrackingId trackingId;
|
|
40
|
|
- Cargo cargo;
|
|
|
32
|
+ private HandlingEventFactory factory;
|
|
|
33
|
+ private CargoRepository cargoRepository;
|
|
|
34
|
+ private VoyageRepository voyageRepository;
|
|
|
35
|
+ private LocationRepository locationRepository;
|
|
|
36
|
+ private TrackingId trackingId;
|
|
|
37
|
+ private Cargo cargo;
|
|
41
|
38
|
|
|
42
|
39
|
@Before
|
|
43
|
40
|
public void setUp() {
|
|
44
|
41
|
|
|
45
|
|
- cargoRepository = createMock(CargoRepository.class);
|
|
|
42
|
+ cargoRepository = mock(CargoRepository.class);
|
|
46
|
43
|
voyageRepository = new VoyageRepositoryInMem();
|
|
47
|
44
|
locationRepository = new LocationRepositoryInMem();
|
|
48
|
45
|
factory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
|
|
49
|
46
|
|
|
50
|
|
-
|
|
51
|
|
-
|
|
52
|
47
|
trackingId = new TrackingId("ABC");
|
|
53
|
48
|
RouteSpecification routeSpecification = new RouteSpecification(TOKYO, HELSINKI, new Date());
|
|
54
|
49
|
cargo = new Cargo(trackingId, routeSpecification);
|
|
|
@@ -56,9 +51,7 @@ public class HandlingEventFactoryTest {
|
|
56
|
51
|
|
|
57
|
52
|
@Test
|
|
58
|
53
|
public void testCreateHandlingEventWithCarrierMovement() throws Exception {
|
|
59
|
|
- expect(cargoRepository.find(trackingId)).andReturn(cargo);
|
|
60
|
|
-
|
|
61
|
|
- replay(cargoRepository);
|
|
|
54
|
+ when(cargoRepository.find(trackingId)).thenReturn(cargo);
|
|
62
|
55
|
|
|
63
|
56
|
VoyageNumber voyageNumber = CM001.voyageNumber();
|
|
64
|
57
|
UnLocode unLocode = STOCKHOLM.unLocode();
|
|
|
@@ -76,9 +69,7 @@ public class HandlingEventFactoryTest {
|
|
76
|
69
|
|
|
77
|
70
|
@Test
|
|
78
|
71
|
public void testCreateHandlingEventWithoutCarrierMovement() throws Exception {
|
|
79
|
|
- expect(cargoRepository.find(trackingId)).andReturn(cargo);
|
|
80
|
|
-
|
|
81
|
|
- replay(cargoRepository);
|
|
|
72
|
+ when(cargoRepository.find(trackingId)).thenReturn(cargo);
|
|
82
|
73
|
|
|
83
|
74
|
UnLocode unLocode = STOCKHOLM.unLocode();
|
|
84
|
75
|
HandlingEvent handlingEvent = factory.createHandlingEvent(
|
|
|
@@ -95,9 +86,7 @@ public class HandlingEventFactoryTest {
|
|
95
|
86
|
|
|
96
|
87
|
@Test
|
|
97
|
88
|
public void testCreateHandlingEventUnknownLocation() throws Exception {
|
|
98
|
|
- expect(cargoRepository.find(trackingId)).andReturn(cargo);
|
|
99
|
|
-
|
|
100
|
|
- replay(cargoRepository);
|
|
|
89
|
+ when(cargoRepository.find(trackingId)).thenReturn(cargo);
|
|
101
|
90
|
|
|
102
|
91
|
UnLocode invalid = new UnLocode("NOEXT");
|
|
103
|
92
|
try {
|
|
|
@@ -110,9 +99,7 @@ public class HandlingEventFactoryTest {
|
|
110
|
99
|
|
|
111
|
100
|
@Test
|
|
112
|
101
|
public void testCreateHandlingEventUnknownCarrierMovement() throws Exception {
|
|
113
|
|
- expect(cargoRepository.find(trackingId)).andReturn(cargo);
|
|
114
|
|
-
|
|
115
|
|
- replay(cargoRepository);
|
|
|
102
|
+ when(cargoRepository.find(trackingId)).thenReturn(cargo);
|
|
116
|
103
|
|
|
117
|
104
|
try {
|
|
118
|
105
|
VoyageNumber invalid = new VoyageNumber("XXX");
|
|
|
@@ -125,9 +112,7 @@ public class HandlingEventFactoryTest {
|
|
125
|
112
|
|
|
126
|
113
|
@Test
|
|
127
|
114
|
public void testCreateHandlingEventUnknownTrackingId() throws Exception {
|
|
128
|
|
- expect(cargoRepository.find(trackingId)).andReturn(null);
|
|
129
|
|
-
|
|
130
|
|
- replay(cargoRepository);
|
|
|
115
|
+ when(cargoRepository.find(trackingId)).thenReturn(null);
|
|
131
|
116
|
|
|
132
|
117
|
try {
|
|
133
|
118
|
factory.createHandlingEvent(
|
|
|
@@ -137,8 +122,4 @@ public class HandlingEventFactoryTest {
|
|
137
|
122
|
} catch (UnknownCargoException expected) {}
|
|
138
|
123
|
}
|
|
139
|
124
|
|
|
140
|
|
- @After
|
|
141
|
|
- public void tearDown() {
|
|
142
|
|
- verify(cargoRepository);
|
|
143
|
|
- }
|
|
144
|
125
|
}
|