package com.atlassian.stash.internal.notification.pull.activity;

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

import java.util.Collection;

import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.*;

public class CommentThreadCollectionTest extends AbstractCommentThreadTest {

    private final CommentThreadCollection collection = new CommentThreadCollection();

    @Test
    public void testAdd() throws Exception {
        CommentThread commentThread = new CommentThread(comments.get(0), false);
        commentThread.addReply(new CommentThread(comments.get(1), false));
        collection.add(commentThread);

        assertThread();
    }

    private void assertThread() {
        Collection<CommentThread> threads = collection.getThreads();
        assertThat(threads, hasSize(1));
        CommentThread thread = Iterables.getOnlyElement(threads);
        assertEquals(comments.get(0), thread.getComment());
        assertThat(thread.getReplies(), hasSize(1));
        assertFalse(thread.isContext());
    }
}