Skip to content

Commit eae3840

Browse files
fix: Mockito inline mocking for Java 21+ (#207)
Before this fix the execution of the maven surefire plugin with Java 21 logged warnings that mockito should be added as a java agent, because the self-attaching won't be supported in future java releases. In Java 24 the test just broke. This problem is solved by modifying the pom.xml of the parent and doing this changes: * Adding mockito as a java agent. * Removing the surefireArgLine from the properties. This can be added back when it's needed (for example when JaCoCo will be used). Furthermore, the pom.xml in the mcp-spring-* modules now have the byte-buddy dependency included, as the test would otherwise break when trying to mock McpSchema#CreateMessageRequest. Fixes #187 Co-authored-by: Dariusz Jędrzejczyk <[email protected]>
1 parent e34babb commit eae3840

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

mcp-spring/mcp-spring-webflux/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
<version>${mockito.version}</version>
8383
<scope>test</scope>
8484
</dependency>
85+
<dependency>
86+
<groupId>net.bytebuddy</groupId>
87+
<artifactId>byte-buddy</artifactId>
88+
<version>${byte-buddy.version}</version>
89+
<scope>test</scope>
90+
</dependency>
8591
<dependency>
8692
<groupId>io.projectreactor</groupId>
8793
<artifactId>reactor-test</artifactId>

mcp-spring/mcp-spring-webmvc/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
<version>${mockito.version}</version>
7878
<scope>test</scope>
7979
</dependency>
80+
<dependency>
81+
<groupId>net.bytebuddy</groupId>
82+
<artifactId>byte-buddy</artifactId>
83+
<version>${byte-buddy.version}</version>
84+
<scope>test</scope>
85+
</dependency>
8086
<dependency>
8187
<groupId>org.testcontainers</groupId>
8288
<artifactId>junit-jupiter</artifactId>

pom.xml

+13-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<java.version>17</java.version>
5858
<maven.compiler.source>17</maven.compiler.source>
5959
<maven.compiler.target>17</maven.compiler.target>
60+
<surefireArgLine/>
6061

6162
<assert4j.version>3.26.3</assert4j.version>
6263
<junit.version>5.10.2</junit.version>
@@ -163,13 +164,23 @@
163164
</execution>
164165
</executions>
165166
</plugin>
167+
<plugin>
168+
<groupId>org.apache.maven.plugins</groupId>
169+
<artifactId>maven-dependency-plugin</artifactId>
170+
<executions>
171+
<execution>
172+
<goals>
173+
<goal>properties</goal>
174+
</goals>
175+
</execution>
176+
</executions>
177+
</plugin>
166178
<plugin>
167179
<groupId>org.apache.maven.plugins</groupId>
168180
<artifactId>maven-surefire-plugin</artifactId>
169181
<version>${maven-surefire-plugin.version}</version>
170182
<configuration>
171-
<argLine>${surefireArgLine}</argLine>
172-
183+
<argLine>${surefireArgLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
173184
<useFile>false</useFile>
174185
<trimStackTrace>false</trimStackTrace>
175186

0 commit comments

Comments
 (0)