Skip to content

Commit

Permalink
Issue #6439: move powermock tests away from the normal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Feb 23, 2019
1 parent 96385e2 commit 86dcb80
Show file tree
Hide file tree
Showing 52 changed files with 2,867 additions and 1,843 deletions.
135 changes: 133 additions & 2 deletions .ci/pitest.sh

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions config/import-control-test.xml
Expand Up @@ -7,6 +7,13 @@


<disallow pkg="junit.framework" /> <disallow pkg="junit.framework" />


<!-- Conflicts with normal tests and pitest.
See examples in https://github.com/checkstyle/checkstyle/issues/6439 -->
<allow class="org.powermock.reflect.Whitebox" />
<allow class="org.mockito.internal.util.Checks" />
<disallow pkg="org\.powermock.*" regex="true" />
<disallow pkg="org\.mockito.*" regex="true" />

<allow pkg=".*" regex="true" /> <allow pkg=".*" regex="true" />


</import-control> </import-control>
2 changes: 2 additions & 0 deletions config/suppressions.xml
Expand Up @@ -97,4 +97,6 @@


<!-- HandlerFactory crosses allowed limit for executable statements --> <!-- HandlerFactory crosses allowed limit for executable statements -->
<suppress checks="ExecutableStatementCount" files="HandlerFactory\.java"/> <suppress checks="ExecutableStatementCount" files="HandlerFactory\.java"/>

