2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.plugins.core.issue.ignore.pattern;
23 import org.junit.Test;
25 import static org.fest.assertions.Assertions.assertThat;
27 public class LineRangeTest {
29 @Test(expected = IllegalArgumentException.class)
30 public void lineRangeShouldBeOrdered() {
31 new LineRange(25, 12);
35 public void shouldConvertLineRangeToLines() {
36 LineRange range = new LineRange(12, 15);
38 assertThat(range.toLines()).containsOnly(12, 13, 14, 15);
42 public void shouldTestInclusionInRangeOfLines() {
43 LineRange range = new LineRange(12, 15);
45 assertThat(range.in(3)).isFalse();
46 assertThat(range.in(12)).isTrue();
47 assertThat(range.in(13)).isTrue();
48 assertThat(range.in(14)).isTrue();
49 assertThat(range.in(15)).isTrue();
50 assertThat(range.in(16)).isFalse();
54 public void testToString() throws Exception {
55 assertThat(new LineRange(12, 15).toString()).isEqualTo("[12-15]");
59 public void testEquals() throws Exception {
60 LineRange range = new LineRange(12, 15);
61 assertThat(range).isEqualTo(range);
62 assertThat(range).isEqualTo(new LineRange(12, 15));
63 assertThat(range).isNotEqualTo(new LineRange(12, 2000));
64 assertThat(range).isNotEqualTo(new LineRange(1000, 2000));
65 assertThat(range).isNotEqualTo(null);
66 assertThat(range).isNotEqualTo(new StringBuffer());
70 public void testHashCode() throws Exception {
71 assertThat(new LineRange(12, 15).hashCode()).isEqualTo(new LineRange(12, 15).hashCode());