gnodet-bot commented on code in PR #2348:
URL: https://github.com/apache/maven-resolver/pull/2348#discussion_r4652195536


##########
maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultTransporterProviderTest.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.eclipse.aether.internal.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.internal.test.util.TestUtils;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.spi.connector.transport.Transporter;
+import org.eclipse.aether.spi.connector.transport.TransporterFactory;
+import org.eclipse.aether.transfer.NoTransporterException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+class DefaultTransporterProviderTest {
+
+    private static final class StubTransporterFactory implements 
TransporterFactory {
+
+        private final String name;
+
+        private final boolean canHandle;
+
+        private final Transporter transporter;
+
+        private int newInstanceCalls;
+
+        private String lastProtocol;
+
+        StubTransporterFactory(String name, boolean canHandle, Transporter 
transporter) {
+            this.name = name;
+            this.canHandle = canHandle;
+            this.transporter = transporter;
+        }
+
+        @Override
+        public boolean canHandle(String protocol) {
+            lastProtocol = protocol;
+            return canHandle;
+        }
+
+        @Override
+        public String getDescription() {
+            return name + " transporter";
+        }
+
+        @Override
+        public Transporter newInstance(RepositorySystemSession session, 
RemoteRepository repository)
+                throws NoTransporterException {
+            newInstanceCalls++;
+            if (transporter == null) {
+                throw new NoTransporterException(repository);
+            }
+            return transporter;
+        }
+
+        @Override
+        public float getPriority() {
+            return 1;
+        }
+    }
+
+    @Test
+    void skipsFactoryThatCannotHandleProtocol() {
+        Transporter usable = mock(Transporter.class);
+        StubTransporterFactory declining = new 
StubTransporterFactory("declining", false, mock(Transporter.class));
+        StubTransporterFactory accepting = new 
StubTransporterFactory("accepting", true, usable);
+
+        Map<String, TransporterFactory> factories = new HashMap<>();
+        factories.put("declining", declining);

Review Comment:
   ⚠️ **Non-deterministic iteration order** — `HashMap` does not guarantee 
traversal order. `PrioritizedComponents.add()` uses `HashMap.values()` 
iteration to assign insertion indices (which break priority ties), so the 
factory that happens to come out first gets the lower index and higher 
effective priority. The assertion `assertEquals("https", 
declining.lastProtocol)` on line 100 requires `"declining"` to be iterated 
before `"accepting"`, which is currently true by coincidence (current JDK hash 
values happen to produce that ordering) but is not contractually guaranteed.
   
   ```suggestion
           Map<String, TransporterFactory> factories = new LinkedHashMap<>();
   ```



##########
maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultTransporterProviderTest.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.eclipse.aether.internal.impl;
+
+import java.util.HashMap;
+import java.util.Map;

Review Comment:
   Update the import to match the fix above:
   
   ```suggestion
   import java.util.LinkedHashMap;
   ```



-- 
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