-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikita Pavlovskiy
committed
Aug 21, 2023
1 parent
ca43041
commit 376c7c3
Showing
7 changed files
with
112 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
apps/backend/api/src/main/java/com/nikitades/carres/domain/TimeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.nikitades.carres.domain; | ||
|
||
import java.time.Instant; | ||
|
||
public interface TimeProvider { | ||
public Instant utcNow(); | ||
} |
13 changes: 13 additions & 0 deletions
13
.../backend/api/src/main/java/com/nikitades/carres/infrastructure/java/JavaTimeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.nikitades.carres.infrastructure.java; | ||
|
||
import com.nikitades.carres.domain.TimeProvider; | ||
import java.time.Instant; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class JavaTimeProvider implements TimeProvider { | ||
|
||
public Instant utcNow() { | ||
return Instant.now(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,16 @@ | |
import com.nikitades.carres.domain.Notifier; | ||
import com.nikitades.carres.domain.Reservation; | ||
import com.nikitades.carres.domain.ReservationRepository; | ||
import com.nikitades.carres.domain.TimeProvider; | ||
import com.nikitades.carres.infrastructure.java.JavaTimeProvider; | ||
import com.nikitades.carres.infrastructure.java.JavaUuidProvider; | ||
import com.nikitades.carres.infrastructure.prometheus.AnalyticsReporter; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
@@ -48,6 +52,8 @@ class ReservationModuleTest { | |
|
||
UuidProvider uuidProvider = new JavaUuidProvider(); | ||
|
||
TimeProvider timeProvider = new JavaTimeProvider(); | ||
|
||
ReservationModule instance; | ||
|
||
@BeforeEach | ||
|
@@ -57,6 +63,7 @@ void init() { | |
reservationRepository, | ||
carRepository, | ||
uuidProvider, | ||
timeProvider, | ||
analyticsReporter, | ||
notifier | ||
); | ||
|
@@ -75,7 +82,7 @@ void whenMissingCarIdIsPassed_thenNotFoundExceptionIsThrown() { | |
UUID.randomUUID(), | ||
"[email protected]", | ||
UUID.randomUUID(), | ||
Instant.now(), | ||
timeProvider.utcNow(), | ||
30 | ||
) | ||
); | ||
|
@@ -95,7 +102,7 @@ void whenTooShortReservationDurationIsPassed_thenBadRequestExceptionIsThrown() { | |
UUID.randomUUID(), | ||
"[email protected]", | ||
UUID.randomUUID(), | ||
Instant.now(), | ||
timeProvider.utcNow(), | ||
10 | ||
) | ||
); | ||
|
@@ -115,7 +122,7 @@ void whenReservationIsMadeSoonerThanACertainTimeFromNow_thenBadRequestExceptionI | |
UUID.randomUUID(), | ||
"[email protected]", | ||
UUID.randomUUID(), | ||
Instant.now().plus(Duration.ofMinutes(5)), | ||
timeProvider.utcNow().plus(Duration.ofMinutes(5)), | ||
30 | ||
) | ||
); | ||
|
@@ -132,21 +139,23 @@ void whenOtherReservationsOverlapWithNewlyCreatedOne_thenBadRequestExceptionIsTh | |
.of(Reservation.class) | ||
.set( | ||
field(Reservation::getStartsAt), | ||
LocalDateTime | ||
.now() | ||
timeProvider | ||
.utcNow() | ||
.atZone(ZoneId.of("UTC")) | ||
.plus(Duration.ofDays(1)) | ||
.withHour(15) | ||
.withMinute(0) | ||
.toInstant(ZoneOffset.UTC) | ||
.toInstant() | ||
) | ||
.set( | ||
field(Reservation::getEndsAt), | ||
LocalDateTime | ||
.now() | ||
timeProvider | ||
.utcNow() | ||
.atZone(ZoneId.of("UTC")) | ||
.plus(Duration.ofDays(1)) | ||
.withHour(15) | ||
.withMinute(30) | ||
.toInstant(ZoneOffset.UTC) | ||
.toInstant() | ||
) | ||
.create(); | ||
when(reservationRepository.findByCarId(any(UUID.class))).thenReturn(List.of(reservation1)); | ||
|
@@ -159,12 +168,13 @@ void whenOtherReservationsOverlapWithNewlyCreatedOne_thenBadRequestExceptionIsTh | |
UUID.randomUUID(), | ||
"[email protected]", | ||
UUID.randomUUID(), | ||
LocalDateTime | ||
.now() | ||
timeProvider | ||
.utcNow() | ||
.atZone(ZoneId.of("UTC")) | ||
.plus(Duration.ofDays(1)) | ||
.withHour(15) | ||
.withMinute(15) | ||
.toInstant(ZoneOffset.UTC), | ||
.toInstant(), | ||
15 | ||
); | ||
} | ||
|
@@ -182,12 +192,13 @@ void whenReservationSuccessfullyCreated_thenAnalyticsCounterIncremented() { | |
UUID.randomUUID(), | ||
"[email protected]", | ||
UUID.randomUUID(), | ||
LocalDateTime | ||
.now() | ||
timeProvider | ||
.utcNow() | ||
.atZone(ZoneId.of("UTC")) | ||
.plus(Duration.ofDays(1)) | ||
.withHour(15) | ||
.withMinute(15) | ||
.toInstant(ZoneOffset.UTC), | ||
.toInstant(), | ||
15 | ||
); | ||
|
||
|
Oops, something went wrong.