Skip to content

Commit dfcb955

Browse files
committed
Load MockitoConfiguration parent-first to make it work in continuous testing
Moves the class to a separate new module to reduce the blast radius.
1 parent c6233ad commit dfcb955

File tree

7 files changed

+43
-4
lines changed

7 files changed

+43
-4
lines changed

bom/application/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,11 @@
25762576
<artifactId>quarkus-junit5-mockito</artifactId>
25772577
<version>${project.version}</version>
25782578
</dependency>
2579+
<dependency>
2580+
<groupId>io.quarkus</groupId>
2581+
<artifactId>quarkus-junit5-mockito-config</artifactId>
2582+
<version>${project.version}</version>
2583+
</dependency>
25792584
<dependency>
25802585
<groupId>io.quarkus</groupId>
25812586
<artifactId>quarkus-junit5-vertx</artifactId>

core/runtime/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<parentFirstArtifact>io.quarkus:quarkus-class-change-agent</parentFirstArtifact>
171171
<parentFirstArtifact>org.jacoco:org.jacoco.agent:runtime</parentFirstArtifact>
172172
<parentFirstArtifact>io.quarkus:quarkus-bootstrap-gradle-resolver</parentFirstArtifact>
173+
<parentFirstArtifact>io.quarkus:quarkus-junit5-mockito-config</parentFirstArtifact>
173174

174175
<!-- RestAssured uses groovy, which seems to do some things with soft references that
175176
prevent the ClassLoader from being GC'ed, see https://github.com/quarkusio/quarkus/issues/12498 -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.quarkus</groupId>
9+
<artifactId>quarkus-test-framework</artifactId>
10+
<version>999-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>quarkus-junit5-mockito-config</artifactId>
14+
<name>Quarkus - Test framework - JUnit 5 - Mockito Config</name>
15+
<description>
16+
Contains a MockitoConfiguration that has to be loaded parent-first to work in continuous testing.
17+
It is separated from junit5-mockito to minimize the blast radius.
18+
</description>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.mockito</groupId>
23+
<artifactId>mockito-core</artifactId>
24+
</dependency>
25+
</dependencies>
26+
27+
</project>

test-framework/junit5-mockito/src/main/java/org/mockito/configuration/MockitoConfiguration.java test-framework/junit5-mockito-config/src/main/java/org/mockito/configuration/MockitoConfiguration.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import org.mockito.stubbing.Answer;
66

7-
import io.quarkus.test.junit.mockito.internal.MutinyAnswer;
8-
97
public class MockitoConfiguration extends DefaultMockitoConfiguration {
108

119
@SuppressWarnings("unchecked")
@@ -14,7 +12,7 @@ public Answer<Object> getDefaultAnswer() {
1412
ClassLoader cl = Thread.currentThread().getContextClassLoader();
1513
try {
1614
// we need to load it from the TCCL (QuarkusClassLoader) instead of our class loader (JUnit CL)
17-
Class<?> mutinyAnswer = cl.loadClass(MutinyAnswer.class.getName());
15+
Class<?> mutinyAnswer = cl.loadClass("io.quarkus.test.junit.mockito.internal.MutinyAnswer");
1816
return (Answer<Object>) mutinyAnswer.getDeclaredConstructor().newInstance();
1917
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException | IllegalAccessException
2018
| InstantiationException | NoSuchMethodException | InvocationTargetException e) {

test-framework/junit5-mockito/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
<groupId>io.quarkus</groupId>
1919
<artifactId>quarkus-junit5</artifactId>
2020
</dependency>
21+
<!-- Contains the MockitoConfiguration that adds MutinyAnswer as a default answer.
22+
The dependency is in this direction so that users don't need to worry about it
23+
and only have to add this dependency (quarkus-junit5-mockito), but not ...-config. -->
24+
<dependency>
25+
<groupId>io.quarkus</groupId>
26+
<artifactId>quarkus-junit5-mockito-config</artifactId>
27+
</dependency>
2128
<dependency>
2229
<groupId>io.quarkus</groupId>
2330
<artifactId>quarkus-arc-deployment</artifactId>

test-framework/junit5-properties/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<artifactId>quarkus-junit5-properties</artifactId>
1414
<name>Quarkus - Test Framework - JUnit 5 - Properties</name>
1515
<description>
16-
Contains junit-platform.properties in a "use-excludable" way
16+
Contains junit-platform.properties in a "user-excludable" way
1717
until https://github.com/junit-team/junit5/issues/2794 is available.
1818
</description>
1919

test-framework/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<module>junit5-properties</module>
2929
<module>junit5</module>
3030
<module>junit5-mockito</module>
31+
<module>junit5-mockito-config</module>
3132
<module>junit5-vertx</module>
3233
<module>amazon-lambda</module>
3334
<module>arquillian</module>

0 commit comments

Comments
 (0)