View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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 org.junit.Assert.assertEquals;
23  
24  import org.junit.Test;
25  
26  import nl.jqno.equalsverifier.EqualsVerifier;
27  
28  public class LineColumnTest {
29  
30      @Test
31      public void testCompareToBothEqual() {
32          assertEquals("Invalid LineColumn comparing result",
33                  0, new LineColumn(0, 0).compareTo(new LineColumn(0, 0)));
34      }
35  
36      @Test
37      public void testCompareToFirstLarger() {
38          final LineColumn lineColumn = new LineColumn(0, 0);
39  
40          assertEquals("Invalid LineColumn comparison result",
41                  1, new LineColumn(1, 0).compareTo(lineColumn));
42          assertEquals("Invalid LineColumn comparison result",
43                  1, new LineColumn(0, 1).compareTo(lineColumn));
44      }
45  
46      @Test
47      public void testCompareToFirstSmaller() {
48          final Comparable<LineColumn> lineColumn = new LineColumn(0, 0);
49  
50          assertEquals("Invalid LineColumn comparison result", -1,
51                  lineColumn.compareTo(new LineColumn(1, 0)));
52          assertEquals("Invalid LineColumn comparison result", -1,
53                  lineColumn.compareTo(new LineColumn(0, 1)));
54      }
55  
56      @Test
57      public void testEqualsAndHashCode() {
58          EqualsVerifier.forClass(LineColumn.class).usingGetClass().verify();
59      }
60  
61      @Test
62      public void testGetters() {
63          final LineColumn lineColumn = new LineColumn(2, 3);
64  
65          assertEquals("Invalid LineColumn comparison result",
66                  2, lineColumn.getLine());
67          assertEquals("Invalid LineColumn comparison result",
68                  3, lineColumn.getColumn());
69      }
70  }