package com.alexstyl.specialdates.date;

import android.content.res.Resources;

import com.alexstyl.specialdates.DisplayName;
import com.alexstyl.specialdates.Optional;
import com.alexstyl.specialdates.R;
import com.alexstyl.specialdates.TestContact;
import com.alexstyl.specialdates.contact.Contact;
import com.alexstyl.specialdates.events.peopleevents.StandardEventType;

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

import static com.alexstyl.specialdates.date.DateConstants.JANUARY;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class ContactEventTest {

    private static final Optional<Long> NO_DEVICE_ID = Optional.absent();
    private static final Contact ANY_CONTACT = new TestContact(1, DisplayName.from("Peter"));
    private static final Date SOME_DATE = Date.on(1, JANUARY, 1990);
    private static final Date SOME_DATE_WITHOUT_YEAR = Date.on(1, JANUARY);
    private static final int CURRENT_YEAR = Date.CURRENT_YEAR;

    @Mock
    private Resources mockResources;

    @Before
    public void setUp() throws Exception {
        when(mockResources.getString(R.string.nameday)).thenReturn("Nameday");
        when(mockResources.getString(R.string.birthday)).thenReturn("Birthday");
        when(mockResources.getString(R.string.turns_age, 10)).thenReturn("Turns 10");

    }

    @Test
    public void labelForNameday() {
        ContactEvent contactEvent = new ContactEvent(NO_DEVICE_ID, StandardEventType.NAMEDAY, SOME_DATE, ANY_CONTACT);
        String label = contactEvent.getLabel(mockResources);
        assertThat(label).isEqualTo("Nameday");
    }

    @Test
    public void labelForBirthdayWithoutYear() {
        ContactEvent contactEvent = new ContactEvent(NO_DEVICE_ID, StandardEventType.BIRTHDAY, SOME_DATE_WITHOUT_YEAR, ANY_CONTACT);
        String label = contactEvent.getLabel(mockResources);
        assertThat(label).isEqualTo("Birthday");
    }

    @Test
    public void labelForBirthdayWithYearAfterDate() {
        Date eventDate = Date.on(1, JANUARY, CURRENT_YEAR + 50);
        ContactEvent contactEvent = new ContactEvent(NO_DEVICE_ID, StandardEventType.BIRTHDAY, eventDate, ANY_CONTACT);
        String label = contactEvent.getLabel(mockResources);
        assertThat(label).isEqualTo("Birthday");
    }

    @Test
    public void labelForBirthdayWithYearOnDate() {
        Date eventDate = Date.on(1, JANUARY, CURRENT_YEAR);
        ContactEvent contactEvent = new ContactEvent(NO_DEVICE_ID, StandardEventType.BIRTHDAY, eventDate, ANY_CONTACT);
        String label = contactEvent.getLabel(mockResources);
        assertThat(label).isEqualTo("Birthday");
    }

    @Test
    public void labelForBirthdayWithYearBeforeDate() {
        Date eventDate = Date.on(1, JANUARY, CURRENT_YEAR - 10);
        ContactEvent contactEvent = new ContactEvent(NO_DEVICE_ID, StandardEventType.BIRTHDAY, eventDate, ANY_CONTACT);
        String label = contactEvent.getLabel(mockResources);
        assertThat(label).isEqualTo("Turns 10");
    }

}

@@ -45,28 +45,27 @@
 ort 
-android.content.res.
+com.alexstyl.String
 Reso
@@ -71,17 +71,16 @@
 ources;%0A
-%0A
 import c
@@ -1156,16 +1156,22 @@
 private 
+String
 Resource

Fix failing test