package com.atlassian.stash.internal.pull.comment.drift;

import com.atlassian.stash.internal.pull.InternalPullRequestDiffCommentAnchor;
import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

public class OrphanAllCommentDriftStrategyTest {

    @Test
    public void testApply() {
        InternalPullRequestDiffCommentAnchor first = mock(InternalPullRequestDiffCommentAnchor.class);
        InternalPullRequestDiffCommentAnchor second = mock(InternalPullRequestDiffCommentAnchor.class);
        List<InternalPullRequestDiffCommentAnchor> anchors = Lists.newArrayList(first, second);

        DriftContext context = mock(DriftContext.class);
        when(context.iterator()).thenReturn(anchors.iterator());

        new OrphanAllCommentDriftStrategy().apply(context);

        assertTrue("All anchors should have been removed via the iterator", anchors.isEmpty());
        verify(context).orphan(same(first));
        verify(context).orphan(same(second));
    }
}
