Skip to content
Snippets Groups Projects
Commit 3c23fa07 authored by Simon Urli's avatar Simon Urli
Browse files

Fix pseudo-tested methods

parent 1394fd9a
No related branches found
No related tags found
No related merge requests found
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Default implementation of the Resource API and some default Resources</description> <description>Default implementation of the Resource API and some default Resources</description>
<properties> <properties>
<xwiki.jacoco.instructionRatio>0.73</xwiki.jacoco.instructionRatio> <xwiki.jacoco.instructionRatio>0.76</xwiki.jacoco.instructionRatio>
<xwiki.pitest.mutationThreshold>62</xwiki.pitest.mutationThreshold> <xwiki.pitest.mutationThreshold>70</xwiki.pitest.mutationThreshold>
<!-- Name to display by the Extension Manager --> <!-- Name to display by the Extension Manager -->
<xwiki.extension.name>Default Resource Implementation</xwiki.extension.name> <xwiki.extension.name>Default Resource Implementation</xwiki.extension.name>
</properties> </properties>
......
...@@ -71,22 +71,28 @@ public class DefaultEntityResourceActionLister implements EntityResourceActionLi ...@@ -71,22 +71,28 @@ public class DefaultEntityResourceActionLister implements EntityResourceActionLi
@Named("context") @Named("context")
private Provider<ComponentManager> contextComponentManagerProvider; private Provider<ComponentManager> contextComponentManagerProvider;
@Override protected SAXBuilder createSAXBuilder()
public void initialize() throws InitializationException
{ {
// Parse the Struts config file (struts-config.xml) to extract all available actions
List<String> actionNames = new ArrayList<>();
SAXBuilder builder = new SAXBuilder(); SAXBuilder builder = new SAXBuilder();
// Make sure we don't require an Internet Connection to parse the Struts config file! // Make sure we don't require an Internet Connection to parse the Struts config file!
builder.setEntityResolver(new EntityResolver() { builder.setEntityResolver(new EntityResolver() {
@Override public InputSource resolveEntity(String publicId, String systemId) @Override public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException throws SAXException, IOException
{ {
return new InputSource(new StringReader("")); return new InputSource(new StringReader(""));
} }
}); });
return builder;
}
@Override
public void initialize() throws InitializationException
{
// Parse the Struts config file (struts-config.xml) to extract all available actions
List<String> actionNames = new ArrayList<>();
// Step 1: Get a stream on the Struts config file if it exists // Step 1: Get a stream on the Struts config file if it exists
InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource()); InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
...@@ -94,7 +100,7 @@ public void initialize() throws InitializationException ...@@ -94,7 +100,7 @@ public void initialize() throws InitializationException
// Step 2: Parse the Strust config file, looking for action names // Step 2: Parse the Strust config file, looking for action names
Document document; Document document;
try { try {
document = builder.build(strutsConfigStream); document = createSAXBuilder().build(strutsConfigStream);
} catch (JDOMException | IOException e) { } catch (JDOMException | IOException e) {
throw new InitializationException( throw new InitializationException(
String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e); String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
import org.xwiki.test.junit5.mockito.InjectMockComponents; import org.xwiki.test.junit5.mockito.InjectMockComponents;
import org.xwiki.test.mockito.MockitoComponentMockingRule; import org.xwiki.test.mockito.MockitoComponentMockingRule;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same; import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -47,7 +49,7 @@ ...@@ -47,7 +49,7 @@
public class MainResourceReferenceHandlerManagerTest public class MainResourceReferenceHandlerManagerTest
{ {
@InjectMockComponents @InjectMockComponents
public MainResourceReferenceHandlerManager handlerManager; private MainResourceReferenceHandlerManager handlerManager;
@Test @Test
public void handleWithOrder(ComponentManager componentManager) throws Exception public void handleWithOrder(ComponentManager componentManager) throws Exception
...@@ -75,4 +77,22 @@ public void handleWithOrder(ComponentManager componentManager) throws Exception ...@@ -75,4 +77,22 @@ public void handleWithOrder(ComponentManager componentManager) throws Exception
// Verify that the second Action is called (since it has a higher priority). // Verify that the second Action is called (since it has a higher priority).
verify(beforeTestHandler).handle(same(reference), any(ResourceReferenceHandlerChain.class)); verify(beforeTestHandler).handle(same(reference), any(ResourceReferenceHandlerChain.class));
} }
@Test
public void matches()
{
ResourceReferenceHandler resourceReferenceHandler1 = mock(ResourceReferenceHandler.class);
ResourceReferenceHandler resourceReferenceHandler2 = mock(ResourceReferenceHandler.class);
ResourceType resourceType1 = new ResourceType("test1");
ResourceType resourceType2 = new ResourceType("test2");
when(resourceReferenceHandler1.getSupportedResourceReferences()).thenReturn(Arrays.asList(resourceType1));
when(resourceReferenceHandler2.getSupportedResourceReferences()).thenReturn(Arrays.asList(resourceType1, resourceType2));
assertTrue(handlerManager.matches(resourceReferenceHandler1, resourceType1));
assertFalse(handlerManager.matches(resourceReferenceHandler1, resourceType2));
assertTrue(handlerManager.matches(resourceReferenceHandler2, resourceType1));
assertTrue(handlerManager.matches(resourceReferenceHandler2, resourceType2));
}
} }
...@@ -19,11 +19,18 @@ ...@@ -19,11 +19,18 @@
*/ */
package org.xwiki.resource.internal.entity; package org.xwiki.resource.internal.entity;
import java.io.IOException;
import java.io.StringReader;
import javax.inject.Provider; import javax.inject.Provider;
import org.jdom2.input.SAXBuilder;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.manager.ComponentManager;
import org.xwiki.component.util.DefaultParameterizedType; import org.xwiki.component.util.DefaultParameterizedType;
import org.xwiki.environment.Environment; import org.xwiki.environment.Environment;
...@@ -31,6 +38,8 @@ ...@@ -31,6 +38,8 @@
import org.xwiki.resource.entity.EntityResourceAction; import org.xwiki.resource.entity.EntityResourceAction;
import org.xwiki.test.mockito.MockitoComponentMockingRule; import org.xwiki.test.mockito.MockitoComponentMockingRule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.hasItems;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
...@@ -67,4 +76,11 @@ public void listActions() throws Exception ...@@ -67,4 +76,11 @@ public void listActions() throws Exception
assertThat(this.mocker.getComponentUnderTest().listActions(), hasItems("view", "edit", "get", "testaction")); assertThat(this.mocker.getComponentUnderTest().listActions(), hasItems("view", "edit", "get", "testaction"));
} }
@Test
public void createSAXBuilder() throws Exception
{
SAXBuilder saxBuilder = this.mocker.getComponentUnderTest().createSAXBuilder();
assertNotNull(saxBuilder.getEntityResolver().resolveEntity("foo", "bar"));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment