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

File DefaultNotificationRSSRendererTest.java

 

Code metrics

0
22
3
1
113
66
3
0.14
7.33
3
1

Classes

Class Line # Actions
DefaultNotificationRSSRendererTest 55 22 0% 3 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.internal.rss;
21   
22    import java.util.Arrays;
23    import java.util.Date;
24    import java.util.HashSet;
25   
26    import javax.script.ScriptContext;
27   
28    import org.junit.Before;
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.mockito.ArgumentMatchers;
32    import org.mockito.Mockito;
33    import org.xwiki.eventstream.Event;
34    import org.xwiki.localization.ContextualLocalizationManager;
35    import org.xwiki.model.reference.DocumentReference;
36    import org.xwiki.notifications.CompositeEvent;
37    import org.xwiki.notifications.notifiers.internal.rss.DefaultNotificationRSSRenderer;
38    import org.xwiki.script.ScriptContextManager;
39    import org.xwiki.template.Template;
40    import org.xwiki.template.TemplateManager;
41    import org.xwiki.test.mockito.MockitoComponentMockingRule;
42   
43    import com.rometools.rome.feed.synd.SyndEntry;
44   
45    import static org.junit.Assert.assertEquals;
46    import static org.mockito.Mockito.mock;
47    import static org.mockito.Mockito.when;
48   
49    /**
50    * Unit tests for {@link DefaultNotificationRSSRenderer}.
51    *
52    * @version $Id: 64ad7e6730f8b7b6cfaa651e73c796476a2dae6d $
53    * @since 9.6RC1
54    */
 
55    public class DefaultNotificationRSSRendererTest
56    {
57    @Rule
58    public final MockitoComponentMockingRule<DefaultNotificationRSSRenderer> mocker =
59    new MockitoComponentMockingRule<>(DefaultNotificationRSSRenderer.class);
60   
61    private ContextualLocalizationManager contextualLocalizationManager;
62   
63    private TemplateManager templateManager;
64   
65    private ScriptContextManager scriptContextManager;
66   
 
67  1 toggle @Before
68    public void setUp() throws Exception
69    {
70  1 this.contextualLocalizationManager = this.mocker.registerMockComponent(ContextualLocalizationManager.class);
71   
72  1 this.templateManager = this.mocker.registerMockComponent(TemplateManager.class);
73   
74  1 this.scriptContextManager = this.mocker.registerMockComponent(ScriptContextManager.class);
75    }
76   
 
77  1 toggle private void mockEvent(CompositeEvent testCompositeEvent) throws Exception
78    {
79  1 Event testEvent1 = mock(Event.class);
80  1 Date testEventDate = mock(Date.class);
81  1 when(testEvent1.getTitle()).thenReturn("EventTitle");
82  1 when(testEvent1.getDocumentTitle()).thenReturn("EventDocumentTitle");
83  1 when(this.contextualLocalizationManager.getTranslationPlain("EventTitle", "EventDocumentTitle"))
84    .thenReturn("TranslatedEventTitle");
85   
86  1 DocumentReference testEventAuthor1 = new DocumentReference("xwiki", "XWiki", "AuthorName");
87   
88  1 when(this.templateManager.getTemplate(ArgumentMatchers.any())).thenReturn(Mockito.mock(Template.class));
89   
90  1 when(testCompositeEvent.getEvents()).thenReturn(Arrays.asList(testEvent1));
91  1 when(testCompositeEvent.getUsers()).thenReturn(new HashSet<>(Arrays.asList(testEventAuthor1)));
92  1 when(testCompositeEvent.getEventIds()).thenReturn(Arrays.asList("id1"));
93  1 when(testCompositeEvent.getType()).thenReturn("eventType");
94  1 when(testCompositeEvent.getDates()).thenReturn(Arrays.asList(testEventDate));
95   
96    }
97   
 
98  1 toggle @Test
99    public void testCompositeEventRendering() throws Exception
100    {
101  1 CompositeEvent testCompositeEvent = mock(CompositeEvent.class);
102   
103  1 this.mockEvent(testCompositeEvent);
104   
105  1 when(this.scriptContextManager.getCurrentScriptContext()).thenReturn(Mockito.mock(ScriptContext.class));
106   
107  1 SyndEntry resultEntry = this.mocker.getComponentUnderTest().renderNotification(testCompositeEvent);
108   
109  1 assertEquals("TranslatedEventTitle", resultEntry.getTitle());
110  1 assertEquals(1, resultEntry.getAuthors().size());
111  1 assertEquals("id1", resultEntry.getUri());
112    }
113    }