| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.display.internal; |
| 21 |
|
|
| 22 |
|
import java.util.Collections; |
| 23 |
|
import java.util.HashMap; |
| 24 |
|
|
| 25 |
|
import org.junit.Assert; |
| 26 |
|
|
| 27 |
|
import org.junit.Rule; |
| 28 |
|
import org.junit.Test; |
| 29 |
|
import org.mockito.Mockito; |
| 30 |
|
import org.mockito.invocation.InvocationOnMock; |
| 31 |
|
import org.mockito.stubbing.Answer; |
| 32 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
| 33 |
|
import org.xwiki.bridge.DocumentModelBridge; |
| 34 |
|
import org.xwiki.context.Execution; |
| 35 |
|
import org.xwiki.context.ExecutionContext; |
| 36 |
|
import org.xwiki.model.reference.DocumentReference; |
| 37 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 38 |
|
import org.xwiki.rendering.block.Block; |
| 39 |
|
import org.xwiki.rendering.block.XDOM; |
| 40 |
|
import org.xwiki.rendering.listener.MetaData; |
| 41 |
|
import org.xwiki.rendering.transformation.TransformationContext; |
| 42 |
|
import org.xwiki.rendering.transformation.TransformationManager; |
| 43 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@link |
| 47 |
|
|
| 48 |
|
@version |
| 49 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 2 |
Complexity Density: 0.11 |
|
| 50 |
|
public class DocumentContentDisplayerTest |
| 51 |
|
{ |
| 52 |
|
@Rule |
| 53 |
|
public final MockitoComponentMockingRule<DocumentDisplayer> mocker = |
| 54 |
|
new MockitoComponentMockingRule<DocumentDisplayer>(DocumentContentDisplayer.class); |
| 55 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
| 56 |
1 |
@Test... |
| 57 |
|
public void testBaseMetaDataIsSetBeforeExecutingTransformations() throws Exception |
| 58 |
|
{ |
| 59 |
|
|
| 60 |
1 |
Execution mockExecution = mocker.getInstance(Execution.class); |
| 61 |
1 |
ExecutionContext executionContext = new ExecutionContext(); |
| 62 |
1 |
executionContext.setProperty("xwikicontext", new HashMap<String, Object>()); |
| 63 |
1 |
Mockito.when(mockExecution.getContext()).thenReturn(executionContext); |
| 64 |
|
|
| 65 |
|
|
| 66 |
1 |
DocumentModelBridge mockDocument = Mockito.mock(DocumentModelBridge.class); |
| 67 |
1 |
XDOM content = new XDOM(Collections.<Block> emptyList()); |
| 68 |
1 |
Mockito.when(mockDocument.getXDOM()).thenReturn(content); |
| 69 |
|
|
| 70 |
|
|
| 71 |
1 |
DocumentReference currentDocRef = new DocumentReference("wiki", "Space", "Page"); |
| 72 |
1 |
DocumentAccessBridge mockDocumentAccessBridge = mocker.getInstance(DocumentAccessBridge.class); |
| 73 |
1 |
Mockito.when(mockDocumentAccessBridge.getCurrentDocumentReference()).thenReturn(currentDocRef); |
| 74 |
|
|
| 75 |
1 |
EntityReferenceSerializer<String> serializer = mocker.getInstance(EntityReferenceSerializer.TYPE_STRING); |
| 76 |
1 |
Mockito.when(serializer.serialize(currentDocRef)).thenReturn("foo"); |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
1 |
TransformationManager mockTransformationManager = mocker.getInstance(TransformationManager.class); |
| 81 |
1 |
Mockito.doAnswer(new Answer<Void>() |
| 82 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 83 |
1 |
@Override... |
| 84 |
|
public Void answer(InvocationOnMock invocation) throws Throwable |
| 85 |
|
{ |
| 86 |
1 |
XDOM xdom = (XDOM) invocation.getArguments()[0]; |
| 87 |
|
|
| 88 |
1 |
Assert.assertEquals("foo", xdom.getMetaData().getMetaData(MetaData.BASE)); |
| 89 |
1 |
return null; |
| 90 |
|
} |
| 91 |
|
}).when(mockTransformationManager) |
| 92 |
|
.performTransformations(Mockito.any(XDOM.class), Mockito.any(TransformationContext.class)); |
| 93 |
|
|
| 94 |
|
|
| 95 |
1 |
Assert.assertSame(content, |
| 96 |
|
mocker.getComponentUnderTest().display(mockDocument, new DocumentDisplayerParameters())); |
| 97 |
|
|
| 98 |
|
|
| 99 |
1 |
Mockito.verify(mockTransformationManager, Mockito.times(1)).performTransformations(Mockito.same(content), |
| 100 |
|
Mockito.any(TransformationContext.class)); |
| 101 |
|
} |
| 102 |
|
} |