diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-09 12:02:32 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-09 12:02:32 +0200 |
commit | fde900a0be3a5ec99d0b6dfcde4cf18d531210f6 (patch) | |
tree | e9db39dac2810cc1138ebf38d73ff11817c3e054 /sonar-plugin-api | |
parent | 1f2c767187d23d71f2af67a2c1686eb849f3c717 (diff) | |
download | sonarqube-fde900a0be3a5ec99d0b6dfcde4cf18d531210f6.tar.gz sonarqube-fde900a0be3a5ec99d0b6dfcde4cf18d531210f6.zip |
Fix some quality flaws
Diffstat (limited to 'sonar-plugin-api')
3 files changed, 68 insertions, 33 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 221282b04e6..7772d706ec2 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 @@ -44,7 +44,7 @@ public class BlameLine { * @param revision of the commit * @param author will also be used as committer identification */ - public BlameLine(Date date, String revision, @Nullable String author) { + public BlameLine(@Nullable Date date, String revision, @Nullable String author) { this(date, revision, author, author); } @@ -55,58 +55,42 @@ public class BlameLine { * @param author the person who wrote the line * @param committer the person who committed the change */ - public BlameLine(Date date, String revision, @Nullable String author, @Nullable String committer) { - setDate(date); - setRevision(revision); - setAuthor(author); - setCommitter(committer); + public BlameLine(@Nullable Date date, String revision, @Nullable String author, @Nullable String committer) { + if (date != null) { + this.date = new Date(date.getTime()); + } else { + this.date = null; + } + this.revision = revision; + this.author = author; + this.committer = committer; } - public String getRevision() { + public String revision() { return revision; } - public void setRevision(String revision) { - this.revision = revision; - } - @CheckForNull - public String getAuthor() { + public String author() { return author; } - public void setAuthor(@Nullable String author) { - this.author = author; - } - @CheckForNull - public String getCommitter() { + public String committer() { return committer; } - public void setCommitter(@Nullable String committer) { - this.committer = committer; - } - /** * @return the commit date */ @CheckForNull - public Date getDate() { + public Date date() { if (date != null) { return (Date) date.clone(); } return null; } - public void setDate(@Nullable Date date) { - if (date != null) { - this.date = new Date(date.getTime()); - } else { - this.date = null; - } - } - // For testing purpose @Override 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 index 6d084ead610..1ff1eee16b2 100644 --- 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 @@ -32,12 +32,15 @@ public class BlameLineTest { 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"); + BlameLine line2 = new BlameLine(null, "2", "foo2"); - assertThat(line1.getAuthor()).isEqualTo("foo"); - assertThat(line1.getCommitter()).isEqualTo("foo"); + assertThat(line1.author()).isEqualTo("foo"); + assertThat(line1.date()).isEqualTo(date); + assertThat(line1.revision()).isEqualTo("1"); + assertThat(line1.committer()).isEqualTo("foo"); assertThat(line1).isEqualTo(line1); + assertThat(line1).isNotEqualTo(null); assertThat(line1).isEqualTo(line1b); assertThat(line1.hashCode()).isEqualTo(line1b.hashCode()); assertThat(line1).isNotEqualTo(line2); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java new file mode 100644 index 00000000000..f55ec0cc2e5 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/ScmProviderTest.java @@ -0,0 +1,48 @@ +/* + * 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.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.fest.assertions.Assertions.assertThat; + +public class ScmProviderTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testDefaultImplementation() { + ScmProvider provider = new ScmProvider() { + + @Override + public String key() { + return "foo"; + } + }; + + assertThat(provider.supports(null)).isFalse(); + thrown.expect(UnsupportedOperationException.class); + provider.blameCommand(); + } + +} |