You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/07/24 15:27:35 UTC
Re: [PR] [MNG-11449] Add Mockito javaagent for maven-cli tests [maven]
gnodet commented on code in PR #11743:
URL: https://github.com/apache/maven/pull/11743#discussion_r3646435988
##########
impl/maven-cli/pom.xml:
##########
@@ -308,6 +308,7 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <argLine>-Xmx256m @{jacocoArgLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
Review Comment:
Two issues with this line:
1. **Overrides parent argLine**: On master (post-PR #12369), the parent `pluginManagement` sets `argLine` to `${argLine.xmx} @{jacocoArgLine} ${argLine.mockito}`, composing three properties. This per-module override replaces that entire mechanism, losing the ability to set `argLine.xmx` or `argLine.mockito` via profiles.
2. **Eager interpolation**: Uses `${org.mockito:mockito-core:jar}` which resolves at POM parse time — before `dependency:properties` runs. PR #12369 explicitly fixed this project-wide by switching to late-binding `@{org.mockito:mockito-core:jar}`.
```suggestion
<argLine>${argLine.xmx} @{jacocoArgLine} ${argLine.mockito}</argLine>
```
(But even this is unnecessary — the parent already provides it.)
##########
impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/MockitoAgentConfigurationTest.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.cling.invoker.mvnup.goals;
+
+import java.lang.management.ManagementFactory;
+import java.util.List;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@DisplayName("Mockito agent configuration")
+class MockitoAgentConfigurationTest {
+
+ @Test
+ @DisplayName("should run tests with mockito configured as javaagent")
+ void shouldRunTestsWithMockitoAsJavaAgent() {
Review Comment:
This test verifies build infrastructure configuration (javaagent presence) rather than production code. If the Mockito javaagent were missing, every test using `mock()` or `@Mock` on final classes would fail with a clear `IncompatibleClassChangeError` or `MockitoException`, making this infrastructure check redundant.
This test also does not exist on master after #12369.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org