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

File ContextRootComponentManagerTest.java

 

Code metrics

0
21
2
1
89
48
2
0.1
10.5
2
1

Classes

Class Line # Actions
ContextRootComponentManagerTest 40 21 0% 2 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.component.internal;
21   
22    import static org.mockito.Mockito.verify;
23   
24    import java.lang.reflect.Type;
25   
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.component.descriptor.DefaultComponentDescriptor;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.test.annotation.ComponentList;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    /**
35    * Unit tests for {@link org.xwiki.component.script.ContextRootComponentManager}.
36    *
37    * @version $Id: 45af78046466ee5982608f9c103584d151f10c7e $
38    */
39    @ComponentList(ContextComponentManagerProvider.class)
 
40    public class ContextRootComponentManagerTest
41    {
42    @Rule
43    public MockitoComponentMockingRule<ComponentManager> mocker = new MockitoComponentMockingRule<ComponentManager>(
44    ContextRootComponentManager.class);
45   
46    /**
47    * The mock component manager used by the script service under test.
48    */
49    private ComponentManager contextComponentManager;
50   
51    private ComponentManager rootComponentManager;
52   
 
53  1 toggle @Before
54    public void before() throws Exception
55    {
56  1 this.contextComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context");
57  1 this.rootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "root");
58    }
59   
 
60  1 toggle @Test
61    public void test() throws Exception
62    {
63  1 this.mocker.getComponentUnderTest().getInstance(Type.class);
64  1 this.mocker.getComponentUnderTest().getInstance(Type.class, "hint");
65  1 this.mocker.getComponentUnderTest().getComponentDescriptor(Type.class, "hint");
66  1 this.mocker.getComponentUnderTest().getComponentDescriptorList(Type.class);
67  1 this.mocker.getComponentUnderTest().getComponentDescriptorList((Type)Type.class);
68  1 this.mocker.getComponentUnderTest().getInstanceList(Type.class);
69  1 this.mocker.getComponentUnderTest().getInstanceMap(Type.class);
70   
71  1 DefaultComponentDescriptor<Type> descriptor = new DefaultComponentDescriptor<>();
72  1 this.mocker.getComponentUnderTest().registerComponent(descriptor);
73  1 this.mocker.getComponentUnderTest().registerComponent(descriptor, Type.class);
74   
75    // Verify
76   
77  1 verify(contextComponentManager).getInstance(Type.class);
78  1 verify(contextComponentManager).getInstance(Type.class, "hint");
79  1 verify(contextComponentManager).getComponentDescriptor(Type.class, "hint");
80  1 verify(contextComponentManager).getComponentDescriptorList(Type.class);
81  1 verify(contextComponentManager).getComponentDescriptorList((Type)Type.class);
82  1 verify(contextComponentManager).getInstanceList(Type.class);
83  1 verify(contextComponentManager).getInstanceMap(Type.class);
84   
85  1 verify(rootComponentManager).registerComponent(descriptor);
86  1 verify(rootComponentManager).registerComponent(descriptor, Type.class);
87    }
88   
89    }