package com.alexstyl.specialdates.upcoming;

import com.alexstyl.specialdates.DisplayName;
import com.alexstyl.specialdates.date.CelebrationDate;
import com.alexstyl.specialdates.date.ContactEvent;
import com.alexstyl.specialdates.date.DayDate;
import com.alexstyl.specialdates.events.EventType;
import com.alexstyl.specialdates.TestContact;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static org.fest.assertions.api.Assertions.assertThat;

@RunWith(MockitoJUnitRunner.class)
public class UpcomingDatesBuilderTest {

    private static final DayDate FEBRUARY_1st = DayDate.newInstance(1, DayDate.FEBRUARY, 1990);
    private static final DayDate FEBRUARY_3rd = DayDate.newInstance(3, DayDate.FEBRUARY, 1990);

    @Test
    public void givenASingleContactEvent_thenOneCelebrationDateIsCreated() {
        List<ContactEvent> contactEvents = Collections.singletonList(aContactEvent());

        List<CelebrationDate> dates = new UpcomingDatesBuilder()
                .withContactEvents(contactEvents)
                .build();

        assertThat(dates.size()).isEqualTo(1);
    }

    @Test
    public void givenASingleContactEvent_thenTheCelebrationDateContainsTheContactEvent() {
        List<ContactEvent> contactEvents = Collections.singletonList(aContactEvent());

        List<CelebrationDate> dates = new UpcomingDatesBuilder()
                .withContactEvents(contactEvents)
                .build();

        ContactEvent celebrationDateEvent = dates.get(0).getContactEvents().getEvent(0);
        assertThat(celebrationDateEvent).isEqualTo(contactEvents.get(0));
    }

    @Test
    public void givenTwoContactEventsOnSameDate_thenOneCelebrationDateIsCreated() throws Exception {
        List<ContactEvent> contactEventsList = Arrays.asList(
                aContactEventOn(FEBRUARY_1st),
                aContactEventOn(FEBRUARY_1st)
        );

        List<CelebrationDate> dates = new UpcomingDatesBuilder()
                .withContactEvents(contactEventsList)
                .build();

        assertThat(dates.size()).isEqualTo(1);
    }

    @Test
    public void givenTwoContactEventsOnDifferentDate_thenTwoCelebrationDateAreCreated() throws Exception {
        List<ContactEvent> contactEventsList = Arrays.asList(
                aContactEventOn(FEBRUARY_1st),
                aContactEventOn(FEBRUARY_3rd)
        );

        List<CelebrationDate> dates = new UpcomingDatesBuilder()
                .withContactEvents(contactEventsList)
                .build();

        assertThat(dates.size()).isEqualTo(2);
    }

    private static ContactEvent aContactEvent() {
        return aContactEventOn(DayDate.newInstance(1, 1, 1990));
    }

    private static ContactEvent aContactEventOn(DayDate date) {
        TestContact contact = new TestContact(1, DisplayName.NO_NAME);
        return new ContactEvent(EventType.BIRTHDAY, date, contact);
    }

}

@@ -38,16 +38,60 @@
 oming;%0A%0A
+import android.support.annotation.NonNull;%0A%0A
 import c
@@ -128,16 +128,16 @@
 ayName;%0A
-
 import c
@@ -378,16 +378,145 @@
 Contact;
+%0Aimport com.alexstyl.specialdates.events.bankholidays.BankHoliday;%0Aimport com.alexstyl.specialdates.events.namedays.NamesInADate;
 %0A%0Aimport
@@ -1021,16 +1021,106 @@
 , 1990);
+%0A    private static final DayDate MARCH_5th = DayDate.newInstance(5, DayDate.MARCH, 1990);
 %0A%0A    @T
@@ -2076,33 +2076,16 @@
 reated()
- throws Exception
  %7B%0A     
@@ -2547,25 +2547,8 @@
 ed()
- throws Exception
  %7B%0A 
@@ -2851,32 +2851,32 @@
      .build();%0A%0A
-
         assertTh
@@ -2905,32 +2905,1202 @@
 alTo(2);%0A    %7D%0A%0A
+    @Test%0A    public void givenABankHoliday_thenACelebrationDateIsCreated() %7B%0A        List%3CBankHoliday%3E bankHolidays = Collections.singletonList(aBankHoliday());%0A        List%3CCelebrationDate%3E dates = new UpcomingDatesBuilder()%0A                .withBankHolidays(bankHolidays)%0A                .build();%0A%0A        assertThat(dates.size()).isEqualTo(1);%0A    %7D%0A%0A    @Test%0A    public void givenEventsOnDifferentEvents_thenACelebrationDatesForEachOneAreCreated() %7B%0A        List%3CCelebrationDate%3E dates = new UpcomingDatesBuilder()%0A                .withContactEvents(Collections.singletonList(aContactEventOn(FEBRUARY_1st)))%0A                .withBankHolidays(Collections.singletonList(aBankHolidayOn(FEBRUARY_3rd)))%0A                .withNamedays(Collections.singletonList(new NamesInADate(MARCH_5th, Collections.singletonList(%22Name%22))))%0A                .build();%0A%0A        assertThat(dates.size()).isEqualTo(3);%0A    %7D%0A%0A    private BankHoliday aBankHolidayOn(DayDate date) %7B%0A        return new BankHoliday(%22A bank holiday%22, date);%0A    %7D%0A%0A    @NonNull%0A    private BankHoliday aBankHoliday() %7B%0A        return new BankHoliday(%22A bank holiday%22, DayDate.newInstance(1, 1, 1990));%0A    %7D%0A%0A
     private stat

Add test around bank holidays and namedays