package cz.moneta.test.unit.dsl.util;

import cz.moneta.test.dsl.util.DateUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import static org.junit.jupiter.api.Assertions.fail;

public class DateUtilsTest {

    private static final String DATE_FORMAT = "dd.MM.yyyy";

    @Test
    void isWorkingDay() {
        Assertions.assertTrue(DateUtils.isWorkingDay(LocalDate.of(2020, 9, 22)));
    }

    @Test
    void isStateHoliday() {
        Assertions.assertTrue(DateUtils.isStateHoliday(LocalDate.of(2020, 9, 28)));
    }

    @Test
    void getTodayDateIncrementedByDays() {
        Assertions.assertEquals(LocalDate.now().plusDays(10).format(DateTimeFormatter.ofPattern(DATE_FORMAT)),
                DateUtils.getTodayDateIncrementedByDays(10, DATE_FORMAT));
    }

    @Test
    void getRandomDate() {
        try {
            LocalDate date = LocalDate.parse(DateUtils.getRandomDate(1971, 2020, DATE_FORMAT), DateTimeFormatter.ofPattern(DATE_FORMAT));
            Assertions.assertTrue(date.isAfter(LocalDate.of(1970, 12, 31)) && date.isBefore(LocalDate.of(2021, 1, 1)));
        } catch (Exception e) {
            fail("Cannot parse generated random date");
        }
    }
}