View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }