package com.service;

import com.entity.Task;
import com.repository.TaskRepository;
import com.service.impl.TaskServiceImpl;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Laurentiu Marcut on 6/26/2016.
 */
@RunWith(MockitoJUnitRunner.class)
public class TaskServiceTest {

    @InjectMocks
    private TaskService taskService = new TaskServiceImpl();

    @Mock
    private TaskRepository taskRepository;

    @Before
    public void init() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testSelect() throws Exception {
        int task = 12;
        when(this.taskRepository.select(task)).thenReturn(this.getTask());
        when(this.taskRepository.selectAllTags(task)).thenReturn(this.getTags());

        Task taskObj = this.taskService.select(task);

        Assert.assertTrue(taskObj.getId() == task);
    }

    private Task getTask() {
        Task task = new Task();
        task.setId(12);
        task.setState("Done");
        task.setPriority(1);
        task.setPoints(8);

        return task;
    }

    private List<String> getTags() {
        List<String> tags = new ArrayList<>();
        tags.add("tag1");
        tags.add("tag2");

        return tags;
    }
}
