Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load MockitoConfiguration parent-first to make it work in continuous testing #23112

Merged
merged 1 commit into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,11 @@
<artifactId>quarkus-junit5-mockito</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito-config</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-vertx</artifactId>
Expand Down
1 change: 1 addition & 0 deletions core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<parentFirstArtifact>io.quarkus:quarkus-class-change-agent</parentFirstArtifact>
<parentFirstArtifact>org.jacoco:org.jacoco.agent:runtime</parentFirstArtifact>
<parentFirstArtifact>io.quarkus:quarkus-bootstrap-gradle-resolver</parentFirstArtifact>
<parentFirstArtifact>io.quarkus:quarkus-junit5-mockito-config</parentFirstArtifact>

<!-- RestAssured uses groovy, which seems to do some things with soft references that
prevent the ClassLoader from being GC'ed, see https://github.com/quarkusio/quarkus/issues/12498 -->
Expand Down
27 changes: 27 additions & 0 deletions test-framework/junit5-mockito-config/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-framework</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-junit5-mockito-config</artifactId>
<name>Quarkus - Test framework - JUnit 5 - Mockito Config</name>
<description>
Contains a MockitoConfiguration that has to be loaded parent-first to work in continuous testing.
It is separated from junit5-mockito to minimize the blast radius.
</description>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import org.mockito.stubbing.Answer;

import io.quarkus.test.junit.mockito.internal.MutinyAnswer;

public class MockitoConfiguration extends DefaultMockitoConfiguration {

@SuppressWarnings("unchecked")
Expand All @@ -14,7 +12,7 @@ public Answer<Object> getDefaultAnswer() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
// we need to load it from the TCCL (QuarkusClassLoader) instead of our class loader (JUnit CL)
Class<?> mutinyAnswer = cl.loadClass(MutinyAnswer.class.getName());
Class<?> mutinyAnswer = cl.loadClass("io.quarkus.test.junit.mockito.internal.MutinyAnswer");
return (Answer<Object>) mutinyAnswer.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException | IllegalAccessException
| InstantiationException | NoSuchMethodException | InvocationTargetException e) {
Expand Down
7 changes: 7 additions & 0 deletions test-framework/junit5-mockito/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
</dependency>
<!-- Contains the MockitoConfiguration that adds MutinyAnswer as a default answer.
The dependency is in this direction so that users don't need to worry about it
and only have to add this dependency (quarkus-junit5-mockito), but not ...-config. -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito-config</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion test-framework/junit5-properties/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<artifactId>quarkus-junit5-properties</artifactId>
<name>Quarkus - Test Framework - JUnit 5 - Properties</name>
<description>
Contains junit-platform.properties in a "use-excludable" way
Contains junit-platform.properties in a "user-excludable" way
until https://github.com/junit-team/junit5/issues/2794 is available.
</description>

Expand Down
1 change: 1 addition & 0 deletions test-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<module>junit5-properties</module>
<module>junit5</module>
<module>junit5-mockito</module>
<module>junit5-mockito-config</module>
<module>junit5-vertx</module>
<module>amazon-lambda</module>
<module>arquillian</module>
Expand Down