Selaa lähdekoodia

Merge e414008c6300fe382a7de0c9b1502028217d8a94 into 08ad303bee24b41cc8cf0319b28fcaa704b31380

Marten Deinum 8 vuotta sitten
vanhempi
commit
6f2103b747

+ 0
- 6
pom.xml Näytä tiedosto

@@ -151,12 +151,6 @@
151 151
             <scope>test</scope>
152 152
         </dependency>
153 153
         <dependency>
154
-            <groupId>org.easymock</groupId>
155
-            <artifactId>easymock</artifactId>
156
-            <version>2.3</version>
157
-            <scope>test</scope>
158
-        </dependency>
159
-        <dependency>
160 154
             <groupId>org.assertj</groupId>
161 155
             <artifactId>assertj-core</artifactId>
162 156
             <scope>test</scope>

+ 20
- 17
src/test/java/se/citerus/dddsample/application/BookingServiceTest.java Näytä tiedosto

@@ -1,11 +1,18 @@
1 1
 package se.citerus.dddsample.application;
2 2
 
3 3
 import static org.assertj.core.api.Assertions.assertThat;
4
-import static org.easymock.EasyMock.createMock;
5
-import static org.easymock.EasyMock.expect;
6
-import static org.easymock.EasyMock.isA;
7
-import static org.easymock.EasyMock.replay;
8
-import static org.easymock.EasyMock.verify;
4
+import static org.mockito.Matchers.any;
5
+import static org.mockito.Matchers.isA;
6
+import static org.mockito.Mockito.mock;
7
+import static org.mockito.Mockito.times;
8
+import static org.mockito.Mockito.verify;
9
+import static org.mockito.Mockito.when;
10
+import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
11
+import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
12
+
13
+import java.util.Date;
14
+
15
+import static org.assertj.core.api.Assertions.assertThat;
9 16
 import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
10 17
 import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
11 18
 
@@ -14,7 +21,6 @@ import java.util.Date;
14 21
 import org.junit.After;
15 22
 import org.junit.Before;
16 23
 import org.junit.Test;
17
-
18 24
 import se.citerus.dddsample.application.impl.BookingServiceImpl;
19 25
 import se.citerus.dddsample.domain.model.cargo.Cargo;
