Skip to content

Commit

Permalink
Merge pull request #1022 from hcoles/feature/non-delegating-classload…
Browse files Browse the repository at this point in the history
…er-test-support

support quarkus test runner
  • Loading branch information
hcoles authored May 20, 2022
2 parents 203ec98 + 4bb3171 commit 5558125
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 15 deletions.
8 changes: 7 additions & 1 deletion pitest-maven-verification/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<version>1.7.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-entry</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.rules.TestName;
import org.pitest.support.DirectoriesOnlyWalker;
import org.pitest.testapi.execute.Pitest;
import org.pitest.util.CurrentRuntime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,6 +37,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

/**
* @author Stefan Penndorf <stefan.penndorf@gmail.com>
Expand All @@ -55,7 +57,7 @@ public class PitMojoIT {

@Before
public void beforeEachTest() {
LOGGER.info("running test '{}'", testName.getMethodName());
LOGGER.info("running test '{}' with {} ", testName.getMethodName(), VERSION);
startTime = System.currentTimeMillis();
}

Expand Down Expand Up @@ -391,6 +393,27 @@ public void shouldWorkWithYatspec() throws Exception {
assertThat(actual).doesNotContain("status='RUN_ERROR'");
}

@Test
// note this test depends on the junit5 plugin
public void shouldWorkWithQuarkus() throws Exception {
assumeTrue(CurrentRuntime.version() >= 11);

File testDir = prepare("/pit-quarkus");
verifier.executeGoal("test");
verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage");

String actual = readResults(testDir);
assertThat(actual)
.contains(
"<mutation detected='false' status='SURVIVED' numberOfTestsRun='2'>" +
"<sourceFile>ExampleController.java</sourceFile>");

assertThat(actual)
.contains(
"<mutation detected='true' status='KILLED' numberOfTestsRun='2'><sourceFile>ExampleController.java</sourceFile>");

}


private static String readResults(File testDir) throws IOException {
File mutationReport = new File(testDir.getAbsoluteFile() + File.separator
Expand Down
116 changes: 116 additions & 0 deletions pitest-maven-verification/src/test/resources/pit-quarkus/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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-quarlus</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<failsafe.useModulePath>false</failsafe.useModulePath>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.8.3.Final</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<pitest.junit5.version>0.14</pitest.junit5.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
<version>2.8.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pit.version}</version>
<configuration>
<timeoutConstant>10000</timeoutConstant>
<exportLineCoverage>true</exportLineCoverage>
<outputFormats><value>XML</value></outputFormats>
<timestampedReports>false</timestampedReports>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>${pitest.junit5.version}</version>
</dependency>
</dependencies>
</plugin>

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

import com.example.service.ExampleService;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/example")
@ApplicationScoped
public class ExampleController {
@Inject
ExampleService service;

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public boolean doStuff(String s) {
System.out.println("Won't die");
return service.doStuff(s);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.service;


import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class ExampleService {

public boolean doStuff(String s) {
return s.equals("foo");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.rest-client."org.acme.rest.client.ExtensionsService".scope=javax.inject.ApplicationScoped #
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example;

import com.example.controller.ExampleController;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import com.example.service.ExampleService;

import javax.inject.Inject;
import io.quarkus.test.junit.mockito.InjectMock;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;

@QuarkusTest
public class ExampleControllerTest {
@Inject
ExampleController controller;

@InjectMock
ExampleService service;

@Test
void doTrue() {
Mockito.when(service.doStuff(anyString())).thenReturn(true);
assertTrue(controller.doStuff("s"));
}

@Test
void doFalse() {
Mockito.when(service.doStuff(anyString())).thenReturn(false);
assertFalse(controller.doStuff("s"));
}


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

import io.quarkus.test.junit.QuarkusTest;
import com.example.service.ExampleService;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTest
public class ExampleServiceTest {
@Inject
ExampleService service;


@Test
void doTrue() {
assertTrue(service.doStuff("foo"));
}

@Test
void doFalse() {
assertFalse(service.doStuff("notfoo"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example;

import org.junit.jupiter.api.Test;

class NormalTest {

@Test
void dd() {
long pid = ProcessHandle.current().pid();
System.out.println("!!!!!!!!!!!!! " + pid);
}

}
1 change: 0 additions & 1 deletion pitest/src/main/java/org/pitest/boot/HotSwapAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static boolean hotSwap(final Class<?> mutateMe, final byte[] bytes) { //

try {
instrumentation.redefineClasses(definitions);

return true;
} catch (final ClassNotFoundException | UnmodifiableClassException | VerifyError | InternalError e) {
// swallow
Expand Down
11 changes: 0 additions & 11 deletions pitest/src/main/java/org/pitest/functional/prelude/Prelude.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -54,12 +53,6 @@ public static <A> Or<A> or(final Iterable<Predicate<A>> ps) {
return new Or<>(ps);
}

public static <A> Consumer<A> accumulateTo(
final Collection<A> collection) {
return collection::add;

}

public static <A, B> Consumer<A> putToMap(final Map<A, B> map,
final B value) {
return key -> map.put(key, value);
Expand Down Expand Up @@ -94,10 +87,6 @@ public static <T> Consumer<T> printlnWith(final T t) {
return a -> System.out.println(t + " : " + a);
}

public static <T extends Number> Predicate<T> isGreaterThan(final T value) {
return o -> o.longValue() > value.longValue();
}

public static <T> Function<T, Iterable<T>> asList(final Class<T> type) {
return Collections::singletonList;
}
Expand Down
Loading

0 comments on commit 5558125

Please sign in to comment.