package com.atlassian.bitbucket.pull;

import com.google.common.collect.ImmutableSet;
import org.junit.Test;

import static java.util.Collections.singleton;
import static org.junit.Assert.*;

@SuppressWarnings({"deprecation", "ConstantConditions"})
public class PullRequestParticipantRequestTest {

    @Test
    public void testApprove() {
        PullRequestParticipantRequest request = new PullRequestParticipantRequest.Builder("username")
                .role(PullRequestRole.AUTHOR)
                .approved(true)
                .build();

        assertEquals(singleton(PullRequestParticipantStatus.APPROVED), request.getStatuses());
        assertTrue(request.getApproved());

        assertEquals(PullRequestRole.AUTHOR, request.getRole());
        assertEquals("username", request.getUsername());
    }

    @Test
    public void testMultipleStatuses() {
        PullRequestParticipantRequest request = new PullRequestParticipantRequest.Builder("username")
                .status(PullRequestParticipantStatus.APPROVED)
                .status(PullRequestParticipantStatus.UNAPPROVED)
                .build();

        assertEquals(ImmutableSet.of(PullRequestParticipantStatus.APPROVED, PullRequestParticipantStatus.UNAPPROVED),
                request.getStatuses());
        assertFalse(request.getApproved());
    }

    @Test
    public void testUnapprove() {
        PullRequestParticipantRequest request = new PullRequestParticipantRequest.Builder("username")
                .approved(false)
                .build();

        assertEquals(singleton(PullRequestParticipantStatus.UNAPPROVED), request.getStatuses());
        assertFalse(request.getApproved());
    }
}