Skip to content

Commit

Permalink
minor: changed powermock tests to normal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Feb 23, 2019
1 parent 1ada892 commit af13d06
Show file tree
Hide file tree
Showing 20 changed files with 629 additions and 782 deletions.
62 changes: 1 addition & 61 deletions .ci/pitest.sh
Expand Up @@ -34,6 +34,7 @@ case $1 in
pitest-annotation|pitest-design \
|pitest-metrics|pitest-modifier|pitest-naming \
|pitest-sizes|pitest-whitespace \
|pitest-packagenamesloader \
|pitest-common-2)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=();
Expand Down Expand Up @@ -74,9 +75,7 @@ pitest-header)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"AbstractHeaderCheck.java.html:<td class='uncovered'><pre><span class=''> catch (final IOException ex) {</span></pre></td></tr>"
"AbstractHeaderCheck.java.html:<td class='uncovered'><pre><span class=''> catch (final IOException ex) {</span></pre></td></tr>"
"AbstractHeaderCheck.java.html:<td class='uncovered'><pre><span class='survived'> throw new IllegalArgumentException(&#34;unable to load header&#34;, ex);</span></pre></td></tr>"
"AbstractHeaderCheck.java.html:<td class='uncovered'><pre><span class='survived'> throw new CheckstyleException(</span></pre></td></tr>"
"HeaderCheck.java.html:<td class='covered'><pre><span class='survived'> if (list.length == 0) {</span></pre></td></tr>"
"RegexpHeaderCheck.java.html:<td class='covered'><pre><span class='survived'> if (list.length == 0) {</span></pre></td></tr>"
"RegexpHeaderCheck.java.html:<td class='covered'><pre><span class='survived'> isMatch = headerLineNo == headerSize</span></pre></td></tr>"
Expand All @@ -94,10 +93,6 @@ pitest-filters)
"SuppressionCommentFilter.java.html:<td class='covered'><pre><span class='survived'> if (line == object.line) {</span></pre></td></tr>"
"SuppressionXpathSingleFilter.java.html:<td class='covered'><pre><span class='survived'> if (checks == null) {</span></pre></td></tr>"
"SuppressionXpathSingleFilter.java.html:<td class='covered'><pre><span class='survived'> if (files == null) {</span></pre></td></tr>"
"SuppressionsLoader.java.html:<td class='uncovered'><pre><span class=''> catch (final FileNotFoundException ex) {</span></pre></td></tr>"
"SuppressionsLoader.java.html:<td class='uncovered'><pre><span class=''> catch (final IOException ex) {</span></pre></td></tr>"
"SuppressionsLoader.java.html:<td class='uncovered'><pre><span class='survived'> throw new CheckstyleException(&#34;Unable to read &#34; + sourceName, ex);</span></pre></td></tr>"
"SuppressionsLoader.java.html:<td class='uncovered'><pre><span class='survived'> throw new CheckstyleException(UNABLE_TO_FIND_ERROR_MESSAGE + sourceName, ex);</span></pre></td></tr>"
"SuppressWithNearbyCommentFilter.java.html:<td class='covered'><pre><span class='survived'> else if (tagMessageRegexp == null) {</span></pre></td></tr>"
"SuppressWithNearbyCommentFilter.java.html:<td class='covered'><pre><span class='survived'> if (CommonUtil.startsWithChar(format, &#39;+&#39;)) {</span></pre></td></tr>"
"SuppressWithNearbyCommentFilter.java.html:<td class='covered'><pre><span class='survived'> if (event.getLocalizedMessage() != null) {</span></pre></td></tr>"
Expand Down Expand Up @@ -126,20 +121,13 @@ pitest-api)
"FileContents.java.html:<td class='covered'><pre><span class='survived'> if (hasIntersection) {</span></pre></td></tr>"
"FileText.java.html:<td class='covered'><pre><span class='survived'> if (lineBreaks == null) {</span></pre></td></tr>"
"FileText.java.html:<td class='covered'><pre><span class='survived'> if (lineNo &#60; lineBreakPositions.length) {</span></pre></td></tr>"
"LocalizedMessage.java.html:<td class='covered'><pre><span class='survived'> StandardCharsets.UTF_8.name())) {</span></pre></td></tr>"
"LocalizedMessage.java.html:<td class='covered'><pre><span class='survived'> resourceBundle = new PropertyResourceBundle(streamReader);</span></pre></td></tr>"
"LocalizedMessage.java.html:<td class='covered'><pre><span class='survived'> connection.setUseCaches(!reload);</span></pre></td></tr>"
"LocalizedMessage.java.html:<td class='covered'><pre><span class='survived'> if (connection != null) {</span></pre></td></tr>"
"LocalizedMessage.java.html:<td class='covered'><pre><span class='survived'> if (url != null) {</span></pre></td></tr>"
);
checkPitestReport "${ignoredItems[@]}"
;;

