package com.alexstyl.specialdates.events.namedays.calendar.resource;

import com.alexstyl.specialdates.date.Date;
import com.alexstyl.specialdates.events.namedays.NameCelebrations;
import com.alexstyl.specialdates.events.namedays.NamedayBundle;
import com.alexstyl.specialdates.events.namedays.NamedayLocale;

import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;

import static com.alexstyl.specialdates.date.DateConstants.*;
import static org.fest.assertions.api.Assertions.assertThat;

public class NamedayJSONParserTest {

    private NamedayJSON namedayJSON;

    @Before
    public void setUp() throws JSONException {
        JavaJSONResourceLoader resourceLoader = new JavaJSONResourceLoader();
        NamedayJSONResourceProvider resourceProvider = new NamedayJSONResourceProvider(resourceLoader);
        namedayJSON = resourceProvider.getNamedayJSONFor(NamedayLocale.gr);

    }

    @Test
    public void returningBundleHasNames() {
        NamedayBundle namedayBundle = NamedayJSONParser.getNamedaysFrom(namedayJSON);
        assertThat(namedayBundle.getNames()).isNotEmpty();
    }

    @Test
    public void alexandrosNamedayIsReturnedCorrectly() {
        NamedayBundle namedayBundle = NamedayJSONParser.getNamedaysFrom(namedayJSON);
        NameCelebrations dates = namedayBundle.getDatesFor("Αλέξανδρος");
        assertThat(dates.getDate(0)).isEqualTo(Date.on(30, AUGUST));
    }

    @Test
    public void davidNamedayIsReturnedCorrectly() {
        NamedayBundle namedayBundle = NamedayJSONParser.getNamedaysFrom(namedayJSON);
        NameCelebrations dates = namedayBundle.getDatesFor("Δαβίδ");
        assertThat(dates.getDate(0)).isEqualTo(Date.on(26, JUNE));
    }

    @Test
    public void magdoulaNamedayIsReturnedCorrectly() {
        NamedayBundle namedayBundle = NamedayJSONParser.getNamedaysFrom(namedayJSON);
        NameCelebrations dates = namedayBundle.getDatesFor("Αμαλία");
        assertThat(dates.getDate(0)).isEqualTo(Date.on(10, JULY));
    }
}

@@ -505,16 +505,71 @@
 ertThat;
+%0Aimport static org.fest.assertions.api.Assertions.fail;
 %0A%0Apublic
@@ -1418,37 +1418,28 @@
 That
-(dates.getDate(0)).isEqualTo(
+ContainsDate(dates, 
 Date
@@ -1702,37 +1702,28 @@
 That
-(dates.getDate(0)).isEqualTo(
+ContainsDate(dates, 
 Date
@@ -1988,56 +1988,509 @@
 That
-(dates.getDate(0)).isEqualTo(Date.on(10, JULY));
+ContainsDate(dates, Date.on(10, JULY));%0A    %7D%0A%0A    private void assertThatContainsDate(NameCelebrations celebrations, Date date) %7B%0A        boolean found = false;%0A        for (int i = 0; i %3C celebrations.getDates().size(); i++) %7B%0A            Date date1 = celebrations.getDate(i);%0A            if (date1.equals(date)) %7B%0A                found = true;%0A                break;%0A            %7D%0A        %7D%0A        if (!found) %7B%0A            fail(%22Couldn't find date %22 + date + %22 inside %22 + celebrations);%0A        %7D
 %0A   

Check weather celebration includes date instead of contains only