package tests;

import backend.IssueMetadata;
import backend.RepoIO;
import backend.interfaces.RepoSource;
import backend.resource.TurboIssue;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;

public class RepoIOTests {
    /**
     * Tests that RepoIO's getIssueMetadata calls RepoSource's downloadMetaData method and
     * receives a corresponding CompletableFuture response
     */
    @Test
    public void testGetIssueMetaData() {
        RepoSource source = mock(RepoSource.class);
        CompletableFuture<Map<Integer, IssueMetadata>> response = new CompletableFuture<>();
        doReturn(response).when(source).downloadMetadata(anyString(), anyListOf(TurboIssue.class));

        RepoIO repoIO = new RepoIO(Optional.of(source), Optional.empty(), Optional.empty());
        CompletableFuture result = repoIO.getIssueMetadata("test/test", new ArrayList<>());

        verify(source, times(1)).downloadMetadata(anyString(), anyListOf(TurboIssue.class));
        assertEquals(response, result);
    }

    /**
     * Tests that RepoIO's replaceIssueLabelsOnServer calls RepoSource's replaceIssueLabelsOnServer
     * and receives a corresponding CompletableFuture response
     */
    @Test
    public void testReplaceIssueLabels() {
        RepoSource source = mock(RepoSource.class);
        CompletableFuture<List<String>> response = new CompletableFuture<>();
        doReturn(response).when(source).replaceIssueLabels(any(TurboIssue.class),
                                                           anyListOf(String.class));

        RepoIO repoIO = new RepoIO(Optional.of(source), Optional.empty(), Optional.empty());
        CompletableFuture result = repoIO.replaceIssueLabels(mock(TurboIssue.class), new ArrayList<>());

        verify(source, times(1)).replaceIssueLabels(any(TurboIssue.class), anyListOf(String.class));
        assertEquals(response, result);
    }
}

@@ -2174,11 +2174,816 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Tests that RepoIO's replaceIssueLabels calls RepoSource's replaceIssueLabels%0A     * and receives a corresponding CompletableFuture response%0A     */%0A    @Test%0A    public void testReplaceIssueMilestones() %7B%0A        RepoSource source = mock(RepoSource.class);%0A        CompletableFuture%3CList%3CString%3E%3E response = new CompletableFuture%3C%3E();%0A        doReturn(response).when(source).replaceIssueMilestone(any(TurboIssue.class),%0A                any(Integer.class));%0A%0A        RepoIO repoIO = new RepoIO(Optional.of(source), Optional.empty(), Optional.empty());%0A        CompletableFuture result = repoIO.replaceIssueMilestone(mock(TurboIssue.class), 0);%0A%0A        verify(source, times(1)).replaceIssueMilestone(any(TurboIssue.class), any(Integer.class));%0A        assertEquals(response, result);%0A    %7D
 %0A%7D%0A

Add testReplaceIssueMilestone.