package com.atlassian.stash.internal.pull;

import com.atlassian.bitbucket.pull.PullRequestParticipantStatus;
import com.atlassian.bitbucket.pull.PullRequestRole;
import com.google.common.collect.ImmutableList;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

public class InternalPullRequestParticipantTest {

    @Test
    public void testSorting() {
        InternalPullRequest pr = mock(InternalPullRequest.class);

        InternalPullRequestParticipant approving = new InternalPullRequestParticipant.Builder(pr)
                .status(PullRequestParticipantStatus.APPROVED)
                .role(PullRequestRole.PARTICIPANT)
                .build();

        InternalPullRequestParticipant unapproving = new InternalPullRequestParticipant.Builder(pr)
                .status(PullRequestParticipantStatus.UNAPPROVED)
                .role(PullRequestRole.PARTICIPANT)
                .build();

        List<InternalPullRequestParticipant> sorted = new ArrayList<>(ImmutableList.of(unapproving, approving));
        Collections.sort(sorted);
        assertEquals(ImmutableList.of(approving, unapproving), sorted);
    }
}