re base code
[sdc.git] / openecomp-be / lib / openecomp-sdc-notification-lib / openecomp-sdc-notification-core / src / test / java / org / openecomp / sdc / notification / services / impl / NotificationsServiceImplTest.java
1 package org.openecomp.sdc.notification.services.impl;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.mockito.InjectMocks;
6 import org.mockito.Mock;
7 import org.mockito.MockitoAnnotations;
8 import org.mockito.Spy;
9 import org.openecomp.sdc.notification.dao.LastNotificationDao;
10 import org.openecomp.sdc.notification.dao.NotificationsDao;
11 import org.openecomp.sdc.notification.dao.types.NotificationEntity;
12 import org.openecomp.sdc.notification.exceptons.NotificationNotExistException;
13
14 import java.util.UUID;
15
16 import static org.mockito.Matchers.any;
17 import static org.mockito.Mockito.*;
18
19 /**
20  * @author avrahamg
21  * @since July 13, 2017
22  */
23 public class NotificationsServiceImplTest {
24     @Mock
25     private LastNotificationDao lastNotificationDao;
26     @Mock
27     private NotificationsDao notificationsDao;
28     @Spy
29     @InjectMocks
30     private NotificationsServiceImpl notificationsService;
31
32     @Before
33     public void setUp() throws Exception {
34         MockitoAnnotations.initMocks(this);
35     }
36
37     public void shouldCallNotificationsDaoIfNotificationEntityExist() throws Exception {
38         doReturn(new NotificationEntity()).when(notificationsDao).get(any());
39         notificationsService.markAsRead("ownerId", UUID.randomUUID().toString());
40         verify(notificationsDao, times(1)).update(any());
41     }
42
43     @Test(expected = NotificationNotExistException.class)
44     public void shouldThrowExceptionIfOwnerIdAndNotificationIdDontRelate() throws Exception {
45         doReturn(null).when(notificationsDao).get(any());
46         notificationsService.markAsRead("ownerId", UUID.randomUUID().toString());
47     }
48 }