Added some tests; also add test for MNG-3001 where it's claimed that [1.0,) includes 1.0-SNAPSHOT, which it doesn't.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@547874 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kenney Westerhof 2007-06-16 07:20:35 +00:00
parent 3efdafe6a8
commit 811de4eb41
2 changed files with 51 additions and 0 deletions

View File

@ -41,6 +41,7 @@ import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.PlexusTestCase;
@ -667,6 +668,24 @@ public class DefaultArtifactCollectorTest
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact} ), res.getArtifacts() );
}
public void testSnapshotNotIncluded()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
ArtifactSpec a = createArtifact( "a", "1.0" );
a.addDependency( "b", "[1.0,)" );
createArtifact( "b", "1.0-SNAPSHOT" );
try
{
ArtifactResolutionResult res = collect( a );
fail( "Expected b not to resolve: " + res );
}
catch ( OverConstrainedVersionException e )
{
assertTrue( e.getMessage().indexOf( "[1.0-SNAPSHOT]" ) < e.getMessage().indexOf( "[1.0,)" ) );
}
}
private Artifact getArtifact( String id, Set artifacts )
{
for ( Iterator i = artifacts.iterator(); i.hasNext(); )

View File

@ -144,6 +144,9 @@ public class VersionRangeTest
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
range = VersionRange.createFromVersionSpec( "[1.0,)" );
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
}
public void testInvalidRanges()
@ -658,4 +661,33 @@ public class VersionRangeTest
// expected
}
}
public void testContains() throws InvalidVersionSpecificationException
{
ArtifactVersion actualVersion = new DefaultArtifactVersion( "2.0.5" );
assertTrue( enforceVersion( "2.0.5", actualVersion ) );
assertTrue( enforceVersion( "2.0.4", actualVersion ) );
assertTrue( enforceVersion( "[2.0.5]", actualVersion ) );
assertFalse( enforceVersion( "[2.0.6,)", actualVersion ) );
assertFalse( enforceVersion( "[2.0.6]", actualVersion ) );
assertTrue( enforceVersion( "[2.0,2.1]", actualVersion ) );
assertFalse( enforceVersion( "[2.0,2.0.3]", actualVersion ) );
assertTrue( enforceVersion( "[2.0,2.0.5]", actualVersion ) );
assertFalse( enforceVersion( "[2.0,2.0.5)", actualVersion ) );
}
public boolean enforceVersion( String requiredVersionRange, ArtifactVersion actualVersion )
throws InvalidVersionSpecificationException
{
VersionRange vr = null;
vr = VersionRange.createFromVersionSpec( requiredVersionRange );
return vr.containsVersion( actualVersion );
}
public void testOrder0()
{
// assertTrue( new DefaultArtifactVersion( "1.0-alpha10" ).compareTo( new DefaultArtifactVersion( "1.0-alpha1" ) ) > 0 );
}
}