package com.njcn.gather.detection.service.impl;

import com.njcn.gather.script.pojo.po.SourceIssue;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class PreDetectionServiceImplTest {

    @Test
    public void isFirstFormalIssueOfBigItem_returnsTrueForFirstIssueOfType() {
        List<SourceIssue> allIssues = Arrays.asList(issue(10, "voltage"), issue(20, "voltage"), issue(30, "current"));

        assertTrue(PreDetectionServiceImpl.isFirstFormalIssueOfBigItem(allIssues, issue(10, "voltage"), "voltage"));
    }

    @Test
    public void isFirstFormalIssueOfBigItem_returnsFalseWhenResumingInsideSameBigItem() {
        List<SourceIssue> allIssues = Arrays.asList(issue(10, "voltage"), issue(20, "voltage"), issue(30, "current"));

        assertFalse(PreDetectionServiceImpl.isFirstFormalIssueOfBigItem(allIssues, issue(20, "voltage"), "voltage"));
    }

    @Test
    public void isFirstFormalIssueOfBigItem_usesOtherTypeAsBigItemType() {
        List<SourceIssue> allIssues = Arrays.asList(otherTypeIssue(10, "V", "voltage"), otherTypeIssue(20, "V", "voltage"));

        assertTrue(PreDetectionServiceImpl.isFirstFormalIssueOfBigItem(allIssues, otherTypeIssue(10, "V", "voltage"), "voltage"));
    }

    private SourceIssue issue(Integer index, String type) {
        SourceIssue issue = new SourceIssue();
        issue.setIndex(index);
        issue.setType(type);
        return issue;
    }

    private SourceIssue otherTypeIssue(Integer index, String type, String otherType) {
        SourceIssue issue = issue(index, type);
        issue.setOtherType(otherType);
        return issue;
    }
}
