1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.test.cts

File TestData.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

10
21
7
1
178
96
12
0.57
3
7
1.71

Classes

Class Line # Actions
TestData 36 21 0% 12 10
0.736842173.7%
 

Contributing tests

This file is covered by 1 test. .

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.test.cts;
21   
22    import java.util.List;
23    import java.util.regex.Matcher;
24    import java.util.regex.Pattern;
25   
26    import org.apache.commons.lang3.builder.EqualsBuilder;
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28    import org.xwiki.text.XWikiToStringBuilder;
29   
30    /**
31    * Contains Test Data for a single test.
32    *
33    * @version $Id: 8950cb82e1976efb25f2d7f443f73b4c1c4fb85b $
34    * @since 4.1M1
35    */
 
36    public class TestData
37    {
38    /**
39    * The syntax being tested and in which the syntax data is written in (eg "xwiki/2.0").
40    */
41    public String syntaxId;
42   
43    /**
44    * The location where this tests is found in the CTS classpath (eg "cts/simple/bold/bold1").
45    */
46    public String prefix;
47   
48    /**
49    * Test Syntax file extension. To compute the full Syntax test name, use: prefix + syntaxExtension.
50    */
51    public String syntaxExtension;
52   
53    /**
54    * CTS file extension. To compute the full CTS test name, use: prefix + ctsExtension.
55    */
56    public String ctsExtension;
57   
58    /**
59    * True if this test is an input test, ie the syntax data represents an input, false otherwise.
60    */
61    public boolean isSyntaxInputTest;
62   
63    /**
64    * The CTS test data (either input or output, depending on whether the syntax data is input or outut; it's the
65    * opposite of the syntax data).
66    */
67    public String ctsData;
68   
69    /**
70    * The syntax data (either input or output).
71    */
72    public String syntaxData;
73   
74    /**
75    * Configuration data for the test.
76    */
77    public TestDataConfiguration configuration;
78   
 
79  0 toggle @Override
80    public String toString()
81    {
82  0 return new XWikiToStringBuilder(this)
83    .append("syntaxId", this.syntaxId)
84    .append("prefix", this.prefix)
85    .append("syntaxExtension", this.syntaxExtension)
86    .append("ctsExtension", this.ctsExtension)
87    .append("isSyntaxInputTest", this.isSyntaxInputTest)
88    .append("ctsData", this.ctsData)
89    .append("syntaxData", this.syntaxData)
90    .append("configuration", this.configuration)
91    .toString();
92    }
93   
94    /**
95    * @return if this test matches a not-applicable-test regex
96    */
 
97  1277 toggle public boolean isNotApplicable()
98    {
99  1277 return matches(this.configuration.notApplicableTests);
100    }
101   
102    /**
103    * @return if this test matches a failing-test regex
104    */
 
105  585 toggle public boolean isFailingTest()
106    {
107  585 return matches(this.configuration.failingTests);
108    }
109   
110    /**
111    * @param regexes the list of regexes to match against
112    * @return true if the current test matches at least one of the passed regexes or false otherwise
113    */
 
114  1862 toggle private boolean matches(List<String> regexes)
115    {
116  1862 boolean matches = false;
117  1862 for (String regex : regexes) {
118  1722 Pattern pattern = Pattern.compile(regex);
119  1722 Matcher matcher = pattern.matcher(computeTestName());
120  1722 if (matcher.matches()) {
121  131 matches = true;
122  131 break;
123    }
124    }
125  1862 return matches;
126    }
127   
128    /**
129    * Compute the test name, used to display in the JUnit Test Runner and for ignoring tests.
130    *
131    * @return the computed test name (eg "simple/bold/bold1 [xwiki/2.0, IN:bold1.in.txt, CTS:bold1.inout.xml]")
132    */
 
133  3063 toggle public String computeTestName()
134    {
135  3063 return String.format("%s [%s, %s:%s, CTS:%s]", this.prefix, this.syntaxId,
136  3063 this.isSyntaxInputTest ? "IN" : "OUT", this.syntaxExtension, this.ctsExtension);
137    }
138   
 
139  4 toggle @Override
140    public boolean equals(Object object)
141    {
142  4 if (object == null) {
143  0 return false;
144    }
145  4 if (object == this) {
146  0 return true;
147    }
148  4 if (object.getClass() != getClass()) {
149  0 return false;
150    }
151  4 TestData rhs = (TestData) object;
152  4 return new EqualsBuilder()
153    .append(this.syntaxId, rhs.syntaxId)
154    .append(this.prefix, rhs.prefix)
155    .append(this.syntaxExtension, rhs.syntaxExtension)
156    .append(this.ctsExtension, rhs.ctsExtension)
157    .append(this.isSyntaxInputTest, rhs.isSyntaxInputTest)
158    .append(this.ctsData, rhs.ctsData)
159    .append(this.syntaxData, rhs.syntaxData)
160    .append(this.configuration, rhs.configuration)
161    .isEquals();
162    }
163   
 
164  0 toggle @Override
165    public int hashCode()
166    {
167  0 return new HashCodeBuilder(3, 17)
168    .append(this.syntaxId)
169    .append(this.prefix)
170    .append(this.syntaxExtension)
171    .append(this.ctsExtension)
172    .append(this.isSyntaxInputTest)
173    .append(this.ctsData)
174    .append(this.syntaxData)
175    .append(this.configuration)
176    .toHashCode();
177    }
178    }