gnodet commented on code in PR #13075:
URL: https://github.com/apache/maven/pull/13075#discussion_r3957016997


##########
impl/maven-core/src/test/java/org/apache/maven/plugin/internal/PluginDependenciesResolverDefaultMethodsTest.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.plugin.internal;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.graph.DependencyFilter;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.DependencyRequest;
+import org.eclipse.aether.resolution.DependencyResult;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@link PluginDependenciesResolver} is documented as internal, but tools 
that embed Maven — most visibly
+ * IntelliJ IDEA's {@code Maven40PluginDependenciesResolver} — implement it 
out of tree and are compiled against
+ * one Maven version while running against another. When {@code 
resolveCoreExtensionAndFlatten} and
+ * {@code resolvePluginAndFlatten} were forward-ported from Maven 3.10.0 as 
<em>abstract</em> methods, every such
+ * implementation started failing with {@code AbstractMethodError} as soon as 
core invoked them.
+ *
+ * <p>These tests pin the compatibility contract: an implementation providing 
only the methods that existed before
+ * the forward port must remain a legal implementation, and the two newer 
methods must stay {@code default}.
+ */
+class PluginDependenciesResolverDefaultMethodsTest {
+
+    private static final DependencyResult RESULT = new DependencyResult(new 
DependencyRequest());
+
+    /**
+     * Implements exactly the method set of the pre-forward-port interface — 
nothing more. This class failing to
+     * compile <em>is</em> the regression: it means the two newer methods went 
back to being abstract.
+     */
+    private static final class LegacyResolver implements 
PluginDependenciesResolver {
+
+        private Plugin plugin;
+        private Artifact pluginArtifact;
+        private DependencyFilter dependencyFilter;
+        private List<RemoteRepository> repositories;
+        private RepositorySystemSession session;
+
+        @Override
+        public Artifact resolve(Plugin plugin, List<RemoteRepository> 
repositories, RepositorySystemSession session) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public org.eclipse.aether.graph.DependencyNode resolve(
+                Plugin plugin,
+                Artifact pluginArtifact,
+                DependencyFilter dependencyFilter,
+                List<RemoteRepository> repositories,
+                RepositorySystemSession session) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public DependencyResult resolvePlugin(
+                Plugin plugin,
+                Artifact pluginArtifact,
+                DependencyFilter dependencyFilter,
+                List<RemoteRepository> repositories,
+                RepositorySystemSession session) {
+            this.plugin = plugin;
+            this.pluginArtifact = pluginArtifact;
+            this.dependencyFilter = dependencyFilter;
+            this.repositories = repositories;
+            this.session = session;
+            return RESULT;
+        }
+    }
+
+    @Test
+    void resolvePluginAndFlattenDelegatesToResolvePlugin() throws 
PluginResolutionException {
+        LegacyResolver resolver = new LegacyResolver();
+        Plugin plugin = new Plugin();
+        Artifact artifact = new DefaultArtifact("g:a:1.0");
+        DependencyFilter filter = (node, parents) -> true;
+        List<RemoteRepository> repositories = List.of();
+
+        assertSame(RESULT, resolver.resolvePluginAndFlatten(plugin, artifact, 
filter, repositories, null));
+
+        assertSame(plugin, resolver.plugin);
+        assertSame(artifact, resolver.pluginArtifact);
+        assertSame(filter, resolver.dependencyFilter);
+        assertSame(repositories, resolver.repositories);
+        assertNull(resolver.session);
+    }
+
+    @Test
+    void resolveCoreExtensionAndFlattenDelegatesToResolvePlugin() throws 
PluginResolutionException {
+        LegacyResolver resolver = new LegacyResolver();
+        Plugin plugin = new Plugin();
+        DependencyFilter filter = (node, parents) -> true;
+        List<RemoteRepository> repositories = List.of();
+
+        assertSame(RESULT, resolver.resolveCoreExtensionAndFlatten(plugin, 
filter, repositories, null));
+
+        assertSame(plugin, resolver.plugin);
+        assertNull(resolver.pluginArtifact, "the extension's main artifact is 
resolved from the plugin GAV");
+        assertSame(filter, resolver.dependencyFilter);
+        assertSame(repositories, resolver.repositories);

Review Comment:
   🔍 **Nit — session forwarding not tested:** `resolveCoreExtensionAndFlatten` 
is called with `null` for the session, but the test has no assertion that the 
session is passed through to `resolvePlugin`. A non-null session should be 
passed and verified with `assertSame(session, resolver.session)` — same pattern 
as the sibling test.



##########
impl/maven-core/src/test/java/org/apache/maven/plugin/internal/PluginDependenciesResolverDefaultMethodsTest.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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.plugin.internal;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.graph.DependencyFilter;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.DependencyRequest;
+import org.eclipse.aether.resolution.DependencyResult;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@link PluginDependenciesResolver} is documented as internal, but tools 
that embed Maven — most visibly
+ * IntelliJ IDEA's {@code Maven40PluginDependenciesResolver} — implement it 
out of tree and are compiled against
+ * one Maven version while running against another. When {@code 
resolveCoreExtensionAndFlatten} and
+ * {@code resolvePluginAndFlatten} were forward-ported from Maven 3.10.0 as 
<em>abstract</em> methods, every such
+ * implementation started failing with {@code AbstractMethodError} as soon as 
core invoked them.
+ *
+ * <p>These tests pin the compatibility contract: an implementation providing 
only the methods that existed before
+ * the forward port must remain a legal implementation, and the two newer 
methods must stay {@code default}.
+ */
+class PluginDependenciesResolverDefaultMethodsTest {
+
+    private static final DependencyResult RESULT = new DependencyResult(new 
DependencyRequest());
+
+    /**
+     * Implements exactly the method set of the pre-forward-port interface — 
nothing more. This class failing to
+     * compile <em>is</em> the regression: it means the two newer methods went 
back to being abstract.
+     */
+    private static final class LegacyResolver implements 
PluginDependenciesResolver {
+
+        private Plugin plugin;
+        private Artifact pluginArtifact;
+        private DependencyFilter dependencyFilter;
+        private List<RemoteRepository> repositories;
+        private RepositorySystemSession session;
+
+        @Override
+        public Artifact resolve(Plugin plugin, List<RemoteRepository> 
repositories, RepositorySystemSession session) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public org.eclipse.aether.graph.DependencyNode resolve(
+                Plugin plugin,
+                Artifact pluginArtifact,
+                DependencyFilter dependencyFilter,
+                List<RemoteRepository> repositories,
+                RepositorySystemSession session) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public DependencyResult resolvePlugin(
+                Plugin plugin,
+                Artifact pluginArtifact,
+                DependencyFilter dependencyFilter,
+                List<RemoteRepository> repositories,
+                RepositorySystemSession session) {
+            this.plugin = plugin;
+            this.pluginArtifact = pluginArtifact;
+            this.dependencyFilter = dependencyFilter;
+            this.repositories = repositories;
+            this.session = session;
+            return RESULT;
+        }
+    }
+
+    @Test
+    void resolvePluginAndFlattenDelegatesToResolvePlugin() throws 
PluginResolutionException {
+        LegacyResolver resolver = new LegacyResolver();
+        Plugin plugin = new Plugin();
+        Artifact artifact = new DefaultArtifact("g:a:1.0");
+        DependencyFilter filter = (node, parents) -> true;
+        List<RemoteRepository> repositories = List.of();
+
+        assertSame(RESULT, resolver.resolvePluginAndFlatten(plugin, artifact, 
filter, repositories, null));
+
+        assertSame(plugin, resolver.plugin);
+        assertSame(artifact, resolver.pluginArtifact);
+        assertSame(filter, resolver.dependencyFilter);
+        assertSame(repositories, resolver.repositories);
+        assertNull(resolver.session);

Review Comment:
   🔍 **Nit — trivial session assertion:** `null` is passed as the session 
argument and this assertion checks that `null` comes out the other side — which 
is guaranteed regardless of whether the default method actually forwards the 
argument. To make this test meaningful, pass a non-null mock or stub session 
and assert `assertSame`:
   
   ```suggestion
           assertNull(resolver.session);
   ```
   
   Suggested improvement (cannot be a one-click suggestion due to the required 
change in the call site at line 104):
   
   ```java
   // line 103-110
   RepositorySystemSession session = mock(RepositorySystemSession.class);
   assertSame(RESULT, resolver.resolvePluginAndFlatten(plugin, artifact, 
filter, repositories, session));
   
   assertSame(plugin, resolver.plugin);
   assertSame(artifact, resolver.pluginArtifact);
   assertSame(filter, resolver.dependencyFilter);
   assertSame(repositories, resolver.repositories);
   assertSame(session, resolver.session);
   ```
   (Add `import static org.mockito.Mockito.mock;` or use 
`Mockito.mock(RepositorySystemSession.class)` — the project already has Mockito 
on the test classpath.)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to