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

File DefaultNotificationEmailUserPreferenceManagerTest.java

 

Code metrics

0
18
3
1
104
61
3
0.17
6
3
1

Classes

Class Line # Actions
DefaultNotificationEmailUserPreferenceManagerTest 44 18 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.preferences.internal.email;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.bridge.DocumentAccessBridge;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.DocumentReferenceResolver;
31    import org.xwiki.notifications.preferences.email.NotificationEmailDiffType;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
34   
35    import static org.junit.Assert.assertEquals;
36    import static org.mockito.Mockito.when;
37   
38    /**
39    * Unit tests for {@link DefaultNotificationEmailUserPreferenceManager}.
40    *
41    * @version $Id: ef146d624d3b418fea12ae878327f5ff81838ef0 $
42    * @since 9.11RC1
43    */
 
44    public class DefaultNotificationEmailUserPreferenceManagerTest
45    {
46    @Rule
47    public final MockitoComponentMockingRule<DefaultNotificationEmailUserPreferenceManager> mocker =
48    new MockitoComponentMockingRule<>(DefaultNotificationEmailUserPreferenceManager.class);
49   
50    private DocumentAccessBridge documentAccessBridge;
51    private DocumentReferenceResolver<String> referenceResolver;
52    private WikiDescriptorManager wikiDescriptorManager;
53    private DocumentReference currentUser;
54   
 
55  1 toggle @Before
56    public void setUp() throws Exception
57    {
58  1 documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
59  1 referenceResolver = mocker.getInstance(DocumentReferenceResolver.TYPE_STRING);
60  1 wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
61   
62  1 when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
63   
64  1 currentUser = new DocumentReference("someWiki", "XWiki", "User");
65  1 when(documentAccessBridge.getCurrentUserReference()).thenReturn(currentUser);
66    }
67   
 
68  4 toggle private List<String> getCodeSpace()
69    {
70  4 return Arrays.asList("XWiki", "Notifications", "Code");
71    }
72   
 
73  1 toggle @Test
74    public void getDiffType() throws Exception
75    {
76    // Default value
77  1 assertEquals(NotificationEmailDiffType.STANDARD, mocker.getComponentUnderTest().getDiffType());
78   
79    // Value from the user profile
80  1 DocumentReference emailClassReference = new DocumentReference("someWiki", Arrays.asList("XWiki",
81    "Notifications", "Code"), "NotificationEmailPreferenceClass");
82  1 when(documentAccessBridge.getProperty(currentUser, emailClassReference, "diffType"))
83    .thenReturn("NOTHING");
84  1 assertEquals(NotificationEmailDiffType.NOTHING, mocker.getComponentUnderTest().getDiffType());
85   
86    // Value from the main wiki config
87  1 DocumentReference user2 = new DocumentReference("someWiki", "XWiki", "User2");
88  1 String user2Id = "someWiki:XWiki.User2";
89  1 when(referenceResolver.resolve(user2Id)).thenReturn(user2);
90  1 when(documentAccessBridge.getProperty(new DocumentReference("mainWiki", getCodeSpace(),
91    "NotificationAdministration"), new DocumentReference("mainWiki",
92    getCodeSpace(), "NotificationEmailPreferenceClass"),
93    "diffType")).thenReturn("NOTHING");
94  1 assertEquals(NotificationEmailDiffType.NOTHING, mocker.getComponentUnderTest().getDiffType(user2Id));
95   
96    // Value from the user's wiki config
97  1 when(documentAccessBridge.getProperty(new DocumentReference("someWiki", getCodeSpace(),
98    "NotificationAdministration"), new DocumentReference("mainWiki",
99    getCodeSpace(), "NotificationEmailPreferenceClass"),
100    "diffType")).thenReturn("NOTHING");
101   
102  1 assertEquals(NotificationEmailDiffType.NOTHING, mocker.getComponentUnderTest().getDiffType(user2Id));
103    }
104    }