test: NbpService#getFetchDate tests
This commit is contained in:
parent
2e4ca845f8
commit
310a4c4087
4 changed files with 92 additions and 6 deletions
|
@ -1,32 +1,82 @@
|
|||
package eu.ztsh.wymiana.service;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class NbpServiceTest {
|
||||
|
||||
@Test
|
||||
void getFetchDateOnWorkingDayTest() {
|
||||
private static final ZoneId zone = ZoneId.of("Europe/Warsaw");
|
||||
private static final LocalDate today = LocalDate.of(2024, Month.MAY, 12); // Sunday
|
||||
private static Clock clock;
|
||||
private NbpService nbpService;
|
||||
|
||||
@BeforeAll
|
||||
static void prepare() {
|
||||
clock = Mockito.mock(Clock.class);
|
||||
Mockito.when(clock.getZone()).thenReturn(zone);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFetchDateOnWeekendTest() {
|
||||
@BeforeEach
|
||||
void prepareTest() {
|
||||
nbpService = new NbpService(clock);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = DayOfWeek.class, names = {"SATURDAY","SUNDAY"}, mode = EnumSource.Mode.EXCLUDE)
|
||||
void getFetchDateOnWorkingDayTest(DayOfWeek dayOfWeek) {
|
||||
updateClock(dayOfWeek);
|
||||
assertThat(nbpService.getFetchDate()).isEqualTo(
|
||||
switch (dayOfWeek) {
|
||||
case MONDAY -> LocalDate.of(2024, Month.MAY, 6);
|
||||
case TUESDAY -> LocalDate.of(2024, Month.MAY, 7);
|
||||
case WEDNESDAY -> LocalDate.of(2024, Month.MAY, 8);
|
||||
case THURSDAY -> LocalDate.of(2024, Month.MAY, 9);
|
||||
case FRIDAY -> LocalDate.of(2024, Month.MAY, 10);
|
||||
default -> null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = DayOfWeek.class, names = {"SATURDAY","SUNDAY"})
|
||||
void getFetchDateOnWeekendTest(DayOfWeek dayOfWeek) {
|
||||
updateClock(dayOfWeek);
|
||||
assertThat(nbpService.getFetchDate()).isEqualTo(LocalDate.of(2024, Month.MAY, 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithoutCacheTest() {
|
||||
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithCacheTest() {
|
||||
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getInvalidCurrencyTest() {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
private void updateClock(DayOfWeek dayOfWeek) {
|
||||
Mockito.when(clock.instant()).thenReturn(
|
||||
today.with(TemporalAdjusters.previousOrSame(dayOfWeek))
|
||||
.atStartOfDay(zone)
|
||||
.toInstant());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue