package ca.antonious.habittracker.habitinteractiontests;

import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

import ca.antonious.habittracker.habitstorage.IHabitRepository;
import ca.antonious.habittracker.interactions.CompleteHabit;
import ca.antonious.habittracker.models.Habit;
import ca.antonious.habittracker.models.HabitCompletion;
import ca.antonious.habittracker.time.IClock;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

/**
 * Created by George on 2016-09-13.
 */
public class CompleteHabitTests {
    private IClock clock;
    private IHabitRepository habitRepository;
    private CompleteHabit completeHabit;

    private Habit habitWithoutCompletion;
    private Habit habitWithCompletion;

    @Before
    public void set_up() {
        habitWithoutCompletion = new Habit();
        habitWithoutCompletion.setId("Habit-ID");
        habitWithoutCompletion.setName("AwesomeHabit");
        habitWithoutCompletion.setStartDate(new Date(1));
        habitWithoutCompletion.setDaysToComplete(Arrays.asList(Calendar.SUNDAY));

        HabitCompletion habitCompletion = new HabitCompletion(new Date(1));
        habitCompletion.setId("Completion-ID");

        habitWithCompletion = new Habit();
        habitWithCompletion.setId("Habit-ID");
        habitWithCompletion.setName("AwesomeHabit");
        habitWithCompletion.setStartDate(new Date(1));
        habitWithCompletion.setDaysToComplete(Arrays.asList(Calendar.SUNDAY));
        habitWithCompletion.setCompletions(Arrays.asList(habitCompletion));

        clock = mock(IClock.class);
        habitRepository = mock(IHabitRepository.class);
        completeHabit = new CompleteHabit(habitRepository, clock);
    }

    @Test
    public void test_complete_ifHabitDoesNotExist_thenNoRepositoryUpdatesOccurs() {
        when(habitRepository.getHabit("Habit-ID")).thenReturn(null);
        completeHabit.complete("Habit-ID");

        verify(habitRepository, never()).updateHabit(any(Habit.class));
    }

    @Test
    public void test_complete_ifHabitExists_thenUpdateIsCalledWithCompletionAdded() {
        fail();
    }
}

@@ -98,16 +98,51 @@
 it.Test;
+%0Aimport org.mockito.ArgumentCaptor;
 %0A%0Aimport
@@ -1973,16 +1973,17 @@
 (null);%0A
+%0A
         
@@ -2206,13 +2206,806 @@
     
-fail(
+when(habitRepository.getHabit(%22Habit-ID%22)).thenReturn(habitWithoutCompletion);%0A        when(clock.getCurrentDate()).thenReturn(new Date(1));%0A%0A        completeHabit.complete(%22Habit-ID%22);%0A%0A        ArgumentCaptor%3CHabit%3E habitCaptor = ArgumentCaptor.forClass(Habit.class);%0A        verify(habitRepository).updateHabit(habitCaptor.capture());%0A%0A        Habit habit = habitCaptor.getValue();%0A%0A        HabitCompletion expectedCompletion = habitWithCompletion.getCompletions().get(0);%0A        HabitCompletion actualCompletion = habit.getCompletions().get(0);%0A%0A        assertEquals(habit.getName(), habitWithCompletion.getName());%0A        assertEquals(habit.getStartDate(), habitWithCompletion.getStartDate());%0A%0A        assertEquals(expectedCompletion.getCompletionTime(), actualCompletion.getCompletionTime()
 );%0A 

Add test for completing a habit that exists