pitest-main)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"Main.java.html:<td class='covered'><pre><span class='survived'> if (files != null) {</span></pre></td></tr>"
"Main.java.html:<td class='covered'><pre><span class='survived'> else if (node.isFile()) {</span></pre></td></tr>"
"Main.java.html:<td class='covered'><pre><span class='survived'> if (node.canRead()) {</span></pre></td></tr>"
"Main.java.html:<td class='covered'><pre><span class='survived'> if (options.executeIgnoredModules) {</span></pre></td></tr>"
"Main.java.html:<td class='covered'><pre><span class='survived'> if (outputPath == null) {</span></pre></td></tr>"
Expand Down Expand Up @@ -337,15 +325,6 @@ pitest-tree-walker)
pitest-misc)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"NewlineAtEndOfFileCheck.java.html:<td class='covered'><pre><span class='survived'> if (readBytes != len) {</span></pre></td></tr>"
"NewlineAtEndOfFileCheck.java.html:<td class='uncovered'><pre><span class='survived'> throw new IOException(&#34;Unable to read &#34; + len + &#34; bytes, got &#34;</span></pre></td></tr>"
"SuppressWarningsHolder.java.html:<td class='covered'><pre><span class='survived'> .getLastColumn() &#62;= column;</span></pre></td></tr>"
"SuppressWarningsHolder.java.html:<td class='covered'><pre><span class='survived'> ALL_WARNING_MATCHING_ID.equals(entry.getCheckName())</span></pre></td></tr>"
"SuppressWarningsHolder.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; (column == 0 || entry.getFirstColumn() &#60;= column);</span></pre></td></tr>"
"SuppressWarningsHolder.java.html:<td class='covered'><pre><span class='survived'> return firstColumn;</span></pre></td></tr>"
"SuppressWarningsHolder.java.html:<td class='covered'><pre><span class='survived'> || entry.getFirstLine() == line</span></pre></td></tr>"
"SuppressWarningsHolder.java.html:<td class='covered'><pre><span class='survived'> || entry.getLastLine() == line &#38;&#38; entry</span></pre></td></tr>"
"SuppressWarningsHolder.java.html:<td class='covered'><pre><span class='survived'> return entry.getFirstLine() &#60; line</span></pre></td></tr>"
"TranslationCheck.java.html:<td class='covered'><pre><span class='survived'> if (exception instanceof NoSuchFileException) {</span></pre></td></tr>"
"TranslationCheck.java.html:<td class='uncovered'><pre><span class=''> args = null;</span></pre></td></tr>"
"TranslationCheck.java.html:<td class='uncovered'><pre><span class=''> key = &#34;general.fileNotFound&#34;;</span></pre></td></tr>"
Expand All @@ -364,45 +343,6 @@ pitest-utils)
checkPitestReport "${ignoredItems[@]}"
;;

pitest-packagenamesloader)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"PackageNamesLoader.java.html:<td class='covered'><pre><span class='survived'> while (packageFiles.hasMoreElements()) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='covered'><pre><span class='survived'> private final Deque&#60;String&#62; packageStack = new ArrayDeque&#60;&#62;();</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> buf.append(&#39;.&#39;);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> buf.append(subPackage);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> final String name = attributes.getValue(&#34;name&#34;);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> final String subPackage = iterator.next();</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> packageNames.add(getPackageName());</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> packageStack.pop();</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> catch (IOException ex) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> catch (IOException ex) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> catch (ParserConfigurationException | SAXException ex) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> final Iterator&#60;String&#62; iterator = packageStack.descendingIterator();</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> }</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> }</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> }</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> }</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> }</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class=''> }</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> processFile(packageFiles.nextElement(), namesLoader);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> final InputSource source = new InputSource(stream);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> if (!CommonUtil.endsWithChar(subPackage, &#39;.&#39;) &#38;&#38; iterator.hasNext()) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> namesLoader.parseInputSource(source);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> packageStack.push(name);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> throw new CheckstyleException(&#34;unable to get package file resources&#34;, ex);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> throw new CheckstyleException(&#34;unable to open &#34; + packageFile, ex);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> throw new CheckstyleException(&#34;unable to open one of package files&#34;, ex);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> final StringBuilder buf = new StringBuilder(256);</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> if (PACKAGE_ELEMENT_NAME.equals(qName)) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> if (PACKAGE_ELEMENT_NAME.equals(qName)) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> return buf.toString();</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> try (InputStream stream = new BufferedInputStream(packageFile.openStream())) {</span></pre></td></tr>"
"PackageNamesLoader.java.html:<td class='uncovered'><pre><span class='survived'> while (iterator.hasNext()) {</span></pre></td></tr>"
);
checkPitestReport "${ignoredItems[@]}"
;;