<suppress id="ImportControlTest" files="[\\/]powermock[\\/]" message=".* - org\.(powermock|mockito).*" />
</suppressions> </suppressions>
30 changes: 15 additions & 15 deletions pom.xml
Expand Up @@ -1827,7 +1827,7 @@
<param>com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilterTest</param> <param>com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilterTest</param>
</targetTests> </targetTests>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>100</coverageThreshold>
<mutationThreshold>100</mutationThreshold> <mutationThreshold>98</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2052,8 +2052,8 @@
<excludedTestClasses> <excludedTestClasses>
<param>*.Input*</param> <param>*.Input*</param>
</excludedTestClasses> </excludedTestClasses>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>97</coverageThreshold>
<mutationThreshold>98</mutationThreshold> <mutationThreshold>96</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2511,8 +2511,8 @@
<excludedTestClasses> <excludedTestClasses>
<param>*.Input*</param> <param>*.Input*</param>
</excludedTestClasses> </excludedTestClasses>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>99</coverageThreshold>
<mutationThreshold>99</mutationThreshold> <mutationThreshold>96</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2553,8 +2553,8 @@
<targetTests> <targetTests>
<param>com.puppycrawl.tools.checkstyle.PackageNamesLoaderTest</param> <param>com.puppycrawl.tools.checkstyle.PackageNamesLoaderTest</param>
</targetTests> </targetTests>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>32</coverageThreshold>
<mutationThreshold>100</mutationThreshold> <mutationThreshold>20</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2627,8 +2627,8 @@
<!-- this test is required for Checker --> <!-- this test is required for Checker -->
<param>com.puppycrawl.tools.checkstyle.filefilters.BeforeExecutionExclusionFileFilterTest</param> <param>com.puppycrawl.tools.checkstyle.filefilters.BeforeExecutionExclusionFileFilterTest</param>
</targetTests> </targetTests>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>98</coverageThreshold>
<mutationThreshold>98</mutationThreshold> <mutationThreshold>94</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2729,7 +2729,7 @@
<param>com.puppycrawl.tools.checkstyle.MainTest</param> <param>com.puppycrawl.tools.checkstyle.MainTest</param>
</targetTests> </targetTests>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>100</coverageThreshold>
<mutationThreshold>99</mutationThreshold> <mutationThreshold>98</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2820,7 +2820,7 @@
</avoidCallsTo> </avoidCallsTo>
</avoidCallsTo> </avoidCallsTo>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>100</coverageThreshold>
<mutationThreshold>100</mutationThreshold> <mutationThreshold>99</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2878,7 +2878,7 @@
<param>*.Input*</param> <param>*.Input*</param>
</excludedTestClasses> </excludedTestClasses>
<coverageThreshold>99</coverageThreshold> <coverageThreshold>99</coverageThreshold>
<mutationThreshold>99</mutationThreshold> <mutationThreshold>98</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down Expand Up @@ -2924,7 +2924,7 @@
<excludedTestClasses> <excludedTestClasses>
<param>*.Input*</param> <param>*.Input*</param>
</excludedTestClasses> </excludedTestClasses>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>99</coverageThreshold>
<mutationThreshold>97</mutationThreshold> <mutationThreshold>97</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
Expand Down Expand Up @@ -2988,7 +2988,7 @@
<excludedTestClasses> <excludedTestClasses>
<param>*.Input*</param> <param>*.Input*</param>
</excludedTestClasses> </excludedTestClasses>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>99</coverageThreshold>
<mutationThreshold>100</mutationThreshold> <mutationThreshold>100</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
Expand Down Expand Up @@ -3108,7 +3108,7 @@
<param>*.Input*</param> <param>*.Input*</param>
</excludedTestClasses> </excludedTestClasses>
<coverageThreshold>100</coverageThreshold> <coverageThreshold>100</coverageThreshold>
<mutationThreshold>96</mutationThreshold> <mutationThreshold>93</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor> <timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant> <timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads> <threads>${pitest.plugin.threads}</threads>
Expand Down
Expand Up @@ -57,7 +57,7 @@
* configuration has changed. * configuration has changed.
* *
*/ */
final class PropertyCacheFile { public final class PropertyCacheFile {


/** /**
* The property key to use for storing the hashcode of the * The property key to use for storing the hashcode of the
Expand Down Expand Up @@ -93,7 +93,7 @@ final class PropertyCacheFile {
* @param config the current configuration, not null * @param config the current configuration, not null
* @param fileName the cache file * @param fileName the cache file
*/ */
PropertyCacheFile(Configuration config, String fileName) { public PropertyCacheFile(Configuration config, String fileName) {
if (config == null) { if (config == null) {
throw new IllegalArgumentException("config can not be null"); throw new IllegalArgumentException("config can not be null");
} }
Expand Down
Expand Up @@ -40,7 +40,7 @@
/** /**
* Responsible for loading the contents of an import control configuration file. * Responsible for loading the contents of an import control configuration file.
*/ */
final class ImportControlLoader extends XmlLoader { public final class ImportControlLoader extends XmlLoader {


/** The public ID for the configuration dtd. */ /** The public ID for the configuration dtd. */
private static final String DTD_PUBLIC_ID_1_0 = private static final String DTD_PUBLIC_ID_1_0 =
Expand Down
Expand Up @@ -20,23 +20,16 @@
package com.puppycrawl.tools.checkstyle; package com.puppycrawl.tools.checkstyle;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;


import java.lang.reflect.Method; import java.lang.reflect.Method;


import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;


import com.puppycrawl.tools.checkstyle.api.AuditEvent; import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; import com.puppycrawl.tools.checkstyle.api.SeverityLevel;


@RunWith(PowerMockRunner.class)
@PrepareForTest(AuditEvent.class)
public class AuditEventDefaultFormatterTest { public class AuditEventDefaultFormatterTest {


@Test @Test
Expand Down Expand Up @@ -65,38 +58,6 @@ public void testFormatFullyQualifiedModuleNameDoesNotContainCheckSuffix() {
assertEquals("Invalid format", expected, formatter.format(event)); assertEquals("Invalid format", expected, formatter.format(event));
} }


@Test
public void testFormatModuleNameContainsCheckSuffix() {
final AuditEvent mock = PowerMockito.mock(AuditEvent.class);
when(mock.getSourceName()).thenReturn("TestModuleCheck");
when(mock.getSeverityLevel()).thenReturn(SeverityLevel.WARNING);
when(mock.getLine()).thenReturn(1);
when(mock.getColumn()).thenReturn(1);
when(mock.getMessage()).thenReturn("Mocked message.");
when(mock.getFileName()).thenReturn("InputMockFile.java");
final AuditEventFormatter formatter = new AuditEventDefaultFormatter();

final String expected = "[WARN] InputMockFile.java:1:1: Mocked message. [TestModule]";

assertEquals("Invalid format", expected, formatter.format(mock));
}

@Test
public void testFormatModuleNameDoesNotContainCheckSuffix() {
final AuditEvent mock = PowerMockito.mock(AuditEvent.class);
when(mock.getSourceName()).thenReturn("TestModule");
when(mock.getSeverityLevel()).thenReturn(SeverityLevel.WARNING);
when(mock.getLine()).thenReturn(1);
when(mock.getColumn()).thenReturn(1);
when(mock.getMessage()).thenReturn("Mocked message.");
when(mock.getFileName()).thenReturn("InputMockFile.java");
final AuditEventFormatter formatter = new AuditEventDefaultFormatter();

final String expected = "[WARN] InputMockFile.java:1:1: Mocked message. [TestModule]";

assertEquals("Invalid format", expected, formatter.format(mock));
}

@Test @Test
public void testFormatModuleWithModuleId() { public void testFormatModuleWithModuleId() {
final LocalizedMessage message = new LocalizedMessage(1, 1, null, null, null, final LocalizedMessage message = new LocalizedMessage(1, 1, null, null, null,
Expand Down Expand Up @@ -124,22 +85,12 @@ public void testCalculateBufferLength() throws Exception {
assertEquals("Buffer length is not expected", 54, result); assertEquals("Buffer length is not expected", 54, result);
} }


/**
* Non meaningful javadoc just to contain "noinspection" tag.
* Till https://youtrack.jetbrains.com/issue/IDEA-187210
* @noinspection JUnitTestCaseWithNoTests
*/
private static class TestModuleCheck { private static class TestModuleCheck {


// no code // no code


} }


/**
* Non meaningful javadoc just to contain "noinspection" tag.
* Till https://youtrack.jetbrains.com/issue/IDEA-187210
* @noinspection JUnitTestCaseWithNoTests
*/
private static class TestModule { private static class TestModule {


// no code // no code
Expand Down

0 comments on commit 86dcb80

Please sign in to comment.