gnodet-bot commented on code in PR #2364: URL: https://github.com/apache/maven-resolver/pull/2364#discussion_r4731010887
########## maven-resolver-util/src/test/java/org/eclipse/aether/util/version/VersionComparisonDataTest.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.util.version; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.eclipse.aether.version.Version; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Runs the language-independent version comparison cases from + * {@code version-comparison-cases.tsv} against {@link GenericVersion}. + * + * <p>The data file is intentionally plain text: other version schemes (Maven core's + * ComparableVersion, Gradle, semver libraries, ...) can consume the same cases without + * depending on this test suite.</p> + */ +class VersionComparisonDataTest extends AbstractVersionTest { + + private static final String DATA = "/version-comparison-cases.tsv"; + + @Override + protected Version newVersion(String version) { + return new GenericVersion(version); + } + + static Stream<Arguments> cases() throws IOException { + List<Arguments> result = new ArrayList<>(); + + try (InputStream in = VersionComparisonDataTest.class.getResourceAsStream(DATA)) { + assertNotNull(in, "Missing test data " + DATA); Review Comment: 💡 **[Low] `assertNotNull` in a `@MethodSource` provider throws `AssertionError`** This is the same anti-pattern as the previous `assertEquals` finding on malformed rows — when the resource file is not found, `assertNotNull` throws `AssertionError`, which JUnit wraps as `"Could not provide arguments"` rather than a clean test failure. The malformed-row case was correctly fixed with `IllegalArgumentException`; this check should be consistent: ```suggestion if (in == null) { throw new IllegalArgumentException("Missing test data: " + DATA); } ``` ########## maven-resolver-util/src/test/java/org/eclipse/aether/util/version/VersionComparisonDataTest.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.util.version; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.eclipse.aether.version.Version; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Runs the language-independent version comparison cases from + * {@code version-comparison-cases.tsv} against {@link GenericVersion}. + * + * <p>The data file is intentionally plain text: other version schemes (Maven core's + * ComparableVersion, Gradle, semver libraries, ...) can consume the same cases without + * depending on this test suite.</p> + */ +class VersionComparisonDataTest extends AbstractVersionTest { + + private static final String DATA = "/version-comparison-cases.tsv"; + + @Override + protected Version newVersion(String version) { + return new GenericVersion(version); + } + + static Stream<Arguments> cases() throws IOException { + List<Arguments> result = new ArrayList<>(); + + try (InputStream in = VersionComparisonDataTest.class.getResourceAsStream(DATA)) { + assertNotNull(in, "Missing test data " + DATA); + + BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); Review Comment: 💡 **[Low] `BufferedReader` is not managed by try-with-resources** `BufferedReader` is allocated inside the `try` block but is not declared as a managed resource. If an exception occurs mid-read, only `InputStream` is closed by try-with-resources; `BufferedReader` is abandoned. Wrapping both in a single try-with-resources declaration is idiomatic and correct: ```suggestion try (InputStream in = VersionComparisonDataTest.class.getResourceAsStream(DATA); BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { if (in == null) { throw new IllegalArgumentException("Missing test data: " + DATA); } ``` -- 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]
