Skip to content

Commit 9386909

Browse files
committed
fix: Mockito inline mocking for Java 21+
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.
1 parent 261554b commit 9386909

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,23 @@
163163
</execution>
164164
</executions>
165165
</plugin>
166+
<plugin>
167+
<groupId>org.apache.maven.plugins</groupId>
168+
<artifactId>maven-dependency-plugin</artifactId>
169+
<executions>
170+
<execution>
171+
<goals>
172+
<goal>properties</goal>
173+
</goals>
174+
</execution>
175+
</executions>
176+
</plugin>
166177
<plugin>
167178
<groupId>org.apache.maven.plugins</groupId>
168179
<artifactId>maven-surefire-plugin</artifactId>
169180
<version>${maven-surefire-plugin.version}</version>
170181
<configuration>
171-
<argLine>${surefireArgLine}</argLine>
172-
182+
<argLine>-javaagent:${org.mockito:mockito-core:jar}</argLine>
173183
<useFile>false</useFile>
174184
<trimStackTrace>false</trimStackTrace>
175185

0 commit comments

Comments
 (0)