aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-08 17:26:35 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-08 17:33:29 +0200
commitfac42bff8871befc994f1efd5cb8e6c803f44283 (patch)
tree971d7986ac17677c8dd75f9234230d7bfe21021a /sonar-plugin-api
parenteb5a7d26a5b7270351a78ba239068e197430b3ec (diff)
downloadsonarqube-fac42bff8871befc994f1efd5cb8e6c803f44283.tar.gz
sonarqube-fac42bff8871befc994f1efd5cb8e6c803f44283.zip
Fix some quality flaws
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java13
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java49
2 files changed, 54 insertions, 8 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java
index 02d16f29ab4..221282b04e6 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java
@@ -91,21 +91,18 @@ public class BlameLine {
/**
* @return the commit date
*/
+ @CheckForNull
public Date getDate() {
- if (date != null)
- {
+ if (date != null) {
return (Date) date.clone();
}
return null;
}
- public void setDate(Date date) {
- if (date != null)
- {
+ public void setDate(@Nullable Date date) {
+ if (date != null) {
this.date = new Date(date.getTime());
- }
- else
- {
+ } else {
this.date = null;
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java
new file mode 100644
index 00000000000..6d084ead610
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.batch.scm;
+
+import org.junit.Test;
+
+import java.util.Date;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class BlameLineTest {
+
+ @Test
+ public void testBlameLine() {
+ Date date = new Date();
+ BlameLine line1 = new BlameLine(date, "1", "foo");
+ BlameLine line1b = new BlameLine(date, "1", "foo");
+ BlameLine line2 = new BlameLine(date, "2", "foo2");
+
+ assertThat(line1.getAuthor()).isEqualTo("foo");
+ assertThat(line1.getCommitter()).isEqualTo("foo");
+
+ assertThat(line1).isEqualTo(line1);
+ assertThat(line1).isEqualTo(line1b);
+ assertThat(line1.hashCode()).isEqualTo(line1b.hashCode());
+ assertThat(line1).isNotEqualTo(line2);
+ assertThat(line1).isNotEqualTo("foo");
+
+ assertThat(line1.toString()).contains("revision=1,author=foo,committer=foo");
+ }
+
+}