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.macro.chart; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
28 |
|
import org.xwiki.environment.Environment; |
29 |
|
import org.xwiki.model.ModelContext; |
30 |
|
import org.xwiki.model.reference.DocumentReference; |
31 |
|
import org.xwiki.model.reference.WikiReference; |
32 |
|
import org.xwiki.rendering.macro.chart.ChartMacroParameters; |
33 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
34 |
|
|
35 |
|
import static org.mockito.Mockito.when; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
43 |
|
public class TemporaryChartImageWriterTest |
44 |
|
{ |
45 |
|
@Rule |
46 |
|
public MockitoComponentMockingRule<TemporaryChartImageWriter> componentManager = |
47 |
|
new MockitoComponentMockingRule<TemporaryChartImageWriter>(TemporaryChartImageWriter.class); |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
49 |
1 |
@Test... |
50 |
|
public void getStorageLocation() throws Exception |
51 |
|
{ |
52 |
1 |
WikiReference currentWikiReference = new WikiReference("wiki"); |
53 |
1 |
ModelContext modelContext = this.componentManager.getInstance(ModelContext.class); |
54 |
1 |
when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference); |
55 |
|
|
56 |
1 |
Environment environment = this.componentManager.getInstance(Environment.class); |
57 |
1 |
when(environment.getTemporaryDirectory()).thenReturn(new File("/tmpdir")); |
58 |
|
|
59 |
1 |
File location = this.componentManager.getComponentUnderTest().getStorageLocation( |
60 |
|
new ImageId(new ChartMacroParameters())); |
61 |
1 |
Assert.assertTrue("Got: " + location.toString(), |
62 |
|
location.toString().matches("/tmpdir/temp/chart/wiki/space/page/.*\\.png")); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
65 |
1 |
@Test... |
66 |
|
public void getURL() throws Exception |
67 |
|
{ |
68 |
1 |
WikiReference currentWikiReference = new WikiReference("wiki"); |
69 |
1 |
ModelContext modelContext = this.componentManager.getInstance(ModelContext.class); |
70 |
1 |
when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference); |
71 |
|
|
72 |
1 |
DocumentAccessBridge dab = this.componentManager.getInstance(DocumentAccessBridge.class); |
73 |
1 |
when(dab.getDocumentURL(new DocumentReference("wiki", "space", "page"), "temp", null, null)).thenReturn( |
74 |
|
"temp/Space/Page"); |
75 |
|
|
76 |
1 |
String location = this.componentManager.getComponentUnderTest().getURL(new ImageId(new ChartMacroParameters())); |
77 |
1 |
Assert.assertTrue("Got: " + location, location.toString().matches("temp/Space/Page/chart/.*\\.png")); |
78 |
|
} |
79 |
|
} |