package periodFilters;


import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import org.dhis2.mobile.utils.date.filters.WeeklyWednesdayPeriodFilter;
import org.junit.Test;

public class WeeklyWednesdayPeriodTest {

    @Test
    public void testWeeklyPeriodsNullStartDate() {
        WeeklyWednesdayPeriodFilter
                periodFilter = new WeeklyWednesdayPeriodFilter(
                null, PeriodFiltersCommon.getDateTimeFromString("2017-01-03"));
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-01-02"));
        assertFalse(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-01-06"));
        assertTrue(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2016-12-28"));
        assertFalse(periodFilter.apply());

        periodFilter = new WeeklyWednesdayPeriodFilter(
                null, PeriodFiltersCommon.getDateTimeFromString("2017-08-02"));
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-08-02"));
        assertFalse(periodFilter.apply());
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-08-08"));
        assertFalse(periodFilter.apply());
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-08-09"));
        assertTrue(periodFilter.apply());
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-08-15"));
        assertTrue(periodFilter.apply());
    }


    @Test
    public void testWeeklyPeriodsNullEndDate() {
        WeeklyWednesdayPeriodFilter periodFilter = new WeeklyWednesdayPeriodFilter(
                PeriodFiltersCommon.getDateTimeFromString("2017-01-04"), null);
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-01-04"));
        assertFalse(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-02-09"));
        assertFalse(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2016-12-26"));
        assertTrue(periodFilter.apply());
    }

    @Test
    public void testWeeklyPeriodsSameDayLimits() {
        WeeklyWednesdayPeriodFilter periodFilter = new WeeklyWednesdayPeriodFilter(
                PeriodFiltersCommon.getDateTimeFromString("2017-01-04"), PeriodFiltersCommon.getDateTimeFromString("2017-01-11"));
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-01-04"));
        assertFalse(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-02-09"));
        assertTrue(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2016-12-26"));
        assertTrue(periodFilter.apply());
    }

    @Test
    public void testWeeklyPeriodsLastDaysOfYearLimits() {
        WeeklyWednesdayPeriodFilter periodFilter = new WeeklyWednesdayPeriodFilter(
                PeriodFiltersCommon.getDateTimeFromString("2016-12-29"), PeriodFiltersCommon.getDateTimeFromString("2017-01-11"));
        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-01-09"));
        assertFalse(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2017-01-16"));
        assertTrue(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2016-12-19"));
        assertTrue(periodFilter.apply());

        periodFilter.setSelectedDate(PeriodFiltersCommon.getDateTimeFromString("2016-12-29"));
        assertFalse(periodFilter.apply());
    }

}

@@ -2513,34 +2513,34 @@
 String(%222017-01-
-11
+04
 %22));%0A        per
@@ -2745,36 +2745,36 @@
 omString(%222017-0
-2-09
+1-11
 %22));%0A        ass
@@ -3169,17 +3169,17 @@
 016-12-2
-9
+8
 %22), Peri
@@ -3217,34 +3217,34 @@
 String(%222017-01-
-11
+03
 %22));%0A        per
@@ -3321,17 +3321,17 @@
 017-01-0
-9
+3
 %22));%0A   
@@ -3459,18 +3459,18 @@
 2017-01-
-16
+04
 %22));%0A   
@@ -3601,10 +3601,10 @@
 -12-
-19
+27
 %22));

fix wednesday tests