diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-27 20:29:11 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-27 22:10:58 +0400 |
commit | 25f963bfb953346ee85337009b1af7d665494aa0 (patch) | |
tree | f1ae028f197e0538460c5d3e349832915bf49bdb /sonar-plugin-api/src/test/java | |
parent | 70c03e6ac1e0f24277655f9e7666142d9418d270 (diff) | |
download | sonarqube-25f963bfb953346ee85337009b1af7d665494aa0.tar.gz sonarqube-25f963bfb953346ee85337009b1af7d665494aa0.zip |
SONAR-2386 Define contract for lineId in Violation
Value can be null or greater than zero, so setter must log warning if
not null and less than 1. It will throw an exception in future releases.
Diffstat (limited to 'sonar-plugin-api/src/test/java')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/rules/ViolationTest.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/ViolationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/ViolationTest.java new file mode 100644 index 00000000000..a77bcd44cc9 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/ViolationTest.java @@ -0,0 +1,48 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.api.rules; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class ViolationTest { + /** + * See http://jira.codehaus.org/browse/SONAR-2386 + */ + @Test + public void testLineIdContract() { + Violation violation = Violation.create((Rule) null, null); + + violation.setLineId(null); + assertThat(violation.hasLineId(), is(false)); + assertThat(violation.getLineId(), nullValue()); + + violation.setLineId(0); + assertThat(violation.hasLineId(), is(false)); + assertThat(violation.getLineId(), nullValue()); + + violation.setLineId(1); + assertThat(violation.hasLineId(), is(true)); + assertThat(violation.getLineId(), is(1)); + } +} |