package com.service;

import com.entity.Sprint;
import com.repository.SprintsRepository;
import com.repository.TaskRepository;
import com.service.impl.SprintsServiceImpl;
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 java.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.when;

/**
 * Created by Cyan on 6/26/2016.
 */
@RunWith(MockitoJUnitRunner.class)
public class SprintsServiceTest {

    @InjectMocks
    private SprintsService sprintsService = new SprintsServiceImpl();

    @Mock
    private SprintsRepository sprintsRepository;

    @Mock
    private TaskRepository taskRepository;

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

    @Test
    public void testSelect() throws Exception {
        String project = "test project";
        int id = 12;

        when(this.sprintsRepository.select(project, id)).thenReturn(this.getSprint());
        when(this.taskRepository.selectAllTags(id)).thenReturn(this.getTags());

        Sprint sprint = this.sprintsService.select(project, id);

        Assert.assertTrue(sprint.getId() == id);
    }

    private Sprint getSprint() {
        Sprint sprint = new Sprint();
        sprint.setId(12);
        sprint.setState("Completed");
        sprint.setProject("test project");

        return sprint;
    }

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

        return tags;
    }

}
