package seedu.address.logic;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

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

import javafx.collections.ObservableList;
import seedu.address.testutil.TaskBuilder;
import seedu.address.testutil.TypicalTestTasks;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.logic.TimedNotifications;
import seedu.task.model.TaskManager;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.Task;
import seedu.task.model.task.UniqueTaskList.DuplicateTaskException;

//@@author A0141928B
/**
 * Tests for TimedNotifications
 */
public class TimedNotificationsTest {

    private TaskManager taskManager = new TaskManager();
    private ObservableList<ReadOnlyTask> taskList = taskManager.getTaskList();
    TimedNotifications notifications;

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

    @Test
    public void noTasks() {
        //no list
        notifications = new TimedNotifications(null, 1000);
        assertNull(notifications.iterator);
        assertNull(notifications.getMessage());
        assertNull(notifications.notification);

        //empty list
        notifications = new TimedNotifications(taskList, 1000);
        assertNotNull(notifications.iterator);
        assertNull(notifications.getMessage());
        assertNull(notifications.notification);
    }

    @Test
    public void typicalTasks() {
        TaskManager typicalAddressBook = new TypicalTestTasks().getTypicalTaskManger();
        ObservableList<ReadOnlyTask> newTasks = typicalAddressBook.getTaskList();

        //list with no tasks right now
        notifications = new TimedNotifications(newTasks, 1000);
        assertNotNull(notifications.iterator);
        assertNull(notifications.getMessage());
        assertNull(notifications.notification);
    }

    @Test
    public void taskDueIn3Hours() {
        //Get today's date and time
        Date today = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(today);
        calendar.add(calendar.HOUR_OF_DAY, 3); //Add 3 hours to current time

        StringBuilder date = new StringBuilder(); //To build a string that matches the deadline format
        date.append(new SimpleDateFormat("dd-MMM-yyyy").format(calendar.getTime()))
                    .append(" @ ").append(new SimpleDateFormat("hh:mm").format(calendar.getTime()));

        //Create a task with the current time + 3 hours
        try {
            taskManager.addTask(new Task(new TaskBuilder().withName("task123")
                    .withInformation("info")
                    .withPriorityLevel("1")
                    .withDeadline(date.toString())
                    .withTags("tag").build()));
        } catch (DuplicateTaskException e) {
            assert false : "not possible";
        } catch (IllegalValueException e) {
            assert false : "not possible";
        }
        taskList = taskManager.getTaskList();

        if (System.getProperty("os.name").startsWith("Windows")) { //Windows OS
            notifications = new TimedNotifications(taskList, 1000);
            notifications.run();
            assertNotNull(notifications.iterator);
            assertEquals(notifications.getMessage(), "task123");
            assertNotNull(notifications.notification);
        } else { //Other OS - can't run system tray notifications
            thrown.expect(UnsupportedOperationException.class);
            thrown.expect(AssertionError.class);
            notifications = new TimedNotifications(taskList, 1000);
            notifications.run();
        }
    }
}

@@ -27,53 +27,8 @@
 c;%0A%0A
-import static org.junit.Assert.assertEquals;%0A
 impo
@@ -117,94 +117,8 @@
 l;%0A%0A
-import java.text.SimpleDateFormat;%0Aimport java.util.Calendar;%0Aimport java.util.Date;%0A%0A
 impo
@@ -248,51 +248,8 @@
 st;%0A
-import seedu.address.testutil.TaskBuilder;%0A
 impo
@@ -296,68 +296,8 @@
 ks;%0A
-import seedu.task.commons.exceptions.IllegalValueException;%0A
 impo
@@ -419,111 +419,8 @@
 ask;
-%0Aimport seedu.task.model.task.Task;%0Aimport seedu.task.model.task.UniqueTaskList.DuplicateTaskException;
 %0A%0A//
@@ -1728,1792 +1728,7 @@
    %7D
-%0A%0A    @Test%0A    public void taskDueIn3Hours() %7B%0A        //Get today's date and time%0A        Date today = new Date();%0A        Calendar calendar = Calendar.getInstance();%0A        calendar.setTime(today);%0A        calendar.add(calendar.HOUR_OF_DAY, 3); //Add 3 hours to current time%0A%0A        StringBuilder date = new StringBuilder(); //To build a string that matches the deadline format%0A        date.append(new SimpleDateFormat(%22dd-MMM-yyyy%22).format(calendar.getTime()))%0A                    .append(%22 @ %22).append(new SimpleDateFormat(%22hh:mm%22).format(calendar.getTime()));%0A%0A        //Create a task with the current time + 3 hours%0A        try %7B%0A            taskManager.addTask(new Task(new TaskBuilder().withName(%22task123%22)%0A                    .withInformation(%22info%22)%0A                    .withPriorityLevel(%221%22)%0A                    .withDeadline(date.toString())%0A                    .withTags(%22tag%22).build()));%0A        %7D catch (DuplicateTaskException e) %7B%0A            assert false : %22not possible%22;%0A        %7D catch (IllegalValueException e) %7B%0A            assert false : %22not possible%22;%0A        %7D%0A        taskList = taskManager.getTaskList();%0A%0A        if (System.getProperty(%22os.name%22).startsWith(%22Windows%22)) %7B //Windows OS%0A            notifications = new TimedNotifications(taskList, 1000);%0A            notifications.run();%0A            assertNotNull(notifications.iterator);%0A            assertEquals(notifications.getMessage(), %22task123%22);%0A            assertNotNull(notifications.notification);%0A        %7D else %7B //Other OS - can't run system tray notifications%0A            thrown.expect(UnsupportedOperationException.class);%0A            thrown.expect(AssertionError.class);%0A            notifications = new TimedNotifications(taskList, 1000);%0A            notifications.run();%0A        %7D%0A    %7D
 %0A%7D%0A

Remove problematic test case in TimedNotificationsTest.java