# pitesttyle-gui)
# mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
# # post validation is skipped, we do not test gui throughly
Expand Down
2 changes: 1 addition & 1 deletion config/suppressions.xml
Expand Up @@ -79,7 +79,7 @@
files="(Checker|Main|CheckstyleAntTask|JavadocDetailNodeParser)\.java"/>
<suppress checks="ClassDataAbstractionCoupling"
files="(CheckerTest|AbstractModuleTestSupport|CheckstyleAntTaskTest|
|TranslationCheckTest)\.java"/>
|TranslationCheckTest|LocalizedMessageTest)\.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="PropertyCacheFileTest\.java"/>
<suppress checks="ClassDataAbstractionCoupling"
files="XpathFileGeneratorAuditListenerTest\.java"/>
Expand Down
16 changes: 8 additions & 8 deletions pom.xml
Expand Up @@ -1827,7 +1827,7 @@
<param>com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilterTest</param>
</targetTests>
<coverageThreshold>100</coverageThreshold>
<mutationThreshold>98</mutationThreshold>
<mutationThreshold>99</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2052,8 +2052,8 @@
<excludedTestClasses>
<param>*.Input*</param>
</excludedTestClasses>
<coverageThreshold>97</coverageThreshold>
<mutationThreshold>96</mutationThreshold>
<coverageThreshold>98</coverageThreshold>
<mutationThreshold>97</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2553,8 +2553,8 @@
<targetTests>
<param>com.puppycrawl.tools.checkstyle.PackageNamesLoaderTest</param>
</targetTests>
<coverageThreshold>32</coverageThreshold>
<mutationThreshold>20</mutationThreshold>
<coverageThreshold>100</coverageThreshold>
<mutationThreshold>100</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2729,7 +2729,7 @@
<param>com.puppycrawl.tools.checkstyle.MainTest</param>
</targetTests>
<coverageThreshold>100</coverageThreshold>
<mutationThreshold>98</mutationThreshold>
<mutationThreshold>99</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2878,7 +2878,7 @@
<param>*.Input*</param>
</excludedTestClasses>
<coverageThreshold>99</coverageThreshold>
<mutationThreshold>98</mutationThreshold>
<mutationThreshold>99</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2924,7 +2924,7 @@
<excludedTestClasses>
<param>*.Input*</param>
</excludedTestClasses>
<coverageThreshold>99</coverageThreshold>
<coverageThreshold>100</coverageThreshold>
<mutationThreshold>97</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
Expand Up @@ -49,6 +49,7 @@
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.rules.TemporaryFolder;
import org.powermock.reflect.Whitebox;

import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
Expand Down Expand Up @@ -617,6 +618,67 @@ public void testExistingDirectoryWithViolations() throws Exception {
getPath(""));
}

/**
* Test doesn't need to be serialized.
* @noinspection SerializableInnerClassWithNonSerializableOuterClass
*/
@Test
public void testListFilesNotFile() throws Exception {
final File fileMock = new File("") {
private static final long serialVersionUID = 1L;

@Override
public boolean canRead() {
return true;
}

@Override
public boolean isDirectory() {
return false;
}

@Override
public boolean isFile() {
return false;
}
};

final List<File> result = Whitebox.invokeMethod(Main.class, "listFiles",
fileMock, new ArrayList<Pattern>());
assertEquals("Invalid result size", 0, result.size());
}

/**
* Test doesn't need to be serialized.
* @noinspection SerializableInnerClassWithNonSerializableOuterClass
*/
@Test
public void testListFilesDirectoryWithNull() throws Exception {
final File[] nullResult = null;
final File fileMock = new File("") {
private static final long serialVersionUID = 1L;

@Override
public boolean canRead() {
return true;
}

@Override
public boolean isDirectory() {
return true;
}

@Override
public File[] listFiles() {
return nullResult;
}
};

final List<File> result = Whitebox.invokeMethod(Main.class, "listFiles",
fileMock, new ArrayList<Pattern>());
assertEquals("Invalid result size", 0, result.size());
}

@Test
public void testFileReferenceDuringException() throws Exception {
exit.expectSystemExitWithStatus(-2);
Expand Down

0 comments on commit af13d06

Please sign in to comment.