Skip to content

Commit

Permalink
failing test case for #771
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles authored and hcoles committed Dec 31, 2020
1 parent 88bd740 commit 28c26c5
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ target/
dependency-reduced-pom.xml
.flattened-pom.xml
*/bin
.DS_Store

35 changes: 23 additions & 12 deletions pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@
*/
package org.pitest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
Expand All @@ -43,6 +31,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

/**
* @author Stefan Penndorf <[email protected]>
*/
Expand Down Expand Up @@ -563,4 +563,15 @@ public void shouldFindOccupiedTestPackages() throws IOException, VerificationExc
"<mutation detected='true' status='KILLED' numberOfTestsRun='1'><sourceFile>DiscoveredClass.java</sourceFile>");
}

@Test
public void shouldNotNullPointerWhenEnumInitiliazerNotCalled() throws IOException, VerificationException {
File testDir = prepare("/pit-enum-constructor-npe");
verifier.executeGoal("test");
verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage");

String actual = readResults(testDir);
assertThat(actual).contains(
"<mutation detected='true' status='KILLED' numberOfTestsRun='1'><sourceFile>DiscoveredClass.java</sourceFile>");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>pitest-sample</artifactId>
<version>0.1-SNAPSHOT</version>
<name>pit #770 npe in constructor</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pit.version}</version>
<configuration>
<verbose>true</verbose>
<outputFormats>
<value>XML</value>
</outputFormats>
<timestampedReports>false</timestampedReports>
<exportLineCoverage>true</exportLineCoverage>
<mutators>
<mutator>VOID_METHOD_CALLS</mutator>
</mutators>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example;

class Test {
public Test() {
System.out.println("I only exist so that pitest thinks there is something to mutate");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example;

import org.junit.Test;

public class NestedClassTest {
public static enum MyEnum {
A { }
}

@Test
public void test() throws ClassNotFoundException {
Class.forName("com.example.NestedClassTest$MyEnum$1");
}
}

0 comments on commit 28c26c5

Please sign in to comment.