Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
artspb committed Jan 26, 2015
1 parent 068131a commit 2aa097c
Show file tree
Hide file tree
Showing 32 changed files with 1,368 additions and 10 deletions.
17 changes: 7 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
*.class
# IntelliJ IDEA
.idea/
*.iml

# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Mac OS X
.DS_Store

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Maven
target/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# idea-pitest
IDEA Pitest plugin

Pitest (aka PIT) is a state of the art mutation testing system for Java and the JVM.

Read all about it at http://pitest.org

The original Pitest logo was created by Ling Yeung. It is licensed under a [Creative Commons License](http://creativecommons.org/licenses/by-nc-sa/3.0/).
22 changes: 22 additions & 0 deletions idea-pitest-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>idea-pitest</artifactId>
<groupId>me.artspb.idea.pitest</groupId>
<version>1.1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>idea-pitest-example</artifactId>
<version>1.1.3.0</version>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.artspb.pitest.example;

/**
* @author Artem Khvastunov &lt;[email protected]&gt;
*/
public class SecondClass {

public int uncoveredMethod() {
int i = 42;
return Math.abs(i);
}

public int partiallyCoveredMethod(int input) {
if (input >= 0 || input % 2 == 0) {
return 42;
}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.artspb.pitest.example;

public class SimplePojo {

private String field;

public String getField() {
return field;
}

public void setField(String field) {
this.field = field;
doSomething();
new SecondClass();
}

private void doSomething() {
this.field = "dleif";
}

public static void main(String[] args) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.artspb.pitest.example;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class SecondClassTest {

private SecondClass secondClass;

@Before
public void setUp() throws Exception {
secondClass = new SecondClass();
}

@Test
public void testUncoveredMethod() throws Exception {
secondClass.uncoveredMethod();
}

@Test
public void testPartiallyCoveredMethod() throws Exception {
int output = secondClass.partiallyCoveredMethod(-2);
assertEquals(output, 42);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.artspb.pitest.example;

import org.junit.Before;
import org.junit.Test;

public class SimplePojoTest {

private SimplePojo pojo;

@Before
public void setUp() throws Exception {
pojo = new SimplePojo();
}

@Test
public void testGetField() throws Exception {
pojo.getField();
}

@Test
public void testSetField() throws Exception {
pojo.setField("field");
}
}
42 changes: 42 additions & 0 deletions idea-pitest-plugin/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<idea-plugin version="2">

<id>me.artspb.idea.pitest.plugin</id>
<name>Pitest</name>
<version>1.1.3.0</version>
<idea-version since-build="139"/>
<vendor email="[email protected]" url="http://artspb.me/pitest">Artem Khvastunov</vendor>
<description><![CDATA[
IntelliJ IDEA plugin which allows user to run Pitest and see results directly in the IDE.<br/>
Pitest (aka PIT) is a state of the art mutation testing system for Java and the JVM. Read all about it at http://pitest.org.
]]></description>
<change-notes>
<![CDATA[
version 1.1.3.0
<br/>
<ul>
<li>first release</li>
</ul>
]]>
</change-notes>

<depends>com.intellij.modules.java</depends>
<depends>JUnit</depends>
<depends>Coverage</depends>

<extensions defaultExtensionNs="com.intellij">
<runConfigurationExtension implementation="me.artspb.idea.pitest.plugin.execution.PitestRunConfigurationExtension"/>
<programRunner implementation="me.artspb.idea.pitest.plugin.runner.PitestProgramRunner"/>
<executor implementation="me.artspb.idea.pitest.plugin.execution.PitestExecutor"/>
<coverageRunner implementation="me.artspb.idea.pitest.plugin.coverage.PitestCoverageRunner"/>
</extensions>

<application-components>
</application-components>

<project-components>
</project-components>

<actions>
</actions>

</idea-plugin>
Binary file added idea-pitest-plugin/lib/pitest-1.1.3.jar
Binary file not shown.
Binary file not shown.
Binary file added idea-pitest-plugin/resources/pitest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions idea-pitest-plugin/src/me/artspb/idea/pitest/plugin/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.artspb.idea.pitest.plugin;

/**
* @author Artem Khvastunov &lt;[email protected]&gt;
*/
final public class Constants {

public static final String ANY_CLASS_PATTERN = "(*)";
public static final String ANY_IN_PACKAGE_PATTERN = ".*";

private Constants() {
}
}
16 changes: 16 additions & 0 deletions idea-pitest-plugin/src/me/artspb/idea/pitest/plugin/Icons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.artspb.idea.pitest.plugin;

import com.intellij.openapi.util.IconLoader;

import javax.swing.*;

/**
* @author Artem Khvastunov &lt;[email protected]&gt;
*/
public final class Icons {

public static final Icon PITEST = IconLoader.getIcon("/pitest.png");

private Icons() {
}
}
16 changes: 16 additions & 0 deletions idea-pitest-plugin/src/me/artspb/idea/pitest/plugin/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.artspb.idea.pitest.plugin;

import java.io.File;

/**
* @author Artem Khvastunov &lt;[email protected]&gt;
*/
public final class Utils {

private Utils() {
}

public static String concatenatePath(String parent, String child) {
return new File(parent, child).getPath();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package me.artspb.idea.pitest.plugin.configuration;

import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.WriteExternalException;
import me.artspb.idea.pitest.plugin.configuration.junit.JUnitConfigurationUtils;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;

/**
* @author Artem Khvastunov &lt;[email protected]&gt;
*/
public class PitestConfiguration implements JDOMExternalizable {

public static final Key<PitestConfiguration> PITEST_KEY = Key.create("me.artspb.idea.pitest.plugin");

private static final String EDIT_MANUALLY = "editManually";
private static final String TARGET_TESTS = "targetTests";
private static final String TARGET_CLASSES = "targetClasses";
private static final String EXCLUDED_CLASSES = "excludedClasses";
private static final String REPORT_DIR = "reportDir";
private static final String SOURCE_DIRS = "sourceDirs";

private boolean editManually;
private String targetTests;
private String targetClasses;
private String excludedClasses;
private String reportDir;
private String sourceDirs;

public static PitestConfiguration getOrCreate(@NotNull RunConfigurationBase runConfiguration) {
PitestConfiguration configuration = runConfiguration.getCopyableUserData(PITEST_KEY);
if (configuration == null || !configuration.isEditManually()) {
if (JUnitConfigurationUtils.supports(runConfiguration)) {
configuration = JUnitConfigurationUtils.parse(runConfiguration);
}
runConfiguration.putCopyableUserData(PITEST_KEY, configuration);
}
return configuration;
}

@Override
public void readExternal(Element element) throws InvalidDataException {
setEditManually(Boolean.valueOf(element.getAttributeValue(EDIT_MANUALLY)));
setTargetTests(element.getAttributeValue(TARGET_TESTS));
setTargetClasses(element.getAttributeValue(TARGET_CLASSES));
setExcludedClasses(element.getAttributeValue(EXCLUDED_CLASSES));
setReportDir(element.getAttributeValue(REPORT_DIR));
setSourceDirs(element.getAttributeValue(SOURCE_DIRS));
}

@Override
public void writeExternal(Element element) throws WriteExternalException {
if (isEditManually()) {
element.setAttribute(EDIT_MANUALLY, String.valueOf(true));
element.setAttribute(TARGET_TESTS, getTargetTests());
element.setAttribute(TARGET_CLASSES, getTargetClasses());
element.setAttribute(EXCLUDED_CLASSES, getExcludedClasses());
element.setAttribute(REPORT_DIR, getReportDir());
element.setAttribute(SOURCE_DIRS, getSourceDirs());
}
}

public boolean isEditManually() {
return editManually;
}

public void setEditManually(boolean editManually) {
this.editManually = editManually;
}

public String getTargetTests() {
return targetTests;
}

public void setTargetTests(String targetTests) {
this.targetTests = targetTests;
}

public String getTargetClasses() {
return targetClasses;
}

public void setTargetClasses(String targetClasses) {
this.targetClasses = targetClasses;
}

public String getExcludedClasses() {
return excludedClasses;
}

public void setExcludedClasses(String excludedClasses) {
this.excludedClasses = excludedClasses;
}

public String getReportDir() {
return reportDir;
}

public void setReportDir(String reportDir) {
this.reportDir = reportDir;
}

public String getSourceDirs() {
return sourceDirs;
}

public void setSourceDirs(String sourceDirs) {
this.sourceDirs = sourceDirs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.artspb.idea.pitest.plugin.configuration.junit;

import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.psi.util.ClassUtil;
import me.artspb.idea.pitest.plugin.configuration.PitestConfiguration;
import org.apache.commons.lang.StringUtils;

import static me.artspb.idea.pitest.plugin.Constants.ANY_IN_PACKAGE_PATTERN;

/**
* @author Artem Khvastunov &lt;[email protected]&gt;
*/
class ClassBasedConfigurator extends Configurator {

@Override
public void configure(JUnitConfiguration jUnitConfiguration, PitestConfiguration configuration) {
JUnitConfiguration.Data data = jUnitConfiguration.getPersistentData();
String targetTests = data.getMainClassName();
String targetClasses;
if (StringUtils.endsWith(targetTests, "Test")) {
targetClasses = targetTests.substring(0, targetTests.lastIndexOf("Test"));
} else {
targetClasses = ClassUtil.extractPackageName(targetTests) + ANY_IN_PACKAGE_PATTERN;
}
configure(configuration, targetTests, targetClasses);
}
}
Loading

0 comments on commit 2aa097c

Please sign in to comment.