1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.notifications.notifiers.internal.email.live

File LiveNotificationEmailSenderTest.java

 

Code metrics

0
16
2
1
112
63
2
0.12
8
2
1

Classes

Class Line # Actions
LiveNotificationEmailSenderTest 52 16 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.notifications.notifiers.internal.email.live;
21   
22    import javax.inject.Provider;
23   
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.mockito.ArgumentMatchers;
28    import org.mockito.Mockito;
29    import org.xwiki.component.util.DefaultParameterizedType;
30    import org.xwiki.mail.MailListener;
31    import org.xwiki.mail.MailSender;
32    import org.xwiki.mail.SessionFactory;
33    import org.xwiki.notifications.CompositeEvent;
34    import org.xwiki.notifications.notifiers.internal.email.NotificationUserIterator;
35    import org.xwiki.notifications.notifiers.internal.email.live.LiveMimeMessageIterator;
36    import org.xwiki.notifications.notifiers.internal.email.live.LiveNotificationEmailSender;
37    import org.xwiki.test.mockito.MockitoComponentMockingRule;
38    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
39   
40    import static org.mockito.ArgumentMatchers.any;
41    import static org.mockito.Mockito.mock;
42    import static org.mockito.Mockito.times;
43    import static org.mockito.Mockito.verify;
44    import static org.mockito.Mockito.when;
45   
46    /**
47    * Unit tests for {@link LiveNotificationEmailSender}.
48    *
49    * @since 9.6RC1
50    * @version $Id: f4cd522161950a6047855536f2600d68bca2b7dd $
51    */
 
52    public class LiveNotificationEmailSenderTest
53    {
54    @Rule
55    public final MockitoComponentMockingRule<LiveNotificationEmailSender> mocker =
56    new MockitoComponentMockingRule<>(LiveNotificationEmailSender.class);
57   
58    private MailSender mailSender;
59   
60    private SessionFactory sessionFactory;
61   
62    private Provider<MailListener> mailListenerProvider;
63   
64    private Provider<NotificationUserIterator> notificationUserIteratorProvider;
65   
66    private Provider<LiveMimeMessageIterator> liveMimeMessageIteratorProvider;
67   
68    private WikiDescriptorManager wikiDescriptorManager;
69   
 
70  1 toggle @Before
71    public void setUp() throws Exception
72    {
73  1 this.mailSender = this.mocker.registerMockComponent(MailSender.class);
74   
75  1 this.sessionFactory = this.mocker.registerMockComponent(SessionFactory.class);
76   
77  1 this.mailListenerProvider = this.mocker.registerMockComponent(Provider.class, "database");
78   
79  1 this.notificationUserIteratorProvider = mock(Provider.class);
80  1 this.mocker.registerComponent(
81    new DefaultParameterizedType(null, Provider.class, NotificationUserIterator.class),
82    this.notificationUserIteratorProvider);
83   
84  1 this.liveMimeMessageIteratorProvider = mock(Provider.class);
85  1 this.mocker.registerComponent(
86    new DefaultParameterizedType(null, Provider.class, LiveMimeMessageIterator.class),
87    this.liveMimeMessageIteratorProvider);
88   
89  1 this.wikiDescriptorManager = this.mocker.registerMockComponent(WikiDescriptorManager.class);
90    }
91   
 
92  1 toggle @Test
93    public void testSendMail() throws Exception
94    {
95  1 CompositeEvent event1 = mock(CompositeEvent.class);
96   
97  1 when(this.wikiDescriptorManager.getCurrentWikiId()).thenReturn("xwiki");
98   
99  1 when(this.notificationUserIteratorProvider.get()).thenReturn(Mockito.mock(NotificationUserIterator.class));
100   
101  1 when(this.liveMimeMessageIteratorProvider.get()).thenReturn(Mockito.mock(LiveMimeMessageIterator.class));
102   
103  1 when(this.sessionFactory.create(ArgumentMatchers.any())).thenReturn(null);
104   
105  1 when(this.mailListenerProvider.get()).thenReturn(Mockito.mock(MailListener.class));
106   
107  1 this.mocker.getComponentUnderTest().sendEmails(event1);
108   
109  1 verify(this.mailSender, times(1)).sendAsynchronously(
110    any(LiveMimeMessageIterator.class), any(), any(MailListener.class));
111    }
112    }