@Test
public void testSetTaskRunStatus() {
Task task = new Task("name", "group", "");
task.setNotification(new Notification());
taskManager.save(task);
TaskRun taskRun = new TaskRun(new Date(), new Date(), "out", "err", "stack", task.getId());
int mailCount = 0;
// no mail should be sent for following
taskRunManager.setStatus(taskRun, Status.INITIALISING);
assertEquals(mailCount, mailSender.getMessageCount());
assertEquals(Status.INITIALISING, taskRun.getStatus());
taskRunManager.setStatus(taskRun, Status.RUNNING);
assertEquals(mailCount, mailSender.getMessageCount());
assertEquals(Status.RUNNING, taskRun.getStatus());
taskRunManager.setStatus(taskRun, Status.CANCELLING);
assertEquals(mailCount, mailSender.getMessageCount());
assertEquals(Status.CANCELLING, taskRun.getStatus());
// mail should be sent for following
taskRunManager.setStatus(taskRun, Status.SUCCESS);
assertEquals(++mailCount, mailSender.getMessageCount());
assertEquals(Status.SUCCESS, taskRun.getStatus());
taskRunManager.setStatus(taskRun, Status.CANCELLED);
assertEquals(++mailCount, mailSender.getMessageCount());
assertEquals(Status.CANCELLED, taskRun.getStatus());
taskRunManager.setStatus(taskRun, Status.INTERRUPTED);
assertEquals(++mailCount, mailSender.getMessageCount());
assertEquals(Status.INTERRUPTED, taskRun.getStatus());
taskRunManager.setStatus(taskRun, Status.ABORTED);
assertEquals(++mailCount, mailSender.getMessageCount());
assertEquals(Status.ABORTED, taskRun.getStatus());
taskRunManager.setStatus(taskRun, Status.FAILED);
assertEquals(++mailCount, mailSender.getMessageCount());
assertEquals(Status.FAILED, taskRun.getStatus());
}