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

File DefaultEntityResourceActionListerTest.java

 

Code metrics

0
8
3
1
86
51
3
0.38
2.67
3
1

Classes

Class Line # Actions
DefaultEntityResourceActionListerTest 53 8 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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.resource.internal.entity;
21   
22    import java.io.IOException;
23    import java.io.StringReader;
24   
25    import javax.inject.Provider;
26   
27    import org.jdom2.input.SAXBuilder;
28    import org.junit.Before;
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.xml.sax.InputSource;
32    import org.xml.sax.SAXException;
33    import org.xwiki.component.manager.ComponentLookupException;
34    import org.xwiki.component.manager.ComponentManager;
35    import org.xwiki.component.util.DefaultParameterizedType;
36    import org.xwiki.environment.Environment;
37    import org.xwiki.resource.ResourceReferenceHandler;
38    import org.xwiki.resource.entity.EntityResourceAction;
39    import org.xwiki.test.mockito.MockitoComponentMockingRule;
40   
41    import static org.junit.Assert.assertEquals;
42    import static org.junit.Assert.assertNotNull;
43    import static org.junit.Assert.assertThat;
44    import static org.hamcrest.CoreMatchers.hasItems;
45    import static org.mockito.Mockito.*;
46   
47    /**
48    * Unit tests for {@link DefaultEntityResourceActionLister}.
49    *
50    * @version $Id: 47b33a2188e5fde09e8a88a4de181742ad3614c6 $
51    * @since 7.2M1
52    */
 
53    public class DefaultEntityResourceActionListerTest
54    {
55    @Rule
56    public MockitoComponentMockingRule<DefaultEntityResourceActionLister> mocker =
57    new MockitoComponentMockingRule<>(DefaultEntityResourceActionLister.class);
58   
 
59  2 toggle @Before
60    public void configure() throws Exception
61    {
62  2 Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(
63    new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
64  2 when(componentManagerProvider.get()).thenReturn(this.mocker);
65    }
66   
 
67  1 toggle @Test
68    public void listActions() throws Exception
69    {
70  1 Environment environment = this.mocker.getInstance(Environment.class);
71  1 when(environment.getResourceAsStream("/WEB-INF/struts-config.xml")).thenReturn(
72    getClass().getClassLoader().getResourceAsStream("WEB-INF/struts-config.xml"));
73   
74  1 this.mocker.registerMockComponent(new DefaultParameterizedType(null, ResourceReferenceHandler.class,
75    EntityResourceAction.class), "testaction");
76   
77  1 assertThat(this.mocker.getComponentUnderTest().listActions(), hasItems("view", "edit", "get", "testaction"));
78    }
79   
 
80  1 toggle @Test
81    public void createSAXBuilder() throws Exception
82    {
83  1 SAXBuilder saxBuilder = this.mocker.getComponentUnderTest().createSAXBuilder();
84  1 assertNotNull(saxBuilder.getEntityResolver().resolveEntity("foo", "bar"));
85    }
86    }