1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.transformation.macro; |
21 |
|
|
22 |
|
import static org.mockito.Mockito.*; |
23 |
|
|
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.Collections; |
26 |
|
|
27 |
|
import org.junit.Assert; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.xwiki.model.EntityType; |
31 |
|
import org.xwiki.model.reference.AttachmentReference; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.model.reference.EntityReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
35 |
|
import org.xwiki.rendering.block.Block; |
36 |
|
import org.xwiki.rendering.block.MetaDataBlock; |
37 |
|
import org.xwiki.rendering.block.WordBlock; |
38 |
|
import org.xwiki.rendering.block.XDOM; |
39 |
|
import org.xwiki.rendering.listener.MetaData; |
40 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
41 |
|
|
42 |
|
|
43 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
|
|
| 92.3% |
Uncovered Elements: 2 (26) |
Complexity: 6 |
Complexity Density: 0.27 |
|
48 |
|
public class CurrentMacroEntityReferenceResolverTest |
49 |
|
{ |
50 |
|
@Rule |
51 |
|
public MockitoComponentMockingRule<EntityReferenceResolver<String>> mocker = |
52 |
|
new MockitoComponentMockingRule<EntityReferenceResolver<String>>(CurrentMacroEntityReferenceResolver.class); |
53 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void resolveWhenNoBlockPassed() throws Exception |
56 |
|
{ |
57 |
1 |
try { |
58 |
1 |
mocker.getComponentUnderTest().resolve("something", EntityType.DOCUMENT); |
59 |
0 |
Assert.fail("Should have thrown an IllegalArgumentException here"); |
60 |
|
} catch (IllegalArgumentException expected) { |
61 |
1 |
Assert.assertEquals("You must pass one parameter of type [org.xwiki.rendering.block.Block]", |
62 |
|
expected.getMessage()); |
63 |
|
} |
64 |
|
} |
65 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
public void resolveWhenWrongParameterPassed() throws Exception |
68 |
|
{ |
69 |
1 |
try { |
70 |
1 |
mocker.getComponentUnderTest() |
71 |
|
.resolve("something", EntityType.ATTACHMENT, "wrong param type must be Block"); |
72 |
0 |
Assert.fail("Should have thrown an IllegalArgumentException here"); |
73 |
|
} catch (IllegalArgumentException expected) { |
74 |
1 |
Assert.assertEquals("You must pass one parameter of type [org.xwiki.rendering.block.Block]", |
75 |
|
expected.getMessage()); |
76 |
|
} |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
79 |
1 |
@Test... |
80 |
|
public void resolveWhenNoMetaDataBlock() throws Exception |
81 |
|
{ |
82 |
1 |
EntityReference expectedReference = new DocumentReference("wiki", "Space", "Page"); |
83 |
1 |
EntityReferenceResolver<String> currentEntityReferenceResolver = |
84 |
|
mocker.getInstance(EntityReferenceResolver.TYPE_STRING, "current"); |
85 |
1 |
when(currentEntityReferenceResolver.resolve("Space.Page", EntityType.DOCUMENT)).thenReturn(expectedReference); |
86 |
|
|
87 |
1 |
Block block = new WordBlock("whatever"); |
88 |
1 |
Assert.assertEquals(expectedReference, |
89 |
|
mocker.getComponentUnderTest().resolve("Space.Page", EntityType.DOCUMENT, block)); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
92 |
1 |
@Test... |
93 |
|
public void resolveWhenMetaDataBlock() throws Exception |
94 |
|
{ |
95 |
1 |
DocumentReference baseReference = new DocumentReference("basewiki", "basespace", "basepage"); |
96 |
1 |
EntityReference expectedReference = new AttachmentReference("file", baseReference); |
97 |
1 |
EntityReferenceResolver<String> currentEntityReferenceResolver = |
98 |
|
mocker.getInstance(EntityReferenceResolver.TYPE_STRING, "current"); |
99 |
1 |
when(currentEntityReferenceResolver.resolve("basewiki:basespace.basepage", EntityType.DOCUMENT)).thenReturn( |
100 |
|
baseReference); |
101 |
1 |
when(currentEntityReferenceResolver.resolve("file", EntityType.ATTACHMENT, baseReference)).thenReturn( |
102 |
|
expectedReference); |
103 |
|
|
104 |
1 |
Block wordBlock = new WordBlock("whatever"); |
105 |
1 |
MetaData metaData = |
106 |
|
new MetaData(Collections.<String, Object> singletonMap(MetaData.BASE, "basewiki:basespace.basepage")); |
107 |
1 |
new XDOM(Arrays.<Block> asList(new MetaDataBlock(Arrays.<Block> asList(wordBlock), metaData))); |
108 |
|
|
109 |
1 |
Assert.assertEquals(expectedReference, |
110 |
|
mocker.getComponentUnderTest().resolve("file", EntityType.ATTACHMENT, wordBlock)); |
111 |
|
} |
112 |
|
} |