Copilot commented on code in PR #271:
URL:
https://github.com/apache/maven-artifact-plugin/pull/271#discussion_r4480266243
##########
src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java:
##########
@@ -305,6 +299,20 @@ private String[] checkArtifact(
return new String[] {actualFilename, null};
}
+ // package-private for tests
+ static String findIssue(String actualLength, String actualSha512, String
referenceLength, String referenceSha512) {
+ if (referenceLength == null) {
+ return "missing reference file";
+ }
+ if (!Objects.equals(actualLength, referenceLength)) {
+ return "size";
+ }
+ if (!Objects.equals(actualSha512, referenceSha512)) {
+ return "sha512";
+ }
+ return null;
+ }
Review Comment:
The new null-safe branches for sha512 comparison aren’t covered by the added
test. Please add unit tests for (a) missing `actualSha512` (with matching
lengths) returning `\"sha512\"`, and optionally (b) both sha512 values missing
resulting in `null` (if that is intended behavior). This ensures the NPE fix is
exercised for both fields.
##########
src/test/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojoFindIssueTest.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.plugins.artifact.buildinfo;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class CompareMojoFindIssueTest {
+ @Test
+ void reportsSizeMismatchWhenActualLengthIsMissing() {
+ assertEquals("size", CompareMojo.findIssue(null, null, "1234",
"abcd"));
Review Comment:
This test currently passes a sha512 mismatch as well (`actualSha512` is
null, `referenceSha512` is \"abcd\"), but relies on the implementation checking
size before sha512. To keep the test focused and less order-dependent, set
sha512 values to match (or both null) so the only asserted mismatch reason is
the missing length.
--
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]