1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.macro.chart

File TemporaryChartImageWriterTest.java

 

Code metrics

0
14
2
1
79
44
2
0.14
7
2
1

Classes

Class Line # Actions
TemporaryChartImageWriterTest 43 14 0% 2 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.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    * Unit tests for {@link TemporaryChartImageWriter}.
39    *
40    * @version $Id: 6a03430859a0fe9ec454e4ecf6b7edb248d26ecf $
41    * @since 4.2M3
42    */
 
43    public class TemporaryChartImageWriterTest
44    {
45    @Rule
46    public MockitoComponentMockingRule<TemporaryChartImageWriter> componentManager =
47    new MockitoComponentMockingRule<TemporaryChartImageWriter>(TemporaryChartImageWriter.class);
48   
 
49  1 toggle @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   
 
65  1 toggle @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    }