aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-07-27 18:35:42 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-07-28 06:06:02 +0400
commitb0e768ada85207c3ac6424b069e0dbc4e162c9db (patch)
tree48e6709ae5d60d084c3d58a4701efeca8c890597
parent223cc999564d32633fbdc493e11556e8a29e2d8b (diff)
downloadsonarqube-b0e768ada85207c3ac6424b069e0dbc4e162c9db.tar.gz
sonarqube-b0e768ada85207c3ac6424b069e0dbc4e162c9db.zip
SONAR-2596 Add unit tests
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java42
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java42
-rw-r--r--sonar-server/src/test/java/org/sonar/server/notifications/reviews/ReviewsNotificationManagerTest.java34
3 files changed, 117 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java
new file mode 100644
index 00000000000..788442341aa
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationChannelTest.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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.notifications;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class NotificationChannelTest {
+
+ @Test
+ public void defaultMethods() {
+ NotificationChannel channel = new FakeNotificationChannel();
+ assertThat(channel.getKey(), is("FakeNotificationChannel"));
+ assertThat(channel.toString(), is("FakeNotificationChannel"));
+ }
+
+ class FakeNotificationChannel extends NotificationChannel {
+ @Override
+ public void deliver(Notification notification, String username) {
+ }
+ }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java
new file mode 100644
index 00000000000..4ea8e86f347
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/notifications/NotificationDispatcherTest.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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.notifications;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class NotificationDispatcherTest {
+
+ @Test
+ public void defaultMethods() {
+ NotificationDispatcher channel = new FakeNotificationDispatcher();
+ assertThat(channel.getKey(), is("FakeNotificationDispatcher"));
+ assertThat(channel.toString(), is("FakeNotificationDispatcher"));
+ }
+
+ class FakeNotificationDispatcher extends NotificationDispatcher {
+ @Override
+ public void dispatch(Notification notification, Context context) {
+ }
+ }
+
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/notifications/reviews/ReviewsNotificationManagerTest.java b/sonar-server/src/test/java/org/sonar/server/notifications/reviews/ReviewsNotificationManagerTest.java
index 187d3e965b3..3cd20d65b5c 100644
--- a/sonar-server/src/test/java/org/sonar/server/notifications/reviews/ReviewsNotificationManagerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/notifications/reviews/ReviewsNotificationManagerTest.java
@@ -19,17 +19,25 @@
*/
package org.sonar.server.notifications.reviews;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
+import java.util.Map;
+
import org.junit.Before;
+import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationManager;
-public class ReviewsNotificationManagerTest { // FIXME implement
+import com.google.common.collect.Maps;
+
+public class ReviewsNotificationManagerTest {
private Notification notification;
private ReviewsNotificationManager manager;
@@ -46,4 +54,28 @@ public class ReviewsNotificationManagerTest { // FIXME implement
manager = new ReviewsNotificationManager(delegate);
}
+ @Test
+ public void shouldScheduleNotification() {
+ Map<String, String> oldValues = Maps.newHashMap();
+ Map<String, String> newValues = Maps.newHashMap();
+ newValues.put("project", "Sonar");
+ newValues.put("resource", "org.sonar.server.ui.DefaultPages");
+ newValues.put("title", "Utility classes should not have a public or default constructor.");
+ newValues.put("creator", "olivier");
+ newValues.put("assignee", "godin");
+ oldValues.put("assignee", "simon");
+ manager.notifyChanged(1L, "freddy", oldValues, newValues);
+ assertThat(notification, notNullValue());
+ assertThat(notification.getType(), is("review-changed"));
+ assertThat(notification.getFieldValue("reviewId"), is("1"));
+ assertThat(notification.getFieldValue("author"), is("freddy"));
+ assertThat(notification.getFieldValue("project"), is("Sonar"));
+ assertThat(notification.getFieldValue("resource"), is("org.sonar.server.ui.DefaultPages"));
+ assertThat(notification.getFieldValue("title"), is("Utility classes should not have a public or default constructor."));
+ assertThat(notification.getFieldValue("creator"), is("olivier"));
+ assertThat(notification.getFieldValue("assignee"), is("godin"));
+ assertThat(notification.getFieldValue("old.assignee"), is("simon"));
+ assertThat(notification.getFieldValue("new.assignee"), is("godin"));
+ }
+
}