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 import nl.jqno.equalsverifier.EqualsVerifier;
27 import nl.jqno.equalsverifier.EqualsVerifierReport;
28
29 public class LineColumnTest {
30
31 @Test
32 public void testCompareToBothEqual() {
33 final int actual = new LineColumn(0, 0).compareTo(new LineColumn(0, 0));
34 assertWithMessage("Invalid LineColumn comparing result")
35 .that(actual)
36 .isEqualTo(0);
37 }
38
39 @Test
40 public void testCompareToFirstLarger() {
41 final LineColumn lineColumn = new LineColumn(0, 0);
42
43 final int line1column0 = new LineColumn(1, 0).compareTo(lineColumn);
44 assertWithMessage("Invalid LineColumn comparison result")
45 .that(line1column0)
46 .isEqualTo(1);
47 final int line2Column1 = new LineColumn(0, 1).compareTo(lineColumn);
48 assertWithMessage("Invalid LineColumn comparison result")
49 .that(line2Column1)
50 .isEqualTo(1);
51 }
52
53 @Test
54 public void testCompareToFirstSmaller() {
55 final Comparable<LineColumn> lineColumn = new LineColumn(0, 0);
56
57 final int line1Column0 = lineColumn.compareTo(new LineColumn(1, 0));
58 assertWithMessage("Invalid LineColumn comparison result")
59 .that(line1Column0)
60 .isEqualTo(-1);
61 final int line0Column1 = lineColumn.compareTo(new LineColumn(0, 1));
62 assertWithMessage("Invalid LineColumn comparison result")
63 .that(line0Column1)
64 .isEqualTo(-1);
65 }
66
67 @Test
68 public void testEqualsAndHashCode() {
69 final EqualsVerifierReport ev = EqualsVerifier.forClass(LineColumn.class).usingGetClass()
70 .report();
71 assertWithMessage("Error: " + ev.getMessage())
72 .that(ev.isSuccessful())
73 .isTrue();
74 }
75
76 @Test
77 public void testGetters() {
78 final LineColumn lineColumn = new LineColumn(2, 3);
79
80 assertWithMessage("Invalid LineColumn comparison result")
81 .that(lineColumn.getLine())
82 .isEqualTo(2);
83 assertWithMessage("Invalid LineColumn comparison result")
84 .that(lineColumn.getColumn())
85 .isEqualTo(3);
86 }
87
88 }