summaryrefslogtreecommitdiffstats
path: root/javatests/com/google/gerrit/mail/AbstractParserTest.java
blob: f99a2af897b77ae8903bb74119769b8ac7afcb2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.mail;

import static com.google.common.truth.Truth.assertThat;

import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Address;
import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;

@Ignore
public class AbstractParserTest {
  protected static final String CHANGE_URL =
      "https://gerrit-review.googlesource.com/c/project/+/123";

  protected static void assertPatchsetComment(String message, MailComment comment) {
    assertThat(comment.fileName).isNull();
    assertThat(comment.message).isEqualTo(message);
    assertThat(comment.inReplyTo).isNull();
    assertThat(comment.type).isEqualTo(MailComment.CommentType.PATCHSET_LEVEL);
  }

  protected static void assertInlineComment(
      String message, MailComment comment, HumanComment inReplyTo) {
    assertThat(comment.fileName).isNull();
    assertThat(comment.message).isEqualTo(message);
    assertThat(comment.inReplyTo.key).isEqualTo(inReplyTo.key);
    assertThat(comment.type).isEqualTo(MailComment.CommentType.INLINE_COMMENT);
  }

  protected static void assertFileComment(String message, MailComment comment, String file) {
    assertThat(comment.fileName).isEqualTo(file);
    assertThat(comment.message).isEqualTo(message);
    assertThat(comment.inReplyTo).isNull();
    assertThat(comment.type).isEqualTo(MailComment.CommentType.FILE_COMMENT);
  }

  protected static HumanComment newComment(String uuid, String file, String message, int line) {
    HumanComment c =
        new HumanComment(
            new Comment.Key(uuid, file, 1),
            Account.id(0),
            Instant.EPOCH,
            (short) 0,
            message,
            "",
            false);
    c.lineNbr = line;
    return c;
  }

  protected static HumanComment newRangeComment(
      String uuid, String file, String message, int line) {
    HumanComment c =
        new HumanComment(
            new Comment.Key(uuid, file, 1),
            Account.id(0),
            Instant.EPOCH,
            (short) 0,
            message,
            "",
            false);
    c.range = new Comment.Range(line, 1, line + 1, 1);
    c.lineNbr = line + 1;
    return c;
  }

  /** Returns a MailMessage.Builder with all required fields populated. */
  protected static MailMessage.Builder newMailMessageBuilder() {
    MailMessage.Builder b = MailMessage.builder();
    b.id("id");
    b.from(Address.create("Foo Bar", "foo@bar.com"));
    b.dateReceived(Instant.now());
    b.subject("");
    return b;
  }

  /** Returns a List of default comments for testing. */
  protected static List<HumanComment> defaultComments() {
    List<HumanComment> comments = new ArrayList<>();
    comments.add(newComment("c1", "gerrit-server/test.txt", "comment", 0));
    comments.add(newComment("c2", "gerrit-server/test.txt", "comment", 2));
    comments.add(newComment("c3", "gerrit-server/test.txt", "comment", 3));
    comments.add(newComment("c3", "gerrit-server/test.txt", "comment", 115));
    comments.add(newRangeComment("c5", "gerrit-server/readme.txt", "comment", 3));
    return comments;
  }
}