class TaskServiceImpl implements TaskService {

    @Override
    public void addOrUpdate(Task task) {
        if (task.getId() == null) {
            throw new IllegalArgumentException("Id property must be set");
        }
        tasks.put(task.getId(), task);
    }

}

class TaskServiceImplTest {

    private TaskService taskService;

    @Test(expected = IllegalArgumentException.class)
    public void testAddIllegal() {

        Task task = new Task();
        taskService.addOrUpdate(task);
    }

}