|
8 | 8 | import io.legacyfighter.cabs.money.Money; |
9 | 9 | import io.legacyfighter.cabs.repository.*; |
10 | 10 |
|
11 | | -import io.legacyfighter.cabs.service.AwardsService; |
12 | | -import io.legacyfighter.cabs.service.CarTypeService; |
13 | | -import io.legacyfighter.cabs.service.ClaimService; |
14 | | -import io.legacyfighter.cabs.service.DriverService; |
| 11 | +import io.legacyfighter.cabs.service.*; |
15 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
16 | 13 | import org.springframework.stereotype.Component; |
17 | 14 |
|
| 15 | +import java.time.Clock; |
18 | 16 | import java.time.Instant; |
19 | 17 | import java.time.LocalDateTime; |
20 | 18 | import java.time.ZoneOffset; |
| 19 | +import java.time.temporal.ChronoUnit; |
21 | 20 | import java.util.stream.IntStream; |
22 | 21 |
|
| 22 | +import static io.legacyfighter.cabs.entity.CarType.CarClass.VAN; |
23 | 23 | import static java.util.stream.IntStream.range; |
| 24 | +import static org.mockito.Mockito.when; |
24 | 25 |
|
25 | 26 |
|
26 | 27 | @Component |
@@ -50,9 +51,18 @@ public class Fixtures { |
50 | 51 | @Autowired |
51 | 52 | AwardsService awardsService; |
52 | 53 |
|
| 54 | + @Autowired |
| 55 | + TransitService transitService; |
| 56 | + |
53 | 57 | @Autowired |
54 | 58 | DriverAttributeRepository driverAttributeRepository; |
55 | 59 |
|
| 60 | + @Autowired |
| 61 | + DriverSessionService driverSessionService; |
| 62 | + |
| 63 | + @Autowired |
| 64 | + DriverTrackingService driverTrackingService; |
| 65 | + |
56 | 66 | public Client aClient() { |
57 | 67 | return clientRepository.save(new Client()); |
58 | 68 | } |
@@ -104,28 +114,63 @@ public Driver aDriver(Status status, String name, String lastName, String driver |
104 | 114 | return driverService.createDriver(driverLicense, lastName, name, Driver.Type.REGULAR, status, ""); |
105 | 115 | } |
106 | 116 |
|
| 117 | + public Driver aNearbyDriver(String plateNumber) { |
| 118 | + Driver driver = aDriver(); |
| 119 | + driverHasFee(driver, DriverFee.FeeType.FLAT, 10); |
| 120 | + driverSessionService.logIn(driver.getId(), plateNumber, VAN, "BRAND"); |
| 121 | + driverTrackingService.registerPosition(driver.getId(), 1, 1, Instant.now()); |
| 122 | + return driver; |
| 123 | + } |
| 124 | + |
107 | 125 | public Transit aCompletedTransitAt(int price, Instant when) { |
108 | 126 | return aCompletedTransitAt(price, when, aClient(), aDriver()); |
109 | 127 | } |
110 | 128 |
|
111 | | - public Transit aCompletedTransitAt(int price, Instant when, Client client, Driver driver) { |
112 | | - Address destination = addressRepository.save(new Address("Polska", "Warszawa", "Zytnia", 20)); |
| 129 | + public Transit aRequestedAndCompletedTransit(int price, Instant publishedAt, Instant completedAt, Client client, Driver driver, Address from, Address destination) { |
| 130 | + from = addressRepository.save(from); |
| 131 | + destination = addressRepository.save(destination); |
113 | 132 | Transit transit = new Transit( |
114 | | - addressRepository.save(new Address("Polska", "Warszawa", "Młynarska", 20)), |
| 133 | + from, |
115 | 134 | destination, |
116 | 135 | client, |
117 | 136 | null, |
118 | | - when, |
| 137 | + publishedAt, |
119 | 138 | Distance.ZERO); |
120 | | - transit.publishAt(when); |
| 139 | + transit.publishAt(publishedAt); |
121 | 140 | transit.proposeTo(driver); |
122 | | - transit.acceptBy(driver, Instant.now()); |
123 | | - transit.start(Instant.now()); |
124 | | - transit.completeAt(Instant.now(), destination, Distance.ofKm(20)); |
| 141 | + transit.acceptBy(driver, publishedAt); |
| 142 | + transit.start(publishedAt); |
| 143 | + transit.completeAt(completedAt, destination, Distance.ofKm(1)); |
125 | 144 | transit.setPrice(new Money(price)); |
126 | 145 | return transitRepository.save(transit); |
127 | 146 | } |
128 | 147 |
|
| 148 | + public Transit aCompletedTransitAt(int price, Instant publishedAt, Instant completedAt, Client client, Driver driver) { |
| 149 | + Address destination = new Address("Polska", "Warszawa", "Zytnia", 20); |
| 150 | + Address from = new Address("Polska", "Warszawa", "Młynarska", 20); |
| 151 | + return aRequestedAndCompletedTransit(price, publishedAt, completedAt, client, driver, from, destination); |
| 152 | + } |
| 153 | + |
| 154 | + public Transit aCompletedTransitAt(int price, Instant publishedAt, Client client, Driver driver) { |
| 155 | + return aCompletedTransitAt(price, publishedAt, publishedAt.plus(10, ChronoUnit.MINUTES), client, driver); |
| 156 | + } |
| 157 | + |
| 158 | + public Transit aRequestedAndCompletedTransit(int price, Instant publishedAt, Instant completedAt, Client client, Driver driver, Address from, Address destination, Clock clock) { |
| 159 | + from = addressRepository.save(from); |
| 160 | + destination = addressRepository.save(destination); |
| 161 | + |
| 162 | + when(clock.instant()).thenReturn(publishedAt); |
| 163 | + Transit transit = transitService.createTransit(client.getId(), from, destination, VAN); |
| 164 | + transitService.publishTransit(transit.getId()); |
| 165 | + transitService.findDriversForTransit(transit.getId()); |
| 166 | + transitService.acceptTransit(driver.getId(), transit.getId()); |
| 167 | + transitService.startTransit(driver.getId(), transit.getId()); |
| 168 | + when(clock.instant()).thenReturn(completedAt); |
| 169 | + transitService.completeTransit(driver.getId(), transit.getId(), destination); |
| 170 | + |
| 171 | + return transitRepository.getOne(transit.getId()); |
| 172 | + } |
| 173 | + |
129 | 174 | public CarType anActiveCarCategory(CarType.CarClass carClass) { |
130 | 175 | CarTypeDTO carTypeDTO = new CarTypeDTO(); |
131 | 176 | carTypeDTO.setCarClass(carClass); |
|
0 commit comments