cmunier commented on code in PR #13407: URL: https://github.com/apache/maven/pull/13407#discussion_r4248166903
########## impl/maven-impl/src/test/java/org/apache/maven/impl/resolver/validator/MavenValidatorFactoryTest.java: ########## @@ -0,0 +1,98 @@ +/* + * 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.impl.resolver.validator; + +import java.util.Locale; + +import org.apache.maven.api.Constants; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.spi.validator.Validator; +import org.eclipse.aether.spi.validator.ValidatorFactory; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests {@link MavenValidatorFactory}. + */ +class MavenValidatorFactoryTest { + + private static final DefaultArtifact SLASH_CLASSIFIER = new DefaultArtifact("g:a:jar:lib/foo.jar:1.0"); + + private final MavenValidatorFactory factory = new MavenValidatorFactory(); + + private Validator newValidator(String level) { + DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false); + if (level != null) { + session.setConfigProperty(Constants.MAVEN_RESOLVER_VALIDATION, level); + } + return factory.newInstance(session); + } + + @Test + void defaultWhenUnset() { + Validator validator = newValidator(null); + assertInstanceOf(MavenValidator.class, validator); + assertThrows(IllegalArgumentException.class, () -> validator.validateArtifact(SLASH_CLASSIFIER)); + } + + @Test + void defaultLevelIgnoresCase() { + for (String level : new String[] {"default", "DEFAULT", "Default"}) { + Validator validator = newValidator(level); + assertInstanceOf(MavenValidator.class, validator, level); + assertThrows(IllegalArgumentException.class, () -> validator.validateArtifact(SLASH_CLASSIFIER), level); + } + } + + @Test + void mildLevelIgnoresCase() { + for (String level : new String[] {"mild", "MILD", "Mild", " mild "}) { Review Comment: If you prefer, I could implement this before merging. Just wanted to check, because you already approved the pull request. -- 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]
