package com.oltruong.teamag.service;

import com.google.common.collect.Lists;
import com.oltruong.teamag.model.Member;
import com.oltruong.teamag.model.builder.EntityFactory;
import com.oltruong.teamag.utils.TestUtils;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.lang.reflect.InvocationTargetException;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * @author Olivier Truong
 */
public class ScheduleServiceTest {


    @Mock
    private EmailService mockEmailService;

    @Mock
    private AbsenceDayService mockAbsenceDayService;

    @Mock
    private MemberService mockMemberService;


    private ScheduleService scheduleService;

    private Long randomLong;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        scheduleService = new ScheduleService();
        randomLong = EntityFactory.createRandomLong();
        TestUtils.setPrivateAttribute(scheduleService, mockEmailService, "emailService");
        TestUtils.setPrivateAttribute(scheduleService, mockMemberService, "memberService");
        TestUtils.setPrivateAttribute(scheduleService, mockAbsenceDayService, "absenceDayService");
    }

    @Test
    public void testSendReminder() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        Member member = EntityFactory.createMember();
        member.setId(randomLong);
        when(mockMemberService.findActiveMembers()).thenReturn(Lists.newArrayList(member));
        when(mockAbsenceDayService.findByMemberAndMonth(anyLong(), anyInt())).thenReturn(Lists.newArrayListWithExpectedSize(0));


        scheduleService.sendReminder();

        verify(mockAbsenceDayService).findByMemberAndMonth(eq(randomLong), eq(DateTime.now().getMonthOfYear()));
        verify(mockEmailService).sendEmailCopyBlindAdministrator(any());
    }

}
@@ -291,16 +291,49 @@
 t.Test;%0A
+import org.junit.runner.RunWith;%0A
 import o
@@ -387,16 +387,135 @@
 tations;
+%0Aimport org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;
 %0A%0Aimport
@@ -727,16 +727,57 @@
 ers.eq;%0A
+import static org.mockito.Mockito.never;%0A
 import s
@@ -854,42 +854,173 @@
 en;%0A
-%0A/**%0A * @author Olivier Truong%0A */
+import static org.powermock.api.mockito.PowerMockito.mockStatic;%0A%0A/**%0A * @author Olivier Truong%0A */%0A@RunWith(PowerMockRunner.class)%0A@PrepareForTest(%7BDateTime.class%7D)
 %0Apub
@@ -1821,16 +1821,24 @@
 Reminder
+_warning
 () throw
@@ -1914,16 +1914,1454 @@
 ption %7B%0A
+%0A        DateTime date = DateTime.now().withTimeAtStartOfDay().withYear(2015).withMonthOfYear(5).withDayOfMonth(7);%0A%0A        testSendReminder(date);%0A        verify(mockAbsenceDayService).findByMemberAndMonth(eq(randomLong), eq(date.getMonthOfYear()));%0A        verify(mockEmailService).sendEmailCopyBlindAdministrator(any());%0A    %7D%0A%0A    @Test%0A    public void testSendReminder_nowarning() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException %7B%0A%0A        DateTime date = DateTime.now().withTimeAtStartOfDay().withYear(2015).withMonthOfYear(5).withDayOfMonth(6);%0A%0A        testSendReminder(date);%0A        verify(mockAbsenceDayService).findByMemberAndMonth(eq(randomLong), eq(date.getMonthOfYear()));%0A        verify(mockEmailService, never()).sendEmailCopyBlindAdministrator(any());%0A    %7D%0A%0A    @Test%0A    public void testSendReminder_nowarningDayOff() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException %7B%0A%0A        DateTime date = DateTime.now().withTimeAtStartOfDay().withYear(2015).withMonthOfYear(5).withDayOfMonth(8);%0A%0A        testSendReminder(date);%0A        verify(mockAbsenceDayService, never()).findByMemberAndMonth(eq(randomLong), eq(date.getMonthOfYear()));%0A        verify(mockEmailService, never()).sendEmailCopyBlindAdministrator(any());%0A    %7D%0A%0A    private void testSendReminder(DateTime date) %7B%0A        mockStatic(DateTime.class);%0A        when(DateTime.now()).thenReturn(date);%0A%0A
         
@@ -3708,194 +3708,8 @@
 );%0A%0A
-        verify(mockAbsenceDayService).findByMemberAndMonth(eq(randomLong), eq(DateTime.now().getMonthOfYear()));%0A        verify(mockEmailService).sendEmailCopyBlindAdministrator(any());%0A
     

Add more tests