1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.event

File CommentEventGeneratorListenerTest.java

 

Code metrics

0
23
4
1
131
76
4
0.17
5.75
4
1

Classes

Class Line # Actions
CommentEventGeneratorListenerTest 47 23 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 com.xpn.xwiki.internal.event;
21   
22    import org.junit.Before;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.component.manager.ComponentLookupException;
26    import org.xwiki.model.reference.DocumentReference;
27    import org.xwiki.observation.ObservationManager;
28    import org.xwiki.observation.event.Event;
29    import org.xwiki.test.mockito.MockitoComponentMockingRule;
30   
31    import com.xpn.xwiki.doc.XWikiDocument;
32    import com.xpn.xwiki.objects.BaseObject;
33    import com.xpn.xwiki.objects.classes.BaseClass;
34    import com.xpn.xwiki.test.MockitoOldcoreRule;
35    import com.xpn.xwiki.test.reference.ReferenceComponentList;
36   
37    import static org.mockito.ArgumentMatchers.any;
38    import static org.mockito.ArgumentMatchers.same;
39    import static org.mockito.Mockito.verify;
40   
41    /**
42    * Validate {@link CommentEventGeneratorListener}.
43    *
44    * @version $Id: 9f4df75d0d1d5f6a01c0f07c124d652e597540e4 $
45    */
46    @ReferenceComponentList
 
47    public class CommentEventGeneratorListenerTest
48    {
49    public MockitoComponentMockingRule<CommentEventGeneratorListener> mocker =
50    new MockitoComponentMockingRule<CommentEventGeneratorListener>(CommentEventGeneratorListener.class);
51   
52    @Rule
53    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(mocker);
54   
55    private ObservationManager mockObservation;
56   
57    private XWikiDocument commentXClassDocument;
58   
59    private BaseClass commentXClass;
60   
61    private BaseObject commentXObject;
62   
63    private XWikiDocument document;
64   
65    private XWikiDocument documentOrigin;
66   
 
67  3 toggle @Before
68    public void before() throws Exception
69    {
70  3 this.commentXClassDocument = new XWikiDocument(new DocumentReference("wiki", "XWiki", "XWikiComments"));
71  3 this.commentXClass = this.commentXClassDocument.getXClass();
72  3 this.commentXClass.addTextAreaField("comment", "comment", 60, 20);
73   
74  3 this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
75  3 this.documentOrigin = new XWikiDocument(this.document.getDocumentReference());
76  3 this.document.setOriginalDocument(this.documentOrigin);
77   
78  3 this.commentXObject = new BaseObject();
79  3 this.commentXObject.setXClassReference(this.commentXClass.getDocumentReference());
80   
81  3 this.mockObservation = this.mocker.getInstance(ObservationManager.class);
82    }
83   
 
84  1 toggle @Test
85    public void testAddComment() throws ComponentLookupException
86    {
87  1 this.document.addXObject(this.commentXObject);
88   
89  1 final Event event = new CommentAddedEvent("wiki:space.page", "0");
90   
91  1 this.mocker.getComponentUnderTest().onEvent(new XObjectAddedEvent(this.commentXObject.getReference()), this.document,
92    this.oldcore.getXWikiContext());
93   
94    // Make sure the listener generated a comment added event
95  1 verify(this.mockObservation)
96    .notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext()));
97    }
98   
 
99  1 toggle @Test
100    public void testDeleteComment() throws ComponentLookupException
101    {
102  1 this.documentOrigin.addXObject(this.commentXObject);
103   
104  1 final Event event = new CommentDeletedEvent("wiki:space.page", "0");
105   
106  1 this.mocker.getComponentUnderTest().onEvent(new XObjectDeletedEvent(this.commentXObject.getReference()),
107    this.document, this.oldcore.getXWikiContext());
108   
109    // Make sure the listener generated a comment deleted event
110  1 verify(this.mockObservation)
111    .notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext()));
112    }
113   
 
114  1 toggle @Test
115    public void testModifiedComment() throws ComponentLookupException
116    {
117  1 this.document.addXObject(this.commentXObject);
118  1 this.documentOrigin.addXObject(this.commentXObject.clone());
119   
120  1 this.commentXObject.setStringValue("comment", "comment");
121   
122  1 final Event event = new CommentUpdatedEvent("wiki:space.page", "0");
123   
124  1 this.mocker.getComponentUnderTest().onEvent(new XObjectUpdatedEvent(this.commentXObject.getReference()),
125    this.document, this.oldcore.getXWikiContext());
126   
127    // Make sure the listener generated a comment updated event
128  1 verify(this.mockObservation)
129    .notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext()));
130    }
131    }