aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-03-27 18:17:09 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-03-27 18:17:09 +0100
commit1f281463046e63d81e398737344969942f6c1a4a (patch)
tree0a50db3762b627b9d598c7cb1c08805e3cbf1501 /sonar-plugin-api/src/test
parent6e44175ed6e81ae9989aa767439d91b9a502f5bf (diff)
downloadsonarqube-1f281463046e63d81e398737344969942f6c1a4a.tar.gz
sonarqube-1f281463046e63d81e398737344969942f6c1a4a.zip
Revert "Remove all deprecated Violation APIs"
This reverts commit 5446d877b4e67f2f32ac869e76d9ad02ca226773.
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rules/ViolationTest.java73
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/test/IsViolation.java69
2 files changed, 142 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..029fcc9d9f6
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/ViolationTest.java
@@ -0,0 +1,73 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+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.Before;
+import org.junit.Test;
+
+public class ViolationTest {
+ private Violation violation;
+
+ @Before
+ public void setUp() {
+ violation = Violation.create((Rule) null, null);
+ }
+
+ /**
+ * See http://jira.codehaus.org/browse/SONAR-2386
+ */
+ @Test
+ public void testLineIdContract() {
+ 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));
+ }
+
+ @Test
+ public void testCostContract() {
+ violation.setCost(null);
+ assertThat(violation.getCost(), nullValue());
+
+ violation.setCost(1.0);
+ assertThat(violation.getCost(), is(1.0));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCostContract_NaN() {
+ violation.setCost(Double.NaN);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCostContract_Negative() {
+ violation.setCost(-1.0);
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsViolation.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsViolation.java
new file mode 100644
index 00000000000..c8b9a6b9774
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsViolation.java
@@ -0,0 +1,69 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.test;
+
+import org.mockito.ArgumentMatcher;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.Violation;
+
+public class IsViolation extends ArgumentMatcher<Violation> {
+
+ private Rule rule;
+ private String message;
+ private Resource resource;
+ private Integer lineId;
+
+ public IsViolation(Violation wanted) {
+ this.lineId = wanted.getLineId();
+ this.message = wanted.getMessage();
+ this.resource = wanted.getResource();
+ this.rule = wanted.getRule();
+ }
+
+ public IsViolation(Rule rule, String message, Resource resource, Integer lineId) {
+ this.rule = rule;
+ this.message = message;
+ this.resource = resource;
+ this.lineId = lineId;
+ }
+
+ @Override
+ public boolean matches(Object o) {
+ Violation violation = (Violation) o;
+ if (lineId != null && !lineId.equals(violation.getLineId())) {
+ return false;
+ }
+
+ if (message != null && !message.equals(violation.getMessage())) {
+ return false;
+ }
+
+ if (resource != null && !resource.equals(violation.getResource())) {
+ return false;
+ }
+
+ if (rule != null && !rule.equals(violation.getRule())) {
+ return false;
+ }
+
+ return true;
+ }
+}