1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.component.wiki

File WikiObjectComponentManagerEventListenerProxyTest.java

 

Code metrics

0
24
5
1
132
83
5
0.21
4.8
5
1

Classes

Class Line # Actions
WikiObjectComponentManagerEventListenerProxyTest 58 24 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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.component.wiki;
21   
22    import java.util.Arrays;
23   
24    import javax.inject.Named;
25   
26    import org.junit.jupiter.api.Test;
27    import org.xwiki.component.manager.ComponentManager;
28    import org.xwiki.component.wiki.internal.WikiComponentManagerEventListenerHelper;
29    import org.xwiki.component.wiki.internal.bridge.WikiBaseObjectComponentBuilder;
30    import org.xwiki.component.wiki.internal.bridge.WikiObjectComponentManagerEventListenerProxy;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.model.reference.ObjectReference;
33    import org.xwiki.query.QueryManager;
34    import org.xwiki.test.junit5.mockito.ComponentTest;
35    import org.xwiki.test.junit5.mockito.InjectMockComponents;
36    import org.xwiki.test.junit5.mockito.MockComponent;
37   
38    import com.xpn.xwiki.doc.XWikiDocument;
39    import com.xpn.xwiki.objects.BaseObject;
40    import com.xpn.xwiki.objects.BaseObjectReference;
41    import com.xpn.xwiki.test.reference.ReferenceComponentList;
42   
43    import static org.junit.Assert.assertEquals;
44    import static org.mockito.ArgumentMatchers.any;
45    import static org.mockito.Mockito.mock;
46    import static org.mockito.Mockito.times;
47    import static org.mockito.Mockito.verify;
48    import static org.mockito.Mockito.when;
49   
50    /**
51    * Unit tests for {@link WikiObjectComponentManagerEventListenerProxy}.
52    *
53    * @version $Id: 4e0d4129e76bb1d23ec1e2b43bdcccd99a0234b3 $
54    * @since 9.5RC1
55    */
56    @ComponentTest
57    @ReferenceComponentList
 
58    public class WikiObjectComponentManagerEventListenerProxyTest
59    {
60    @MockComponent
61    @Named("context")
62    private ComponentManager componentManager;
63   
64    @MockComponent
65    private WikiComponentManagerEventListenerHelper wikiComponentManagerEventListenerHelper;
66   
67    @MockComponent
68    private QueryManager queryManager;
69   
70    @InjectMockComponents
71    private WikiObjectComponentManagerEventListenerProxy listenerProxy;
72   
 
73  1 toggle @Test
74    public void testWikiObjectListCollection() throws Exception
75    {
76  1 WikiObjectComponentBuilder builder1 = mock(WikiObjectComponentBuilder.class);
77  1 WikiObjectComponentBuilder builder2 = mock(WikiObjectComponentBuilder.class);
78   
79  1 ObjectReference builder1Reference = new ObjectReference("builder1", mock(DocumentReference.class));
80  1 ObjectReference builder2Reference = new ObjectReference("builder2", mock(DocumentReference.class));
81   
82  1 when(builder1.getClassReference()).thenReturn(builder1Reference);
83  1 when(builder2.getClassReference()).thenReturn(builder2Reference);
84   
85  1 when(this.componentManager.getInstanceList(WikiObjectComponentBuilder.class))
86    .thenReturn(Arrays.asList(builder1, builder2));
87   
88  1 assertEquals(2, this.listenerProxy.getWikiObjectsList().size());
89    }
90   
 
91  1 toggle @Test
92    public void testRegisterObjectComponentsWithStandardComponentBuilder() throws Exception
93    {
94  1 BaseObjectReference objectReference = mock(BaseObjectReference.class);
95  1 XWikiDocument source = mock(XWikiDocument.class);
96  1 WikiObjectComponentBuilder componentBuilder = mock(WikiObjectComponentBuilder.class);
97   
98  1 this.testWithWikiObjectComponentBuilder(componentBuilder, objectReference, source);
99   
100  1 verify(componentBuilder, times(1)).buildComponents(objectReference);
101    }
102   
 
103  1 toggle @Test
104    public void testRegisterObjectComponentsWithBaseObjectComponentBuilder() throws Exception
105    {
106  1 BaseObjectReference objectReference = mock(BaseObjectReference.class);
107  1 XWikiDocument source = mock(XWikiDocument.class);
108  1 WikiBaseObjectComponentBuilder componentBuilder = mock(WikiBaseObjectComponentBuilder.class);
109   
110  1 this.testWithWikiObjectComponentBuilder(componentBuilder, objectReference, source);
111   
112  1 verify(componentBuilder, times(1)).buildComponents(any(BaseObject.class));
113    }
114   
 
115  1 toggle @Test
116    public void testUnregisterObjectComponents() throws Exception
117    {
118  1 ObjectReference testReference = mock(ObjectReference.class);
119  1 this.listenerProxy.unregisterObjectComponents(testReference);
120   
121  1 verify(this.wikiComponentManagerEventListenerHelper, times(1)).unregisterComponents(testReference);
122    }
123   
 
124  2 toggle private void testWithWikiObjectComponentBuilder(WikiObjectComponentBuilder buider,
125    BaseObjectReference objectReference, XWikiDocument source) throws Exception
126    {
127  2 BaseObject baseObject = mock(BaseObject.class);
128  2 when(source.getXObject(any(ObjectReference.class))).thenReturn(baseObject);
129   
130  2 this.listenerProxy.registerObjectComponents(objectReference, baseObject, buider);
131    }
132    }