package seedu.ezdo.commons.util;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import seedu.ezdo.testutil.TaskBuilder;
import seedu.ezdo.testutil.TestTask;

@RunWith(PowerMockRunner.class)
@PrepareForTest({DateUtil.class, SimpleDateFormat.class})
public class DateUtilTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void dateFormat_parseException() throws Exception {
        thrown.expect(AssertionError.class);
        SimpleDateFormat mock = mock(SimpleDateFormat.class);
        PowerMockito.whenNew(SimpleDateFormat.class).
        withAnyArguments().thenReturn(mock);
        String dateString1 = "omg";
        String dateString2 = "asdf";
        when(mock.parse(dateString1)).thenThrow(new ParseException("parse exception", 1));
        DateUtil.compareDateStrings(dateString1, dateString2, true);
    }

    @Test
    public void noStartDate_pass() throws Exception {
        TestTask task = new TaskBuilder().withName("Alson").withPriority("3").withStartDate("")
                .withDueDate("10/10/2019")
                .withTags("guy").build();
        assertTrue(DateUtil.isTaskDateValid(task));
    }

    @Test
    public void noDueDate_pass() throws Exception {
        TestTask task = new TaskBuilder().withName("Alson").withPriority("3").withStartDate("02/02/2017")
                .withDueDate("")
                .withTags("guy").build();
        assertTrue(DateUtil.isTaskDateValid(task));
    }

    @Test
    public void twoDates_equal_pass() throws Exception {
        TestTask task = new TaskBuilder().withName("Alson").withPriority("3")
                .withStartDate("02/02/2017").withDueDate("02/02/2017")
                .withTags("guy").build();
        assertTrue(DateUtil.isTaskDateValid(task));
    }

    @Test
    public void startAfterDue_fail() throws Exception {
        TestTask task = new TaskBuilder().withName("Alson").withPriority("3")
                .withStartDate("02/02/2020").withDueDate("10/10/2019")
                .withTags("guy").build();
        assertFalse(DateUtil.isTaskDateValid(task));
    }
}

@@ -1940,32 +1940,322 @@
 (task));%0A    %7D%0A%0A
+    @Test%0A    public void noDates_pass() throws Exception %7B%0A        TestTask task = new TaskBuilder().withName(%22Alson%22).withPriority(%223%22).withStartDate(%22%22)%0A                .withDueDate(%22%22)%0A                .withTags(%22guy%22).build();%0A        assertTrue(DateUtil.isTaskDateValid(task));%0A    %7D%0A%0A
     @Test%0A    pu

Add test for DateUtil on floating tasks