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

File MinorEventAlertNotificationFilterTest.java

 

Code metrics

0
24
6
1
113
83
6
0.25
4
6
1

Classes

Class Line # Actions
MinorEventAlertNotificationFilterTest 42 24 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 6 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.filters.internal;
21   
22    import java.util.Collections;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.eventstream.Event;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.notifications.NotificationFormat;
29    import org.xwiki.notifications.filters.NotificationFilter;
30    import org.xwiki.notifications.filters.NotificationFilterType;
31    import org.xwiki.notifications.filters.internal.minor.MinorEventAlertNotificationFilter;
32    import org.xwiki.notifications.preferences.NotificationPreference;
33    import org.xwiki.test.mockito.MockitoComponentMockingRule;
34   
35    import static org.junit.Assert.assertEquals;
36    import static org.junit.Assert.assertFalse;
37    import static org.junit.Assert.assertNull;
38    import static org.junit.Assert.assertTrue;
39    import static org.mockito.Mockito.mock;
40    import static org.mockito.Mockito.when;
41   
 
42    public class MinorEventAlertNotificationFilterTest
43    {
44    @Rule
45    public final MockitoComponentMockingRule<MinorEventAlertNotificationFilter> mocker =
46    new MockitoComponentMockingRule<>(MinorEventAlertNotificationFilter.class);
47   
 
48  1 toggle @Test
49    public void filterEvent() throws Exception
50    {
51  1 DocumentReference randomUser = new DocumentReference("xwiki", "XWiki", "UserA");
52  1 Event event1 = mock(Event.class);
53  1 Event event2 = mock(Event.class);
54  1 Event event3 = mock(Event.class);
55  1 when(event1.getType()).thenReturn("update");
56  1 when(event1.getDocumentVersion()).thenReturn("2.12");
57  1 when(event2.getType()).thenReturn("addComment");
58  1 when(event2.getDocumentVersion()).thenReturn("2.12");
59  1 when(event3.getType()).thenReturn("update");
60  1 when(event3.getDocumentVersion()).thenReturn("2.1");
61  1 assertEquals(NotificationFilter.FilterPolicy.FILTER,
62    mocker.getComponentUnderTest().filterEvent(event1, randomUser, Collections.emptyList(),
63    NotificationFormat.ALERT));
64  1 assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT,
65    mocker.getComponentUnderTest().filterEvent(event2, randomUser, Collections.emptyList(),
66    NotificationFormat.ALERT));
67  1 assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT,
68    mocker.getComponentUnderTest().filterEvent(event3, randomUser, Collections.emptyList(),
69    NotificationFormat.ALERT));
70    }
71   
 
72  1 toggle @Test
73    public void filterExpression() throws Exception
74    {
75  1 NotificationPreference fakePreference = mock(NotificationPreference.class);
76   
77  1 DocumentReference randomUser = new DocumentReference("xwiki", "XWiki", "UserA");
78  1 assertNull(mocker.getComponentUnderTest().filterExpression(randomUser, Collections.emptyList(), fakePreference));
79  1 assertEquals("NOT ((TYPE = \"update\" AND NOT (DOCUMENT_VERSION ENDS WITH \".1\")))",
80    mocker.getComponentUnderTest().filterExpression(randomUser, Collections.emptyList(),
81    NotificationFilterType.EXCLUSIVE,
82    NotificationFormat.ALERT).toString());
83    }
84   
 
85  1 toggle @Test
86    public void filterExpressionWithWrongParameters() throws Exception
87    {
88  1 DocumentReference randomUser = new DocumentReference("xwiki", "XWiki", "UserA");
89  1 assertNull(mocker.getComponentUnderTest().filterExpression(randomUser, Collections.emptyList(),
90    NotificationFilterType.INCLUSIVE, NotificationFormat.ALERT));
91  1 assertNull(mocker.getComponentUnderTest().filterExpression(randomUser, Collections.emptyList(),
92    NotificationFilterType.EXCLUSIVE, NotificationFormat.EMAIL));
93    }
94   
 
95  1 toggle @Test
96    public void matchesPreference() throws Exception
97    {
98  1 assertFalse(mocker.getComponentUnderTest().matchesPreference(mock(NotificationPreference.class)));
99    }
100   
 
101  1 toggle @Test
102    public void getName() throws Exception
103    {
104  1 assertEquals(MinorEventAlertNotificationFilter.FILTER_NAME, mocker.getComponentUnderTest().getName());
105    }
106   
 
107  1 toggle @Test
108    public void getFormats() throws Exception
109    {
110  1 assertEquals(1, mocker.getComponentUnderTest().getFormats().size());
111  1 assertTrue(mocker.getComponentUnderTest().getFormats().contains(NotificationFormat.ALERT));
112    }
113    }