diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-07-28 05:33:33 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-07-28 11:17:54 +0400 |
commit | b56b994e0e67043be18cf5803474ed01ffed100f (patch) | |
tree | 43fdc8cf8f3517c9262b54098b84ac2f8fbbb4bb /sonar-server/src/test/java | |
parent | b0e768ada85207c3ac6424b069e0dbc4e162c9db (diff) | |
download | sonarqube-b56b994e0e67043be18cf5803474ed01ffed100f.tar.gz sonarqube-b56b994e0e67043be18cf5803474ed01ffed100f.zip |
SONAR-2596 Reduce number of arguments for NotificationService constructor
Diffstat (limited to 'sonar-server/src/test/java')
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java | 55 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java | 25 |
2 files changed, 17 insertions, 63 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java deleted file mode 100644 index 82f1c4fbad7..00000000000 --- a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.server.notifications; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.apache.commons.configuration.Configuration; -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.notifications.NotificationChannel; -import org.sonar.api.notifications.NotificationDispatcher; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -public class NotificationServiceDbTest extends AbstractDbUnitTestCase { - - private NotificationService notificationService; - - @Before - public void setUp() { - setupData("fixture"); - notificationService = new NotificationService(mock(Configuration.class), getSessionFactory(), null, null); - } - - @Test - public void shouldCheckEnablement() { - NotificationChannel email = mock(NotificationChannel.class); - when(email.getKey()).thenReturn("EmailNotificationChannel"); - NotificationDispatcher commentOnReviewAssignedToMe = mock(NotificationDispatcher.class); - when(commentOnReviewAssignedToMe.getKey()).thenReturn("CommentOnReviewAssignedToMe"); - - assertThat(notificationService.isEnabled("simon", email, commentOnReviewAssignedToMe), is(true)); - assertThat(notificationService.isEnabled("godin", email, commentOnReviewAssignedToMe), is(false)); - } - -} diff --git a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java index 1bc824b1413..c75a702b3cf 100644 --- a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java @@ -20,6 +20,7 @@ package org.sonar.server.notifications; import static org.mockito.Matchers.any; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -89,8 +90,8 @@ public class NotificationServiceTest { manager = mock(DefaultNotificationManager.class); Configuration configuration = new BaseConfiguration(); configuration.setProperty("sonar.notifications.delay", "1"); // delay 1 second - service = spy(new NotificationService(configuration, null, manager, dispatchers, channels)); - doReturn(false).when(service).isEnabled(any(String.class), any(NotificationChannel.class), any(NotificationDispatcher.class)); + service = spy(new NotificationService(configuration, manager, dispatchers, channels)); + doReturn(false).when(manager).isEnabled(any(String.class), any(String.class), any(String.class)); } @Test @@ -120,8 +121,8 @@ public class NotificationServiceTest { */ @Test public void scenario1() { - doReturn(true).when(service).isEnabled(USER_SIMON, emailChannel, commentOnReviewAssignedToMe); - doReturn(true).when(service).isEnabled(USER_SIMON, emailChannel, commentOnReviewCreatedByMe); + doReturn(true).when(manager).isEnabled(USER_SIMON, "email", "comment on review assigned to me"); + doReturn(true).when(manager).isEnabled(USER_SIMON, "email", "comment on review created by me"); Notification notification = mock(Notification.class); creator = USER_SIMON; @@ -129,6 +130,8 @@ public class NotificationServiceTest { service.deliver(notification); + verify(emailChannel, atLeast(1)).getKey(); + verify(gtalkChannel, atLeast(1)).getKey(); verify(emailChannel).deliver(notification, USER_SIMON); verifyNoMoreInteractions(emailChannel); verifyNoMoreInteractions(gtalkChannel); @@ -147,8 +150,8 @@ public class NotificationServiceTest { */ @Test public void scenario2() { - doReturn(true).when(service).isEnabled(USER_EVGENY, gtalkChannel, commentOnReviewCreatedByMe); - doReturn(true).when(service).isEnabled(USER_SIMON, emailChannel, commentOnReviewAssignedToMe); + doReturn(true).when(manager).isEnabled(USER_EVGENY, "gtalk", "comment on review created by me"); + doReturn(true).when(manager).isEnabled(USER_SIMON, "email", "comment on review assigned to me"); Notification notification = mock(Notification.class); creator = USER_EVGENY; @@ -156,6 +159,8 @@ public class NotificationServiceTest { service.deliver(notification); + verify(emailChannel, atLeast(1)).getKey(); + verify(gtalkChannel, atLeast(1)).getKey(); verify(emailChannel).deliver(notification, USER_SIMON); verify(gtalkChannel).deliver(notification, USER_EVGENY); verifyNoMoreInteractions(emailChannel); @@ -174,8 +179,8 @@ public class NotificationServiceTest { */ @Test public void scenario3() { - doReturn(true).when(service).isEnabled(USER_SIMON, emailChannel, commentOnReviewAssignedToMe); - doReturn(true).when(service).isEnabled(USER_SIMON, gtalkChannel, commentOnReviewAssignedToMe); + doReturn(true).when(manager).isEnabled(USER_SIMON, "email", "comment on review assigned to me"); + doReturn(true).when(manager).isEnabled(USER_SIMON, "gtalk", "comment on review assigned to me"); Notification notification = mock(Notification.class); creator = USER_EVGENY; @@ -183,6 +188,8 @@ public class NotificationServiceTest { service.deliver(notification); + verify(emailChannel, atLeast(1)).getKey(); + verify(gtalkChannel, atLeast(1)).getKey(); verify(emailChannel).deliver(notification, USER_SIMON); verify(gtalkChannel).deliver(notification, USER_SIMON); verifyNoMoreInteractions(emailChannel); @@ -207,6 +214,8 @@ public class NotificationServiceTest { service.deliver(notification); + verify(emailChannel, atLeast(1)).getKey(); + verify(gtalkChannel, atLeast(1)).getKey(); verifyNoMoreInteractions(emailChannel); verifyNoMoreInteractions(gtalkChannel); } |