//@@author A0138848M
package seedu.oneline.model.task;

import static org.junit.Assert.*;

import seedu.oneline.commons.exceptions.IllegalValueException;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class TaskTimeTest {
    
    @Rule
    public ExpectedException thrown = ExpectedException.none();
    
    private void IllegalValueExceptionThrown(String inputDateTime, String errorMessage) throws Exception{
        thrown.expect(IllegalValueException.class);
        thrown.expectMessage(errorMessage);    
        new TaskTime(inputDateTime);
    }

    // Tests for invalid datetime inputs to TaskTime constructor
    
    /**
     * Invalid equivalence partitions for datetime: null, other strings
     */
    
    @Test
    public void constructor_nullDateTime_assertionThrown() {
        thrown.expect(AssertionError.class);
        try {
            new TaskTime(null);
        } catch (IllegalValueException e){
            // should throw an assertion error instead of an illegal value exception
            assert false;
        }
    }

    @Test
    public void constructor_unsupportedDateTimeFormats_assertionThrown() throws Exception {
        IllegalValueExceptionThrown("day after", TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS);
        IllegalValueExceptionThrown("clearly not a time format", TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS);
        IllegalValueExceptionThrown("T u e s d a y", TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS);
    }
    
    // Tests for valid datetime inputs
    
    /**
     * Valid equivalence partitions for datetime:
     *  - day month and year specified
     *  - only day and month specified
     *  - only day specified
     *  - relative date specified
     *  - empty string
     */

    @Test
    public void constructor_emptyDateTime() {
        try {
            TaskTime t = new TaskTime("");
            assert t.getDate() == null;
        } catch (Exception e) {
            assert false;
        }
    }
    
}

@@ -84,16 +84,95 @@
 ert.*;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Calendar;%0Aimport java.util.Date;%0A%0A
 import s
@@ -227,16 +227,63 @@
 ption;%0A%0A
+import org.apache.commons.lang.time.DateUtils;%0A
 import o
@@ -2131,10 +2131,727 @@
  %7D%0A    %0A
+    @Test%0A    public void constructor_DMY() %7B%0A        String%5B%5D validFormats = new String%5B%5D%7B%0A                %225 October 2016%22, %0A                %225 Oct 16%22, %0A                %22Oct 5 16%22,%0A                %2210/5/16%22,%0A                %2210/05/16%22%7D;%0A        try %7B%0A            for (String t : validFormats)%7B%0A                TaskTime tTime = new TaskTime(t);%0A                Calendar tCal = DateUtils.toCalendar(tTime.getDate());%0A                assertTrue(tCal.get(Calendar.DAY_OF_MONTH) == 5);%0A                assertTrue(tCal.get(Calendar.MONTH) == Calendar.OCTOBER);%0A                assertTrue(tCal.get(Calendar.YEAR) == 2016);%0A            %7D%0A        %7D catch (Exception e) %7B%0A            assert false;%0A        %7D%0A    %7D%0A    %0A    %0A
 %7D%0A

Add test case for DMY provided inputs