20 26
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
@@ -32,9 +38,9 @@ public class BookingServiceTest {
32 38
 
33 39
   @Before
34 40
   public void setUp() {
35
-    cargoRepository = createMock(CargoRepository.class);
36
-    locationRepository = createMock(LocationRepository.class);
37
-    routingService = createMock(RoutingService.class);
41
+    cargoRepository = mock(CargoRepository.class);
42
+    locationRepository = mock(LocationRepository.class);
43
+    routingService = mock(RoutingService.class);
38 44
     bookingService = new BookingServiceImpl(cargoRepository, locationRepository, routingService);
39 45
   }
40 46
 
@@ -44,13 +50,9 @@ public class BookingServiceTest {
44 50
     UnLocode fromUnlocode = new UnLocode("USCHI");
45 51
     UnLocode toUnlocode = new UnLocode("SESTO");
46 52
 
47
-    expect(cargoRepository.nextTrackingId()).andReturn(expectedTrackingId);
48
-    expect(locationRepository.find(fromUnlocode)).andReturn(CHICAGO);
49
-    expect(locationRepository.find(toUnlocode)).andReturn(STOCKHOLM);
50
-
51
-    cargoRepository.store(isA(Cargo.class));
52
-
53
-    replay(cargoRepository, locationRepository);
53
+    when(cargoRepository.nextTrackingId()).thenReturn(expectedTrackingId);
54
+    when(locationRepository.find(fromUnlocode)).thenReturn(CHICAGO);
55
+    when(locationRepository.find(toUnlocode)).thenReturn(STOCKHOLM);
54 56
 
55 57
     TrackingId trackingId = bookingService.bookNewCargo(fromUnlocode, toUnlocode, new Date());
56 58
     assertThat(trackingId).isEqualTo(expectedTrackingId);
@@ -58,6 +60,7 @@ public class BookingServiceTest {
58 60
 
59 61
   @After
60 62
   public void tearDown() {
61
-    verify(cargoRepository, locationRepository);
63
+    verify(cargoRepository, times(1)).store(isA(Cargo.class));
64
+    verify(locationRepository, times(2)).find(any(UnLocode.class));
62 65
   }
63 66
 }

+ 15
- 18
src/test/java/se/citerus/dddsample/application/HandlingEventServiceTest.java Näytä tiedosto

@@ -1,10 +1,10 @@
1 1
 package se.citerus.dddsample.application;
2 2
 
3
-import static org.easymock.EasyMock.createMock;
4
-import static org.easymock.EasyMock.expect;
5
-import static org.easymock.EasyMock.isA;
6
-import static org.easymock.EasyMock.replay;
7
-import static org.easymock.EasyMock.verify;
3
+import static org.mockito.Matchers.isA;
4
+import static org.mockito.Mockito.mock;
5
+import static org.mockito.Mockito.times;
6
+import static org.mockito.Mockito.verify;
7
+import static org.mockito.Mockito.when;
8 8
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
9 9
 import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
10 10
 import static se.citerus.dddsample.domain.model.location.SampleLocations.TOKYO;
@@ -39,11 +39,11 @@ public class HandlingEventServiceTest {
39 39
 
40 40
   @Before
41 41
   public void setUp() {
42
-    cargoRepository = createMock(CargoRepository.class);
43
-    voyageRepository = createMock(VoyageRepository.class);
44
-    handlingEventRepository = createMock(HandlingEventRepository.class);
45
-    locationRepository = createMock(LocationRepository.class);
46
-    applicationEvents = createMock(ApplicationEvents.class);
42
+    cargoRepository = mock(CargoRepository.class);
43
+    voyageRepository = mock(VoyageRepository.class);
44
+    handlingEventRepository = mock(HandlingEventRepository.class);
45
+    locationRepository = mock(LocationRepository.class);
46
+    applicationEvents = mock(ApplicationEvents.class);
47 47
 
48 48
     HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
49 49
     service = new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
@@ -51,18 +51,15 @@ public class HandlingEventServiceTest {
51 51
 
52 52
   @After
53 53
   public void tearDown() {
54
-    verify(cargoRepository, voyageRepository, handlingEventRepository, applicationEvents);
54
+    verify(handlingEventRepository, times(1)).store(isA(HandlingEvent.class));
55
+    verify(applicationEvents, times(1)).cargoWasHandled(isA(HandlingEvent.class));
55 56
   }
56 57
 
57 58
   @Test
58 59
   public void testRegisterEvent() throws Exception {
59
-    expect(cargoRepository.find(cargo.trackingId())).andReturn(cargo);
60
-    expect(voyageRepository.find(CM001.voyageNumber())).andReturn(CM001);
61
-    expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
62
-    handlingEventRepository.store(isA(HandlingEvent.class));
63
-    applicationEvents.cargoWasHandled(isA(HandlingEvent.class));
64
-
65
-    replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
60
+    when(cargoRepository.find(cargo.trackingId())).thenReturn(cargo);
61
+    when(voyageRepository.find(CM001.voyageNumber())).thenReturn(CM001);
62
+    when(locationRepository.find(STOCKHOLM.unLocode())).thenReturn(STOCKHOLM);
66 63
 
67 64
     service.registerHandlingEvent(new Date(), cargo.trackingId(), CM001.voyageNumber(), STOCKHOLM.unLocode(), HandlingEvent.Type.LOAD);
68 65
   }

+ 14
- 33
src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java Näytä tiedosto

@@ -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
 }

+ 6
- 9
src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java Näytä tiedosto

@@ -1,11 +1,10 @@
1 1
 package se.citerus.dddsample.infrastructure.routing;
2 2
 
3 3
 import static org.assertj.core.api.Assertions.assertThat;
4
-import static org.easymock.EasyMock.createMock;
5
-import static org.easymock.EasyMock.expect;
6
-import static org.easymock.EasyMock.isA;
7
-import static org.easymock.EasyMock.replay;
8
-import static org.easymock.EasyMock.verify;
4
+import static org.mockito.Matchers.isA;
5
+import static org.mockito.Mockito.mock;
6
+import static org.mockito.Mockito.verify;
7
+import static org.mockito.Mockito.when;
9 8
 import static se.citerus.dddsample.domain.model.location.SampleLocations.GOTHENBURG;
10 9
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
11 10
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
@@ -46,7 +45,7 @@ public class ExternalRoutingServiceTest {
46 45
     LocationRepository locationRepository = new LocationRepositoryInMem();
47 46
     externalRoutingService.setLocationRepository(locationRepository);
48 47
 
49
-    voyageRepository = createMock(VoyageRepository.class);
48
+    voyageRepository = mock(VoyageRepository.class);
50 49
     externalRoutingService.setVoyageRepository(voyageRepository);
51 50
 
52 51
     GraphTraversalService graphTraversalService = new GraphTraversalServiceImpl(new GraphDAOStub() {
@@ -67,9 +66,7 @@ public class ExternalRoutingServiceTest {
67 66
     RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, new Date());
68 67
     Cargo cargo = new Cargo(trackingId, routeSpecification);
69 68
 
70
-    expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.CM002);
71
-    
72
-    replay(voyageRepository);
69
+    when(voyageRepository.find(isA(VoyageNumber.class))).thenReturn(SampleVoyages.CM002);
73 70
 
74 71
     List<Itinerary> candidates = externalRoutingService.fetchRoutesForSpecification(routeSpecification);
75 72
     assertThat(candidates).isNotNull();

+ 6
- 9
src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/ItineraryCandidateDTOAssemblerTest.java Näytä tiedosto

@@ -1,9 +1,8 @@
1 1
 package se.citerus.dddsample.interfaces.booking.facade.internal.assembler;
2 2
 
3 3
 import static org.assertj.core.api.Assertions.assertThat;
4
-import static org.easymock.EasyMock.createMock;
5
-import static org.easymock.EasyMock.expect;
6
-import static org.easymock.EasyMock.replay;
4
+import static org.mockito.Mockito.mock;
5
+import static org.mockito.Mockito.when;
7 6
 import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
8 7
 import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
9 8
 import static se.citerus.dddsample.domain.model.location.SampleLocations.MELBOURNE;
@@ -68,15 +67,13 @@ public class ItineraryCandidateDTOAssemblerTest {
68 67
     legs.add(new LegDTO("CM001", "AAAAA", "BBBBB", new Date(), new Date()));
69 68
     legs.add(new LegDTO("CM001", "BBBBB", "CCCCC", new Date(), new Date()));
70 69
 
71
-    final LocationRepository locationRepository = createMock(LocationRepository.class);
72
-    expect(locationRepository.find(new UnLocode("AAAAA"))).andReturn(HONGKONG);
73
-    expect(locationRepository.find(new UnLocode("BBBBB"))).andReturn(TOKYO).times(2);
74
-    expect(locationRepository.find(new UnLocode("CCCCC"))).andReturn(CHICAGO);
70
+    final LocationRepository locationRepository = mock(LocationRepository.class);
71
+    when(locationRepository.find(new UnLocode("AAAAA"))).thenReturn(HONGKONG);
72
+    when(locationRepository.find(new UnLocode("BBBBB"))).thenReturn(TOKYO);
73
+    when(locationRepository.find(new UnLocode("CCCCC"))).thenReturn(CHICAGO);
75 74
 
76 75
     final VoyageRepository voyageRepository = new VoyageRepositoryInMem();
77 76
 
78
-    replay(locationRepository);
79
-
80 77
 
81 78
     // Tested call
82 79
     final Itinerary itinerary = assembler.fromDTO(new RouteCandidateDTO(legs), voyageRepository, locationRepository);