package models;


import org.junit.Test;
import utils.JodaDateUtil;

import java.util.List;

import static org.fest.assertions.Assertions.assertThat;

public class ReviewCommentTest extends ModelTest<ReviewComment> {

    @Test
    public void findByThread() {
        // given
        addTestData();
        CommentThread thread = CommentThread.find.byId(1l);
        assertThat(thread).isNotNull();

        // when
        List<ReviewComment> commentList = ReviewComment.findByThread(1l);

        // then
        assertThat(commentList.size()).isEqualTo(2);
        assertThat(commentList.get(0).id).isEqualTo(2);
        assertThat(commentList.get(1).id).isEqualTo(1);
    }


    /**
     * {@code commitId}를 가지는 {@link models.NonRangedCodeCommentThread} 한 개 저장.
     *  - state: OPEN
     *  - createDate: 3일전
     *  - id: 1
     * {@code commitId}를 가지는 {@link models.CodeCommentThread} 한 개 저장.
     *  - state: CLOSED
     *  - path: "readme.md"
     *  - createdDate: 2일전
     *  - id: 2
     */
    private void addTestData() {
        NonRangedCodeCommentThread thread1 = new NonRangedCodeCommentThread();
        thread1.commitId = "123456";
        thread1.state = CommentThread.ThreadState.OPEN;
        thread1.createdDate = JodaDateUtil.before(3);
        thread1.save();

        ReviewComment reviewComment1 = new ReviewComment();
        thread1.addComment(reviewComment1);
        reviewComment1.createdDate = JodaDateUtil.before(3);
        reviewComment1.setContents("reviewComment1");
        reviewComment1.save();

        ReviewComment reviewComment3 = new ReviewComment();
        thread1.addComment(reviewComment3);
        reviewComment3.createdDate = JodaDateUtil.before(2);
        reviewComment3.setContents("reviewComment3");
        reviewComment3.save();


        CodeCommentThread thread2 = new CodeCommentThread();
        thread2.commitId = "123456";
        thread2.state = CommentThread.ThreadState.CLOSED;
        CodeRange codeRange = new CodeRange();
        codeRange.path = "readme.md";
        codeRange.startColumn = 0;
        codeRange.startLine = 1;
        codeRange.startSide = CodeRange.Side.A;
        codeRange.endColumn = 100;
        codeRange.endLine = 10;
        codeRange.endSide = CodeRange.Side.B;
        thread2.codeRange = codeRange;
        thread2.createdDate = JodaDateUtil.before(2);
        thread2.save();

        ReviewComment reviewComment2 = new ReviewComment();
        reviewComment2.thread = thread2;
        reviewComment2.createdDate = JodaDateUtil.before(2);
        reviewComment2.setContents("reviewComment2");
        reviewComment2.save();
    }

}

@@ -250,24 +250,83 @@
 yThread() %7B%0A
+        /* Test comments in NonRangedCodeCommentThread */%0A%0A
         // g
@@ -730,16 +730,368 @@
 1);%0A
+%0A%0A        /* Test comments in CodeCommentThread */%0A%0A        // given%0A        thread = CommentThread.find.byId(2l);%0A        assertThat(thread).isNotNull();%0A%0A        // when%0A        commentList = ReviewComment.findByThread(2l);%0A%0A        // then%0A        assertThat(commentList.size()).isEqualTo(1);%0A        assertThat(commentList.get(0).id).isEqualTo(3l);%0A
     %7D%0A%0A
-%0A
     
@@ -1237,16 +1237,278 @@
 - id: 1%0A
+     * %7B@link models.ReviewComment%7D %EC%83%9D%EC%84%B1%ED%95%98%EC%97%AC %7B@link models.NonRangedCodeCommentThread%7D%EC%97%90 %EC%B6%94%EA%B0%80.%0A     *  - createdDate: 3%EC%9D%BC%EC%A0%84%0A     *  - id: 1%0A     * %7B@link models.ReviewComment%7D %EC%83%9D%EC%84%B1%ED%95%98%EC%97%AC %7B@link models.NonRangedCodeCommentThread%7D%EC%97%90 %EC%B6%94%EA%B0%80.%0A     *  - createdDate: 2%EC%9D%BC%EC%A0%84%0A     *  - id: 2%0A
      * %7B
@@ -1660,24 +1660,162 @@
  *  - id: 2%0A
+     * %7B@code %7D%0A     * %7B@link models.ReviewComment%7D %EC%83%9D%EC%84%B1%ED%95%98%EC%97%AC %7B@link models.CodeCommentThread%7D%EC%97%90 %EC%B6%94%EA%B0%80.%0A     *  - createdDate: 3%EC%9D%BC%EC%A0%84%0A     *  - id: 1%0A
      */%0A    

add a TC to test comments in threads.