Skip to content

Commit

Permalink
Issue checkstyle#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 21, 2019
1 parent 88907c5 commit 1ada892
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" />

<!-- 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" />

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

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

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

/**
* 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 fileName the cache file
*/
PropertyCacheFile(Configuration config, String fileName) {
public PropertyCacheFile(Configuration config, String fileName) {
if (config == 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.
*/
final class ImportControlLoader extends XmlLoader {
public final class ImportControlLoader extends XmlLoader {

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

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

import java.lang.reflect.Method;

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 com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;

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

@Test
Expand Down Expand Up @@ -65,38 +58,6 @@ public void testFormatFullyQualifiedModuleNameDoesNotContainCheckSuffix() {
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
public void testFormatModuleWithModuleId() {
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);
}

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

// no code

}

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

// no code
Expand Down

0 comments on commit 1ada892

Please sign in to comment.