1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.api;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23
24 import org.junit.jupiter.api.Test;
25
26 public class CommentTest {
27
28 @Test
29 public void test() {
30 final String[] text = {"test"};
31 final Comment comment = new Comment(text, 1, 2, 3);
32
33 assertWithMessage("invalid text")
34 .that(comment.getText())
35 .isEqualTo(text);
36 assertWithMessage("invalid start line")
37 .that(comment.getStartLineNo())
38 .isEqualTo(2);
39 assertWithMessage("invalid end line")
40 .that(comment.getEndLineNo())
41 .isEqualTo(2);
42 assertWithMessage("invalid start column")
43 .that(comment.getStartColNo())
44 .isEqualTo(1);
45 assertWithMessage("invalid end column")
46 .that(comment.getEndColNo())
47 .isEqualTo(3);
48 assertWithMessage("invalid string")
49 .that(comment.toString())
50 .isEqualTo("Comment[text=[test], startLineNo=2,"
51 + " endLineNo=2, startColNo=1, endColNo=3]");
52 }
53
54 @Test
55 public void testIntersects() {
56 final String[] text = {"test", "test"};
57 final Comment comment = new Comment(text, 2, 4, 4);
58
59 final String message = "invalid";
60 assertWithMessage(message)
61 .that(comment.intersects(1, 1, 1, 1))
62 .isFalse();
63 assertWithMessage(message)
64 .that(comment.intersects(5, 5, 5, 5))
65 .isFalse();
66 assertWithMessage(message)
67 .that(comment.intersects(1, 1, 5, 5))
68 .isTrue();
69 assertWithMessage(message)
70 .that(comment.intersects(1, 1, 3, 5))
71 .isTrue();
72 assertWithMessage(message)
73 .that(comment.intersects(3, 5, 5, 5))
74 .isTrue();
75 }
76
77 @Test
78 public void testIntersects2() {
79 final String[] text = {"a"};
80 final Comment comment = new Comment(text, 2, 2, 2);
81
82 assertWithMessage("invalid")
83 .that(comment.intersects(2, 2, 2, 2))
84 .isTrue();
85 }
86
87 @Test
88 public void testIntersects3() {
89 final String[] text = {"test"};
90 final Comment comment = new Comment(text, 1, 1, 2);
91
92 assertWithMessage("invalid")
93 .that(comment.intersects(1, Integer.MAX_VALUE, 1, 2))
94 .isFalse();
95 }
96 }