Skip to content

Commit

Permalink
Merge pull request quarkusio#23112 from famod/ct-mockito-config-2
Browse files Browse the repository at this point in the history
Load MockitoConfiguration parent-first to make it work in continuous testing
  • Loading branch information
stuartwdouglas authored Jan 23, 2022
2 parents c6233ad + dfcb955 commit 685d832
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
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

0 comments on commit 685d832

Please sign in to comment.