diff --git a/impl/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java b/impl/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java index 684ac70ef894..107ab84f0e19 100644 --- a/impl/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java +++ b/impl/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java @@ -55,7 +55,7 @@ class ProjectModelResolverTest extends AbstractMavenProjectTestCase { } @Test - void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { + void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() { final Parent parent = new Parent(); parent.setGroupId("org.apache"); parent.setArtifactId("apache"); @@ -70,7 +70,7 @@ void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exce } @Test - void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { + void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() { final Parent parent = new Parent(); parent.setGroupId("org.apache"); parent.setArtifactId("apache"); @@ -84,7 +84,7 @@ void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound } @Test - void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { + void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() { final Parent parent = new Parent(); parent.setGroupId("org.apache"); parent.setArtifactId("apache"); @@ -97,6 +97,22 @@ void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUppe assertEquals("The requested parent version range '[1,)' does not specify an upper bound", e.getMessage()); } + @Test + void testResolveParentThrowsUnresolvableModelExceptionWhenUsingWrongRangeFormat() { + final Parent parent = new Parent(); + parent.setGroupId("org.apache"); + parent.setArtifactId("apache"); + parent.setVersion("[1:2)"); + + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel(parent), + "Expected 'UnresolvableModelException' not thrown."); + assertEquals( + "Failed to resolve version range for org.apache:apache:pom:[1:2): Invalid version range [1:2), single version must be surrounded by []", + e.getMessage()); + } + @Test void testResolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception { final Parent parent = new Parent(); @@ -120,7 +136,7 @@ void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() th } @Test - void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws Exception { + void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() { final Dependency dependency = new Dependency(); dependency.setGroupId("org.apache"); dependency.setArtifactId("apache"); @@ -135,7 +151,7 @@ void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws } @Test - void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception { + void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() { final Dependency dependency = new Dependency(); dependency.setGroupId("org.apache"); dependency.setArtifactId("apache"); @@ -149,7 +165,7 @@ void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionF } @Test - void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception { + void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() { final Dependency dependency = new Dependency(); dependency.setGroupId("org.apache"); dependency.setArtifactId("apache"); @@ -162,6 +178,22 @@ void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithout assertEquals("The requested dependency version range '[1,)' does not specify an upper bound", e.getMessage()); } + @Test + void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingWrongRangeFormat() { + final Dependency dependency = new Dependency(); + dependency.setGroupId("org.apache"); + dependency.setArtifactId("apache"); + dependency.setVersion("[2:3)"); + + UnresolvableModelException e = assertThrows( + UnresolvableModelException.class, + () -> newModelResolver().resolveModel(dependency), + "Expected 'UnresolvableModelException' not thrown."); + assertEquals( + "Failed to resolve version range for org.apache:apache:pom:[2:3): Invalid version range [2:3), single version must be surrounded by []", + e.getMessage()); + } + @Test void testResolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception { final Dependency dependency = new Dependency();