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

File UserProfileNotificationPreferenceProviderTest.java

 

Code metrics

0
14
4
1
92
55
4
0.29
3.5
4
1

Classes

Class Line # Actions
UserProfileNotificationPreferenceProviderTest 46 14 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

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;
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.model.reference.DocumentReference;
29    import org.xwiki.notifications.preferences.TargetableNotificationPreference;
30    import org.xwiki.test.mockito.MockitoComponentMockingRule;
31   
32    import static org.junit.Assert.assertEquals;
33    import static org.mockito.ArgumentMatchers.any;
34    import static org.mockito.ArgumentMatchers.eq;
35    import static org.mockito.Mockito.mock;
36    import static org.mockito.Mockito.times;
37    import static org.mockito.Mockito.verify;
38    import static org.mockito.Mockito.when;
39   
40    /**
41    * Unit tests for {@link UserProfileNotificationPreferenceProvider}.
42    *
43    * @version $Id: e54888d3db62fd0d661d176cbb78cdd40d7585b3 $
44    * @since 9.7RC1
45    */
 
46    public class UserProfileNotificationPreferenceProviderTest
47    {
48    @Rule
49    public final MockitoComponentMockingRule<UserProfileNotificationPreferenceProvider> mocker =
50    new MockitoComponentMockingRule<>(UserProfileNotificationPreferenceProvider.class);
51   
52    private ModelBridge cachedModelBridge;
53   
 
54  3 toggle @Before
55    public void setUp() throws Exception
56    {
57  3 cachedModelBridge = mocker.registerMockComponent(ModelBridge.class, "cached");
58    }
59   
 
60  1 toggle @Test
61    public void providerName() throws Exception
62    {
63  1 assertEquals("userProfile", UserProfileNotificationPreferenceProvider.NAME);
64    }
65   
 
66  1 toggle @Test
67    public void getProviderPriority() throws Exception
68    {
69  1 assertEquals(500, mocker.getComponentUnderTest().getProviderPriority());
70    }
71   
 
72  1 toggle @Test
73    public void savePreferencesWithTargetable() throws Exception
74    {
75  1 DocumentReference userReference = new DocumentReference("wiki", "space", "user");
76  1 DocumentReference userReference2 = new DocumentReference("wiki", "space", "user2");
77   
78  1 TargetableNotificationPreference pref1 = mock(TargetableNotificationPreference.class);
79  1 when(pref1.getTarget()).thenReturn(userReference);
80  1 TargetableNotificationPreference pref2 = mock(TargetableNotificationPreference.class);
81  1 when(pref2.getTarget()).thenReturn(userReference);
82  1 TargetableNotificationPreference pref3 = mock(TargetableNotificationPreference.class);
83  1 when(pref3.getTarget()).thenReturn(userReference2);
84   
85  1 mocker.getComponentUnderTest().savePreferences(Arrays.asList(pref1, pref2, pref3));
86   
87  1 verify(cachedModelBridge, times(1)).saveNotificationsPreferences(eq(userReference),
88    any(List.class));
89  1 verify(cachedModelBridge, times(1)).saveNotificationsPreferences(eq(userReference2),
90    any(List.class));
91    }
92    }