aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-04-05 19:15:30 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-04-06 15:42:53 +0200
commit53b695838275d30ab0da26a54bcac93b5577f3fe (patch)
treebbb3a6051c9b5a59214efac3c46433ee823a6719 /sonar-plugin-api/src/test
parent1f69c8dd6cf99519d927cb8f7938d37dc3ac5b14 (diff)
downloadsonarqube-53b695838275d30ab0da26a54bcac93b5577f3fe.tar.gz
sonarqube-53b695838275d30ab0da26a54bcac93b5577f3fe.zip
SONAR-7488 add PostProjectAnalysisTaskTester
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/CeTaskBuilder_PostProjectAnalysisTaskTesterTest.java92
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ConditionBuilder_PostProjectAnalysisTaskTesterTest.java298
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTesterTest.java146
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ProjectBuilder_PostProjectAnalysisTaskTesterTest.java114
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/QualityGateBuilder_PostProjectAnalysisTaskTesterTest.java145
5 files changed, 795 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/CeTaskBuilder_PostProjectAnalysisTaskTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/CeTaskBuilder_PostProjectAnalysisTaskTesterTest.java
new file mode 100644
index 00000000000..4425b0f2281
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/CeTaskBuilder_PostProjectAnalysisTaskTesterTest.java
@@ -0,0 +1,92 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ce.posttask;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CeTaskBuilder_PostProjectAnalysisTaskTesterTest {
+ private static final CeTask.Status SOME_STATUS = CeTask.Status.SUCCESS;
+ private static final String SOME_ID = "some id";
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private PostProjectAnalysisTaskTester.CeTaskBuilder underTest = PostProjectAnalysisTaskTester.newCeTaskBuilder();
+
+ @Test
+ public void setId_throws_NPE_if_id_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("id can not be null");
+
+ underTest.setId(null);
+ }
+
+ @Test
+ public void setStatus_throws_NPE_if_status_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("status can not be null");
+
+ underTest.setStatus(null);
+ }
+
+ @Test
+ public void build_throws_NPE_if_id_is_null() {
+ underTest.setStatus(SOME_STATUS);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("id can not be null");
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_throws_NPE_if_status_is_null() {
+ underTest.setId(SOME_ID);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("status can not be null");
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_returns_new_instance_at_each_call() {
+ underTest.setId(SOME_ID).setStatus(SOME_STATUS);
+
+ assertThat(underTest.build()).isNotSameAs(underTest.build());
+ }
+
+ @Test
+ public void verify_getters() {
+ CeTask ceTask = underTest.setId(SOME_ID).setStatus(SOME_STATUS).build();
+
+ assertThat(ceTask.getId()).isEqualTo(SOME_ID);
+ assertThat(ceTask.getStatus()).isEqualTo(SOME_STATUS);
+ }
+
+ @Test
+ public void verify_toString() {
+ assertThat(underTest.setId(SOME_ID).setStatus(SOME_STATUS).build().toString()).isEqualTo("CeTask{id='some id', status=SUCCESS}");
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ConditionBuilder_PostProjectAnalysisTaskTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ConditionBuilder_PostProjectAnalysisTaskTesterTest.java
new file mode 100644
index 00000000000..c6ab146015d
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ConditionBuilder_PostProjectAnalysisTaskTesterTest.java
@@ -0,0 +1,298 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ce.posttask;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
+ private static final String SOME_METRIC_KEY = "some metric key";
+ private static final QualityGate.Operator SOME_OPERATOR = QualityGate.Operator.GREATER_THAN;
+ private static final String SOME_ERROR_THRESHOLD = "some error threshold";
+ private static final String SOME_WARNING_THRESHOLD = "some warning threshold";
+ private static final QualityGate.EvaluationStatus SOME_STATUS_BUT_NO_VALUE = QualityGate.EvaluationStatus.OK;
+ private static final String SOME_VALUE = "some value";
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private PostProjectAnalysisTaskTester.ConditionBuilder underTest = PostProjectAnalysisTaskTester.newConditionBuilder();
+
+ @Test
+ public void setMetricKey_throws_NPE_if_operator_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("metricKey can not be null");
+
+ underTest.setMetricKey(null);
+ }
+
+ @Test
+ public void setOperator_throws_NPE_if_operator_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("operator can not be null");
+
+ underTest.setOperator(null);
+ }
+
+ @Test
+ public void buildNoValue_throws_NPE_if_metricKey_is_null() {
+ underTest.setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("metricKey can not be null");
+
+ underTest.buildNoValue();
+ }
+
+ @Test
+ public void buildNoValue_throws_NPE_if_operator_is_null() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("operator can not be null");
+
+ underTest.buildNoValue();
+ }
+
+ @Test
+ public void buildNoValue_throws_ISE_if_both_warningThreshold_and_errorThreshold_are_null() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR);
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("At least one of errorThreshold and warningThreshold must be non null");
+
+ underTest.buildNoValue();
+ }
+
+ @Test
+ public void buildNoValue_returns_Condition_which_getStatus_method_returns_NO_VALUE() {
+ initValidBuilder();
+
+ assertThat(underTest.buildNoValue().getStatus()).isEqualTo(QualityGate.EvaluationStatus.NO_VALUE);
+ }
+
+ @Test
+ public void buildNoValue_returns_Condition_which_getValue_method_throws_ISE() {
+ initValidBuilder();
+ QualityGate.Condition condition = underTest.buildNoValue();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("There is no value when status is NO_VALUE");
+
+ condition.getValue();
+ }
+
+ @Test
+ public void buildNoValue_does_not_fail_when_only_errorThreshold_is_set() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD);
+
+ underTest.buildNoValue();
+ }
+
+ @Test
+ public void buildNoValue_does_not_fail_when_only_wardThreshold_is_set() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setWarningThreshold(SOME_WARNING_THRESHOLD);
+
+ underTest.buildNoValue();
+ }
+
+ @Test
+ public void buildNoValue_returns_new_instance_at_each_call() {
+ initValidBuilder();
+
+ assertThat(underTest.buildNoValue()).isNotSameAs(underTest.buildNoValue());
+ }
+
+ @Test
+ public void buildNoValue_has_no_value_in_toString_and_status_is_NO_VALUE() {
+ initValidBuilder();
+
+ assertThat(underTest.buildNoValue().toString())
+ .isEqualTo(
+ "Condition{status=NO_VALUE, metricKey='some metric key', operator=GREATER_THAN, " +
+ "errorThreshold='some error threshold', warningThreshold='some warning threshold', onLeakPeriod=false}");
+ }
+
+ @Test
+ public void verify_getters_of_object_returned_by_buildNoValue() {
+ initValidBuilder().setOnLeakPeriod(true);
+
+ QualityGate.Condition condition = underTest.buildNoValue();
+
+ assertThat(condition.getMetricKey()).isEqualTo(SOME_METRIC_KEY);
+ assertThat(condition.getOperator()).isEqualTo(SOME_OPERATOR);
+ assertThat(condition.getErrorThreshold()).isEqualTo(SOME_ERROR_THRESHOLD);
+ assertThat(condition.getWarningThreshold()).isEqualTo(SOME_WARNING_THRESHOLD);
+ assertThat(condition.isOnLeakPeriod()).isTrue();
+ }
+
+ @Test
+ public void build_throws_NPE_if_status_is_null() {
+ initValidBuilder();
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("status can not be null");
+
+ underTest.build(null, SOME_VALUE);
+ }
+
+ @Test
+ public void build_throws_IAE_if_status_is_NO_VALUE() {
+ initValidBuilder();
+
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("status can not be NO_VALUE, use method buildNoValue() instead");
+
+ underTest.build(QualityGate.EvaluationStatus.NO_VALUE, SOME_VALUE);
+ }
+
+ @Test
+ public void build_throws_NPE_if_value_is_null() {
+ initValidBuilder();
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("value can not be null, use method buildNoValue() instead");
+
+ underTest.build(SOME_STATUS_BUT_NO_VALUE, null);
+ }
+
+ @Test
+ public void build_throws_NPE_if_metricKey_is_null() {
+ underTest.setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("metricKey can not be null");
+
+ underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
+ }
+
+ @Test
+ public void build_throws_NPE_if_operator_is_null() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("operator can not be null");
+
+ underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
+ }
+
+ @Test
+ public void build_does_not_fail_when_only_errorThreshold_is_set() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD);
+
+ underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
+ }
+
+ @Test
+ public void build_does_not_fail_when_only_wardThreshold_is_set() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setWarningThreshold(SOME_WARNING_THRESHOLD);
+
+ underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
+ }
+
+ @Test
+ public void build_throws_ISE_if_both_warningThreshold_and_errorThreshold_are_null() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR);
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("At least one of errorThreshold and warningThreshold must be non null");
+
+ underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
+ }
+
+ @Test
+ public void build_returns_new_instance_at_each_call() {
+ initValidBuilder();
+
+ assertThat(underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE)).isNotSameAs(underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE));
+ }
+
+ @Test
+ public void build_has_value_in_toString_and_specified_status() {
+ initValidBuilder();
+
+ assertThat(underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE).toString())
+ .isEqualTo(
+ "Condition{status=OK, metricKey='some metric key', operator=GREATER_THAN, "
+ + "errorThreshold='some error threshold', warningThreshold='some warning threshold', onLeakPeriod=false, value='some value'}");
+ }
+
+ @Test
+ public void build_returns_Condition_which_getStatus_method_returns_NO_VALUE() {
+ initValidBuilder();
+
+ assertThat(underTest.buildNoValue().getStatus()).isEqualTo(QualityGate.EvaluationStatus.NO_VALUE);
+ }
+
+ @Test
+ public void build_returns_Condition_which_getValue_method_throws_ISE() {
+ initValidBuilder();
+ QualityGate.Condition condition = underTest.buildNoValue();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("There is no value when status is NO_VALUE");
+
+ condition.getValue();
+ }
+
+ @Test
+ public void verify_getters_of_object_returned_by_build() {
+ initValidBuilder().setOnLeakPeriod(true);
+
+ QualityGate.Condition condition = underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
+
+ assertThat(condition.getStatus()).isEqualTo(SOME_STATUS_BUT_NO_VALUE);
+ assertThat(condition.getMetricKey()).isEqualTo(SOME_METRIC_KEY);
+ assertThat(condition.getOperator()).isEqualTo(SOME_OPERATOR);
+ assertThat(condition.getErrorThreshold()).isEqualTo(SOME_ERROR_THRESHOLD);
+ assertThat(condition.getWarningThreshold()).isEqualTo(SOME_WARNING_THRESHOLD);
+ assertThat(condition.isOnLeakPeriod()).isTrue();
+ assertThat(condition.getValue()).isEqualTo(SOME_VALUE);
+ }
+
+ @Test
+ public void isOnLeakPeriod_is_false_by_default() {
+ initValidBuilder();
+
+ assertThat(underTest.buildNoValue().isOnLeakPeriod()).isFalse();
+ assertThat(underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE).isOnLeakPeriod()).isFalse();
+ }
+
+ @Test
+ public void isOnLeakPeriod_changes_isOnLeakPeriod_returned_value() {
+ initValidBuilder().setOnLeakPeriod(true);
+
+ assertThat(underTest.buildNoValue().isOnLeakPeriod()).isTrue();
+ assertThat(underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE).isOnLeakPeriod()).isTrue();
+
+ initValidBuilder().setOnLeakPeriod(false);
+
+ assertThat(underTest.buildNoValue().isOnLeakPeriod()).isFalse();
+ assertThat(underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE).isOnLeakPeriod()).isFalse();
+ }
+
+ private PostProjectAnalysisTaskTester.ConditionBuilder initValidBuilder() {
+ underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+ return underTest;
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTesterTest.java
new file mode 100644
index 00000000000..320a3349e2c
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTesterTest.java
@@ -0,0 +1,146 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ce.posttask;
+
+import java.util.Date;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class PostProjectAnalysisTaskTesterTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private CeTask ceTask = mock(CeTask.class);
+ private Project project = mock(Project.class);
+ private long someDateAsLong = 846351351684351L;
+ private Date someDate = new Date(someDateAsLong);
+ private QualityGate qualityGate = mock(QualityGate.class);
+ private CaptorPostProjectAnalysisTask captorPostProjectAnalysisTask = new CaptorPostProjectAnalysisTask();
+ private PostProjectAnalysisTaskTester underTest = PostProjectAnalysisTaskTester.of(captorPostProjectAnalysisTask);
+
+ @Test
+ public void of_throws_NPE_if_PostProjectAnalysisTask_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("PostProjectAnalysisTask instance can not be null");
+
+ PostProjectAnalysisTaskTester.of(null);
+ }
+
+ @Test
+ public void withCeTask_throws_NPE_if_ceTask_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("ceTask can not be null");
+
+ underTest.withCeTask(null);
+ }
+
+ @Test
+ public void withProject_throws_NPE_if_project_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("project can not be null");
+
+ underTest.withProject(null);
+ }
+
+ @Test
+ public void at_throws_NPE_if_date_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("date can not be null");
+
+ underTest.at(null);
+ }
+
+ @Test
+ public void withQualityGate_does_not_throw_NPE_if_project_is_null() {
+ underTest.withQualityGate(null);
+ }
+
+ @Test
+ public void execute_throws_NPE_if_ceTask_is_null() {
+ underTest.withProject(project).at(someDate);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("ceTask can not be null");
+
+ underTest.execute();
+ }
+
+ @Test
+ public void execute_throws_NPE_if_project_is_null() {
+ underTest.withCeTask(ceTask).at(someDate);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("project can not be null");
+
+ underTest.execute();
+ }
+
+ @Test
+ public void verify_getters_of_ProjectAnalysis_object_passed_to_PostProjectAnalysisTask() {
+ underTest.withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).at(someDate);
+
+ underTest.execute();
+
+ PostProjectAnalysisTask.ProjectAnalysis projectAnalysis = captorPostProjectAnalysisTask.projectAnalysis;
+ assertThat(projectAnalysis).isNotNull();
+ assertThat(projectAnalysis.getCeTask()).isSameAs(ceTask);
+ assertThat(projectAnalysis.getProject()).isSameAs(project);
+ assertThat(projectAnalysis.getDate()).isSameAs(someDate);
+ assertThat(projectAnalysis.getQualityGate()).isSameAs(qualityGate);
+ }
+
+ @Test
+ public void verify_toString_of_ProjectAnalysis_object_passed_to_PostProjectAnalysisTask() {
+ when(ceTask.toString()).thenReturn("CeTask");
+ when(project.toString()).thenReturn("Project");
+ when(qualityGate.toString()).thenReturn("QualityGate");
+ underTest.withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).at(someDate);
+
+ underTest.execute();
+
+ assertThat(captorPostProjectAnalysisTask.projectAnalysis.toString())
+ .isEqualTo("ProjectAnalysis{ceTask=CeTask, project=Project, date=846351351684351, qualityGate=QualityGate}");
+
+ }
+
+ @Test
+ public void execute_throws_NPE_if_date_is_null() {
+ underTest.withCeTask(ceTask).withProject(project);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("date can not be null");
+
+ underTest.execute();
+ }
+
+ private static class CaptorPostProjectAnalysisTask implements PostProjectAnalysisTask {
+ private ProjectAnalysis projectAnalysis;
+
+ @Override
+ public void finished(ProjectAnalysis analysis) {
+ this.projectAnalysis = analysis;
+ }
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ProjectBuilder_PostProjectAnalysisTaskTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ProjectBuilder_PostProjectAnalysisTaskTesterTest.java
new file mode 100644
index 00000000000..25bc2d4614d
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ProjectBuilder_PostProjectAnalysisTaskTesterTest.java
@@ -0,0 +1,114 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ce.posttask;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ProjectBuilder_PostProjectAnalysisTaskTesterTest {
+ private static final String SOME_NAME = "some name";
+ private static final String SOME_KEY = "some key";
+ private static final String SOME_UUID = "some uuid";
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private PostProjectAnalysisTaskTester.ProjectBuilder underTest = PostProjectAnalysisTaskTester.newProjectBuilder();
+
+ @Test
+ public void setKey_throws_NPE_if_key_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("key can not be null");
+
+ underTest.setKey(null);
+ }
+
+ @Test
+ public void setName_throws_NPE_if_name_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("name can not be null");
+
+ underTest.setName(null);
+ }
+
+ @Test
+ public void setUuid_throws_NPE_if_uuid_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("uuid can not be null");
+
+ underTest.setUuid(null);
+ }
+
+ @Test
+ public void build_throws_NPE_if_key_is_null() {
+ underTest.setUuid(SOME_UUID).setName(SOME_NAME);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("key can not be null");
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_throws_NPE_if_name_is_null() {
+ underTest.setUuid(SOME_UUID).setKey(SOME_KEY);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("name can not be null");
+
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_throws_NPE_if_uuid_is_null() {
+ underTest.setKey(SOME_KEY).setName(SOME_NAME);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("uuid can not be null");
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_returns_new_instance_at_each_call() {
+ underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME);
+
+ assertThat(underTest.build()).isNotSameAs(underTest.build());
+ }
+
+ @Test
+ public void verify_getters() {
+ Project project = underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME).build();
+
+ assertThat(project.getUuid()).isEqualTo(SOME_UUID);
+ assertThat(project.getKey()).isEqualTo(SOME_KEY);
+ assertThat(project.getName()).isEqualTo(SOME_NAME);
+ }
+
+ @Test
+ public void verify_toString() {
+ assertThat(underTest.setUuid(SOME_UUID).setKey(SOME_KEY).setName(SOME_NAME).build().toString())
+ .isEqualTo("Project{uuid='some uuid', key='some key', name='some name'}");
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/QualityGateBuilder_PostProjectAnalysisTaskTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/QualityGateBuilder_PostProjectAnalysisTaskTesterTest.java
new file mode 100644
index 00000000000..61a466b372e
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/QualityGateBuilder_PostProjectAnalysisTaskTesterTest.java
@@ -0,0 +1,145 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ce.posttask;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class QualityGateBuilder_PostProjectAnalysisTaskTesterTest {
+ private static final String SOME_NAME = "some name";
+ private static final QualityGate.Status SOME_STATUS = QualityGate.Status.ERROR;
+ private static final String SOME_ID = "some id";
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private QualityGate.Condition condition1 = mock(QualityGate.Condition.class);
+ private QualityGate.Condition condition2 = mock(QualityGate.Condition.class);
+ private PostProjectAnalysisTaskTester.QualityGateBuilder underTest = PostProjectAnalysisTaskTester.newQualityGateBuilder();
+
+ @Test
+ public void setId_throws_NPE_if_id_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("id can not be null");
+
+ underTest.setId(null);
+ }
+
+ @Test
+ public void setStatus_throws_NPE_if_status_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("status can not be null");
+
+ underTest.setStatus(null);
+ }
+
+ @Test
+ public void setName_throws_NPE_if_name_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("name can not be null");
+
+ underTest.setName(null);
+ }
+
+ @Test
+ public void addCondition_throws_NPE_if_condition_is_null() {
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("condition can not be null");
+
+ underTest.add(null);
+ }
+
+ @Test
+ public void clearConditions_does_not_raise_any_error_if_there_is_no_condition_in_builder() {
+ underTest.clearConditions();
+ }
+
+ @Test
+ public void clearConditions_removes_all_conditions_from_builder() {
+ underTest.setId(SOME_ID).setStatus(SOME_STATUS).setName(SOME_NAME).add(condition1).add(condition2);
+
+ assertThat(underTest.build().getConditions()).containsOnly(condition1, condition2);
+
+ underTest.clearConditions();
+
+ assertThat(underTest.build().getConditions()).isEmpty();
+ }
+
+ @Test
+ public void build_throws_NPE_if_id_is_null() {
+ underTest.setStatus(SOME_STATUS).setName(SOME_NAME);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("id can not be null");
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_throws_NPE_if_status_is_null() {
+ underTest.setId(SOME_ID).setName(SOME_NAME);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("status can not be null");
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_throws_NPE_if_name_is_null() {
+ underTest.setId(SOME_ID).setStatus(SOME_STATUS);
+
+ expectedException.expect(NullPointerException.class);
+ expectedException.expectMessage("name can not be null");
+
+ underTest.build();
+ }
+
+ @Test
+ public void build_returns_new_instance_at_each_call() {
+ underTest.setId(SOME_ID).setStatus(SOME_STATUS).setName(SOME_NAME);
+
+ assertThat(underTest.build()).isNotSameAs(underTest.build());
+ }
+
+ @Test
+ public void verify_getters() {
+ QualityGate qualityGate = underTest.setId(SOME_ID).setStatus(SOME_STATUS).setName(SOME_NAME).add(condition1).add(condition2).build();
+
+ assertThat(qualityGate.getId()).isEqualTo(SOME_ID);
+ assertThat(qualityGate.getStatus()).isEqualTo(SOME_STATUS);
+ assertThat(qualityGate.getName()).isEqualTo(SOME_NAME);
+ assertThat(qualityGate.getConditions()).containsOnly(condition1, condition2);
+ }
+
+ @Test
+ public void verify_toString() {
+ when(condition1.toString()).thenReturn("condition1");
+ when(condition2.toString()).thenReturn("condition2");
+
+ assertThat(underTest.setId(SOME_ID).setStatus(SOME_STATUS).setName(SOME_NAME).add(condition1).add(condition2).build().toString())
+ .isEqualTo("QualityGate{id='some id', name='some name', status=ERROR, conditions=[condition1, condition2]}");
+ }
+}