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

File ResultExtractor.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

10
32
5
1
143
71
10
0.31
6.4
5
2

Classes

Class Line # Actions
ResultExtractor 39 32 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 4 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.ctsreport;
21   
22    import java.util.ArrayList;
23    import java.util.HashMap;
24    import java.util.Iterator;
25    import java.util.List;
26    import java.util.Map;
27    import java.util.Set;
28    import java.util.TreeSet;
29   
30    import org.apache.commons.lang3.tuple.ImmutablePair;
31    import org.apache.commons.lang3.tuple.Pair;
32   
33    /**
34    * Extracts Data structures from a List of {@link Result} objects (which corresponds to parsed JUnit test result).
35    *
36    * @version $Id: 3f934d474fda7bd052644c98b0e9af3b102f415b $
37    * @since 4.1M2
38    */
 
39    public class ResultExtractor
40    {
41    /**
42    * @param results the list of {@link Result} objects from which to extract the test names
43    * @return the test names (eg "simple/bold/bold1")
44    */
 
45  3 toggle public Set<String> extractByTestName(List<Result> results)
46    {
47  3 Set<String> testNames = new TreeSet<String>();
48  3 for (Result result : results) {
49  12 testNames.add(result.test.prefix);
50    }
51  3 return testNames;
52    }
53   
54    /**
55    * @param results the list of {@link Result} objects from which to extract the test names
56    * @return a data structure providing test results by syntax. The returned Map's keys are syntax ids, the values
57    * are Pairs of input (left items of the pair) and output tests (right items of the pair)
58    */
 
59  3 toggle public Map<String, Pair<Set<Test>, Set<Test>>> extractBySyntax(List<Result> results)
60    {
61  3 Map<String, Pair<Set<Test>, Set<Test>>> tests = new HashMap<String, Pair<Set<Test>, Set<Test>>>();
62   
63  3 for (Result result : results) {
64   
65    // Is there already an entry for the syntax?
66  12 Pair<Set<Test>, Set<Test>> inOutTests = tests.get(result.syntaxId);
67  12 if (inOutTests == null) {
68  6 inOutTests = new ImmutablePair<Set<Test>, Set<Test>>(
69    new TreeSet<Test>(), new TreeSet<Test>());
70  6 tests.put(result.syntaxId, inOutTests);
71    }
72   
73    // Get the list of Test for the result type (In or Out)
74  12 Set<Test> typeTests;
75  12 if (result.isSyntaxInputTest) {
76  9 typeTests = inOutTests.getLeft();
77    } else {
78  3 typeTests = inOutTests.getRight();
79    }
80   
81    // Add the result as a Test object
82  12 typeTests.add(result.test);
83    }
84   
85    // Sort the Map to order by prefix
86  3 return tests;
87    }
88   
89    /**
90    * Add not applicable tests for all syntaxes.
91    *
92    * @param testNames the test names (eg "simple/bold/bold1")
93    * @param tests the tests by syntaxes
94    */
 
95  2 toggle public void normalize(Set<String> testNames, Map<String, Pair<Set<Test>, Set<Test>>> tests)
96    {
97  2 for (Pair<Set<Test>, Set<Test>> inOutTests : tests.values()) {
98  4 addNotApplicableTests(testNames, inOutTests.getLeft());
99  4 addNotApplicableTests(testNames, inOutTests.getRight());
100    }
101    }
102   
103    /**
104    * Add not applicable tests for all syntaxes, for input or output tests.
105    *
106    * @param testNames the test names (eg "simple/bold/bold1")
107    * @param tests the tests by syntaxes
108    */
 
109  8 toggle private void addNotApplicableTests(Set<String> testNames, Set<Test> tests)
110    {
111  8 List<String> inTestNames = extractTestNames(tests);
112   
113    // We only add "not applicable" tests if there's at least one test since otherwise we consider that
114    // there's no Parser or Renderer for the syntax.
115  8 if (!inTestNames.isEmpty()) {
116  6 for (String testName : testNames) {
117  12 if (!inTestNames.contains(testName)) {
118    // Add it with a Not Applicable State!
119  4 Test test = new Test();
120  4 test.prefix = testName;
121  4 test.state = State.NOT_APPLICABLE;
122  4 tests.add(test);
123    }
124    }
125    }
126    }
127   
128    /**
129    * Extracts tests names from the passed set of tests.
130    *
131    * @param tests the set of tests from which to extract test names
132    * @return the test names (eg "simple/bold/bold1")
133    */
 
134  8 toggle private List<String> extractTestNames(Set<Test> tests)
135    {
136  8 List<String> inTestNames = new ArrayList<String>();
137  8 Iterator<Test> it = tests.iterator();
138  16 while (it.hasNext()) {
139  8 inTestNames.add(it.next().prefix);
140    }
141  8 return inTestNames;
142    }
143    }