From 9d7b312b6d6cd5487c232092abb1c5bd623b2654 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 29 May 2012 14:48:21 +0200 Subject: [PATCH] Add some unit tests --- .../ProjectPropertyConditionTest.java | 18 +++++++++ .../workflow/internal/DefaultReviewTest.java | 37 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java index 7e3344d528a..d0b77e6e87d 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java @@ -19,13 +19,20 @@ */ package org.sonar.api.workflow.condition; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.sonar.api.workflow.Review; import org.sonar.api.workflow.WorkflowContext; +import javax.annotation.Nullable; + import static org.fest.assertions.Assertions.assertThat; public class ProjectPropertyConditionTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Test public void getPropertyKey() { ProjectPropertyCondition condition = new ProjectPropertyCondition("foo") { @@ -36,4 +43,15 @@ public class ProjectPropertyConditionTest { }; assertThat(condition.getPropertyKey()).isEqualTo("foo"); } + + @Test + public void keyIsMandatory() { + thrown.expect(IllegalArgumentException.class); + new ProjectPropertyCondition(""){ + @Override + public boolean doVerify(@Nullable Review review, WorkflowContext context) { + return false; + } + }; + } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java new file mode 100644 index 00000000000..e48208a0c69 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java @@ -0,0 +1,37 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 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.workflow.internal; + +import org.junit.Test; +import org.sonar.api.workflow.MutableReview; + +import static org.fest.assertions.Assertions.assertThat; + +public class DefaultReviewTest { + @Test + public void createComment_keep_order() { + MutableReview review = new DefaultReview(); + review.createComment().setMarkdownText("first"); + review.createComment().setMarkdownText("second"); + assertThat(review.getNewComments()).hasSize(2); + assertThat(review.getNewComments().get(0).getMarkdownText()).isEqualTo("first"); + assertThat(review.getNewComments().get(1).getMarkdownText()).isEqualTo("second"); + } +} -- 2.39.5