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

File TablePieDatasetBuilderTest.java

 

Code metrics

0
24
2
1
91
47
2
0.08
12
2
1

Classes

Class Line # Actions
TablePieDatasetBuilderTest 36 24 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.source.table;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24   
25    import org.jfree.data.general.Dataset;
26    import org.jfree.data.general.PieDataset;
27   
28    import org.xwiki.chart.model.ChartModel;
29   
30    /**
31    * Tests building a pie dataset from a table data source.
32    *
33    * @version $Id: 71a8cbddc2d7484a83191af5055883e1c549ab32 $
34    * @since 4.2M1
35    */
 
36    public class TablePieDatasetBuilderTest extends AbstractMacroContentTableBlockDataSourceTest
37    {
 
38  1 toggle @Test
39    public void testBuildPieDataset() throws Exception
40    {
41  1 String content =
42    "| column 1 | column 2 | column 3 | column 4\n" +
43    "| row 1 | 12 | 13 | 14 \n" +
44    "| row 2 | 22 | 23 | 24 \n";
45  1 setUpContentExpectation(content);
46   
47  1 getDataSource().buildDataset(content, map("type", "pie", "range", "B2-D3"), null);
48   
49  1 ChartModel chartModel = getDataSource().getChartModel();
50   
51  1 Dataset dataset = chartModel.getDataset();
52   
53  1 Assert.assertTrue(dataset instanceof PieDataset);
54   
55  1 PieDataset pieDataset = (PieDataset) dataset;
56   
57  1 Assert.assertTrue(pieDataset.getKey(0).equals(" row 1 "));
58  1 Assert.assertTrue(pieDataset.getKey(1).equals(" row 2 "));
59   
60  1 Assert.assertTrue(pieDataset.getValue(0).intValue() == 12);
61  1 Assert.assertTrue(pieDataset.getValue(1).intValue() == 22);
62    }
63   
 
64  1 toggle @Test
65    public void testBuildPieDatasetRowsSeries() throws Exception
66    {
67  1 String content =
68    "| column 1 | column 2 | column 3 | column 4\n" +
69    "| row 1 | 12 | 13 | 14 \n" +
70    "| row 2 | 22 | 23 | 24 \n";
71  1 setUpContentExpectation(content);
72   
73  1 getDataSource().buildDataset(content, map("type", "pie", "range", "B2-D3", "series", "rows"), null);
74   
75  1 ChartModel chartModel = getDataSource().getChartModel();
76   
77  1 Dataset dataset = chartModel.getDataset();
78   
79  1 Assert.assertTrue(dataset instanceof PieDataset);
80   
81  1 PieDataset pieDataset = (PieDataset) dataset;
82   
83  1 Assert.assertTrue(pieDataset.getKey(0).equals(" column 2 "));
84  1 Assert.assertTrue(pieDataset.getKey(1).equals(" column 3 "));
85  1 Assert.assertTrue(pieDataset.getKey(2).equals(" column 4"));
86   
87  1 Assert.assertTrue(pieDataset.getValue(0).intValue() == 12);
88  1 Assert.assertTrue(pieDataset.getValue(1).intValue() == 13);
89  1 Assert.assertTrue(pieDataset.getValue(2).intValue() == 14);
90    }
91    }