[MNG-7035] Migrate unit tests to Unit 5

Signed-off-by: rfscholte <rfscholte@apache.org>
This commit is contained in:
Guillaume Nodet 2021-01-15 15:07:06 +01:00 committed by rfscholte
parent 83dc6909aa
commit bb916d0784
221 changed files with 3685 additions and 2515 deletions

View File

@ -19,31 +19,33 @@ package org.apache.maven.settings;
* under the License.
*/
import junit.framework.TestCase;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests that the global settings.xml shipped with the distribution is in good state.
*
* @author Benjamin Bentmann
*/
public class GlobalSettingsTest
extends TestCase
{
@Test
public void testValidGlobalSettings()
throws Exception
{
String basedir = System.getProperty( "basedir", System.getProperty( "user.dir" ) );
File globalSettingsFile = new File( basedir, "src/assembly/maven/conf/settings.xml" );
assertTrue( globalSettingsFile.getAbsolutePath(), globalSettingsFile.isFile() );
assertTrue( globalSettingsFile.isFile(), globalSettingsFile.getAbsolutePath() );
try ( Reader reader = new InputStreamReader( new FileInputStream( globalSettingsFile ), StandardCharsets.UTF_8) )
{

View File

@ -24,8 +24,10 @@ import java.util.List;
import java.util.Map;
import org.apache.maven.artifact.versioning.VersionRange;
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Tests {@link ArtifactUtils}.
@ -33,7 +35,6 @@ import junit.framework.TestCase;
* @author Benjamin Bentmann
*/
public class ArtifactUtilsTest
extends TestCase
{
private Artifact newArtifact( String aid )
@ -41,6 +42,7 @@ public class ArtifactUtilsTest
return new DefaultArtifact( "group", aid, VersionRange.createFromVersion( "1.0" ), "test", "jar", "tests", null );
}
@Test
public void testIsSnapshot()
{
assertEquals( false, ArtifactUtils.isSnapshot( null ) );
@ -52,6 +54,7 @@ public class ArtifactUtilsTest
assertEquals( false, ArtifactUtils.isSnapshot( "1.2.3-20090413X094722-2"));
}
@Test
public void testToSnapshotVersion()
{
assertEquals( "1.2.3", ArtifactUtils.toSnapshotVersion( "1.2.3" ) );
@ -63,6 +66,7 @@ public class ArtifactUtilsTest
/**
* Tests that the ordering of the map resembles the ordering of the input collection of artifacts.
*/
@Test
public void testArtifactMapByVersionlessIdOrdering()
throws Exception
{

View File

@ -19,13 +19,15 @@ package org.apache.maven.artifact;
* under the License.
*/
import junit.framework.TestCase;
import org.apache.maven.artifact.handler.ArtifactHandlerMock;
import org.apache.maven.artifact.versioning.VersionRange;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class DefaultArtifactTest
extends TestCase
{
private DefaultArtifact artifact;
@ -43,10 +45,10 @@ public class DefaultArtifactTest
private ArtifactHandlerMock artifactHandler;
protected void setUp()
@BeforeEach
public void setUp()
throws Exception
{
super.setUp();
artifactHandler = new ArtifactHandlerMock();
versionRange = VersionRange.createFromVersion( version );
artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler );
@ -55,6 +57,7 @@ public class DefaultArtifactTest
snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotVersionRange, scope, type, classifier, artifactHandler );
}
@Test
public void testGetVersionReturnsResolvedVersionOnSnapshot()
{
assertEquals( snapshotResolvedVersion, snapshotArtifact.getVersion() );
@ -65,53 +68,62 @@ public class DefaultArtifactTest
assertEquals( snapshotSpecVersion, snapshotArtifact.getBaseVersion() );
}
@Test
public void testGetDependencyConflictId()
{
assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
}
@Test
public void testGetDependencyConflictIdNullGroupId()
{
artifact.setGroupId( null );
assertEquals( null + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
}
@Test
public void testGetDependencyConflictIdNullClassifier()
{
artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler );
assertEquals( groupId + ":" + artifactId + ":" + type, artifact.getDependencyConflictId() );
}
@Test
public void testGetDependencyConflictIdNullScope()
{
artifact.setScope( null );
assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
}
@Test
public void testToString()
{
assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope,
artifact.toString() );
}
@Test
public void testToStringNullGroupId()
{
artifact.setGroupId( null );
assertEquals( artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString() );
}
@Test
public void testToStringNullClassifier()
{
artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler );
assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact.toString() );
}
@Test
public void testToStringNullScope()
{
artifact.setScope( null );
assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version, artifact.toString() );
}
@Test
public void testComparisonByVersion()
{
Artifact artifact1 = new DefaultArtifact( groupId, artifactId, VersionRange.createFromVersion( "5.0" ), scope,
@ -128,6 +140,7 @@ public class DefaultArtifactTest
assertTrue( artifact1.compareTo( artifact ) == 0 );
}
@Test
public void testNonResolvedVersionRangeConsistentlyYieldsNullVersions()
throws Exception
{

View File

@ -19,10 +19,8 @@ package org.apache.maven.artifact.versioning;
* under the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
@ -31,7 +29,9 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.regex.Pattern;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ComparableVersionIT
{
@ -60,11 +60,11 @@ public class ComparableVersionIT
try
{
assertEquals( "Unexpected exit code", 0, p.waitFor() );
assertEquals( 0, p.waitFor(), "Unexpected exit code" );
}
catch ( InterruptedException e )
{
fail( e.getMessage() );
throw new InterruptedIOException( e.toString() );
}
return FileVisitResult.TERMINATE;
}

View File

@ -21,7 +21,10 @@ package org.apache.maven.artifact.versioning;
import java.util.Locale;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test ComparableVersion.
@ -30,7 +33,6 @@ import junit.framework.TestCase;
*/
@SuppressWarnings( "unchecked" )
public class ComparableVersionTest
extends TestCase
{
private Comparable newComparable( String version )
{
@ -39,8 +41,8 @@ public class ComparableVersionTest
String parsedCanonical = new ComparableVersion( canonical ).getCanonical();
System.out.println( "canonical( " + version + " ) = " + canonical );
assertEquals( "canonical( " + version + " ) = " + canonical + " -> canonical: " + parsedCanonical, canonical,
parsedCanonical );
assertEquals( canonical, parsedCanonical,
"canonical( " + version + " ) = " + canonical + " -> canonical: " + parsedCanonical );
return ret;
}
@ -68,8 +70,8 @@ public class ComparableVersionTest
for ( int j = i; j < versions.length; j++ )
{
Comparable high = c[j];
assertTrue( "expected " + low + " < " + high, low.compareTo( high ) < 0 );
assertTrue( "expected " + high + " > " + low, high.compareTo( low ) > 0 );
assertTrue( low.compareTo( high ) < 0, "expected " + low + " < " + high );
assertTrue( high.compareTo( low ) > 0, "expected " + high + " > " + low );
}
}
}
@ -78,11 +80,11 @@ public class ComparableVersionTest
{
Comparable c1 = newComparable( v1 );
Comparable c2 = newComparable( v2 );
assertTrue( "expected " + v1 + " == " + v2, c1.compareTo( c2 ) == 0 );
assertTrue( "expected " + v2 + " == " + v1, c2.compareTo( c1 ) == 0 );
assertTrue( "expected same hashcode for " + v1 + " and " + v2, c1.hashCode() == c2.hashCode() );
assertTrue( "expected " + v1 + ".equals( " + v2 + " )", c1.equals( c2 ) );
assertTrue( "expected " + v2 + ".equals( " + v1 + " )", c2.equals( c1 ) );
assertTrue( c1.compareTo( c2 ) == 0, "expected " + v1 + " == " + v2 );
assertTrue( c2.compareTo( c1 ) == 0, "expected " + v2 + " == " + v1 );
assertTrue( c1.hashCode() == c2.hashCode(), "expected same hashcode for " + v1 + " and " + v2 );
assertTrue( c1.equals( c2 ), "expected " + v1 + ".equals( " + v2 + " )" );
assertTrue( c2.equals( c1 ), "expected " + v2 + ".equals( " + v1 + " )" );
}
private void checkVersionsArrayEqual( String[] array )
@ -97,20 +99,23 @@ public class ComparableVersionTest
{
Comparable c1 = newComparable( v1 );
Comparable c2 = newComparable( v2 );
assertTrue( "expected " + v1 + " < " + v2, c1.compareTo( c2 ) < 0 );
assertTrue( "expected " + v2 + " > " + v1, c2.compareTo( c1 ) > 0 );
assertTrue( c1.compareTo( c2 ) < 0, "expected " + v1 + " < " + v2 );
assertTrue( c2.compareTo( c1 ) > 0, "expected " + v2 + " > " + v1 );
}
@Test
public void testVersionsQualifier()
{
checkVersionsOrder( VERSIONS_QUALIFIER );
}
@Test
public void testVersionsNumber()
{
checkVersionsOrder( VERSIONS_NUMBER );
}
@Test
public void testVersionsEqual()
{
newComparable( "1.0-alpha" );
@ -164,6 +169,7 @@ public class ComparableVersionTest
checkVersionsEqual( "1m3", "1MILESTONE3" );
}
@Test
public void testVersionComparing()
{
checkVersionsOrder( "1", "2" );
@ -202,6 +208,7 @@ public class ComparableVersionTest
* see Netbeans issues <a href="https://netbeans.org/bugzilla/show_bug.cgi?id=240845">240845</a> and
* <a href="https://netbeans.org/bugzilla/show_bug.cgi?id=226100">226100</a>
*/
@Test
public void testMng5568()
{
String a = "6.1.0";
@ -216,6 +223,7 @@ public class ComparableVersionTest
/**
* Test <a href="https://jira.apache.org/jira/browse/MNG-6572">MNG-6572</a> optimization.
*/
@Test
public void testMng6572()
{
String a = "20190126.230843"; // resembles a SNAPSHOT
@ -235,6 +243,7 @@ public class ComparableVersionTest
* Test all versions are equal when starting with many leading zeroes regardless of string length
* (related to MNG-6572 optimization)
*/
@Test
public void testVersionEqualWithLeadingZeroes()
{
// versions with string lengths from 1 to 19
@ -267,6 +276,7 @@ public class ComparableVersionTest
* Test all "0" versions are equal when starting with many leading zeroes regardless of string length
* (related to MNG-6572 optimization)
*/
@Test
public void testVersionZeroEqualWithLeadingZeroes()
{
// versions with string lengths from 1 to 19
@ -299,6 +309,7 @@ public class ComparableVersionTest
* Test <a href="https://issues.apache.org/jira/browse/MNG-6964">MNG-6964</a> edge cases
* for qualifiers that start with "-0.", which was showing A == C and B == C but A &lt; B.
*/
@Test
public void testMng6964()
{
String a = "1-0.alpha";
@ -310,6 +321,7 @@ public class ComparableVersionTest
checkVersionsOrder( a, b ); // Should still be true
}
@Test
public void testLocaleIndependent()
{
Locale orig = Locale.getDefault();
@ -328,6 +340,7 @@ public class ComparableVersionTest
}
}
@Test
public void testReuse()
{
ComparableVersion c1 = new ComparableVersion( "1" );
@ -335,6 +348,6 @@ public class ComparableVersionTest
Comparable c2 = newComparable( "2" );
assertEquals( "reused instance should be equivalent to new instance", c1, c2 );
assertEquals( c1, c2, "reused instance should be equivalent to new instance" );
}
}

View File

@ -19,7 +19,13 @@ package org.apache.maven.artifact.versioning;
* under the License.
*/
import junit.framework.TestCase;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test DefaultArtifactVersion.
@ -27,7 +33,6 @@ import junit.framework.TestCase;
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class DefaultArtifactVersionTest
extends TestCase
{
private ArtifactVersion newArtifactVersion( String version )
{
@ -42,14 +47,15 @@ public class DefaultArtifactVersionTest
"'" + version + "' parsed as ('" + artifactVersion.getMajorVersion() + "', '"
+ artifactVersion.getMinorVersion() + "', '" + artifactVersion.getIncrementalVersion() + "', '"
+ artifactVersion.getBuildNumber() + "', '" + artifactVersion.getQualifier() + "'), ";
assertEquals( parsed + "check major version", major, artifactVersion.getMajorVersion() );
assertEquals( parsed + "check minor version", minor, artifactVersion.getMinorVersion() );
assertEquals( parsed + "check incremental version", incremental, artifactVersion.getIncrementalVersion() );
assertEquals( parsed + "check build number", buildnumber, artifactVersion.getBuildNumber() );
assertEquals( parsed + "check qualifier", qualifier, artifactVersion.getQualifier() );
assertEquals( "check " + version + " string value", version, artifactVersion.toString() );
assertEquals( major, artifactVersion.getMajorVersion(), parsed + "check major version" );
assertEquals( minor, artifactVersion.getMinorVersion(), parsed + "check minor version" );
assertEquals( incremental, artifactVersion.getIncrementalVersion(), parsed + "check incremental version" );
assertEquals( buildnumber, artifactVersion.getBuildNumber(), parsed + "check build number" );
assertEquals( qualifier, artifactVersion.getQualifier(), parsed + "check qualifier" );
assertEquals( version, artifactVersion.toString(), "check " + version + " string value" );
}
@Test
public void testVersionParsing()
{
checkVersionParsing( "1", 1, 0, 0, 0, null );
@ -87,6 +93,7 @@ public class DefaultArtifactVersionTest
checkVersionParsing( "1.2.3-200705301630", 1, 2, 3, 0, "200705301630" );
}
@Test
public void testVersionComparing()
{
assertVersionEqual( "1", "1" );
@ -134,6 +141,7 @@ public class DefaultArtifactVersionTest
assertVersionOlder( "2.0.0.v200706041905-7C78EK9E_EkMNfNOd2d8qq", "2.0.0.v200706041906-7C78EK9E_EkMNfNOd2d8qq" );
}
@Test
public void testVersionSnapshotComparing()
{
assertVersionEqual( "1-SNAPSHOT", "1-SNAPSHOT" );
@ -168,6 +176,7 @@ public class DefaultArtifactVersionTest
assertVersionOlder( "2.0.1-xyz-SNAPSHOT", "2.0.1-123-SNAPSHOT" );
}
@Test
public void testSnapshotVsReleases()
{
assertVersionOlder( "1.0-RC1", "1.0-SNAPSHOT" );
@ -175,6 +184,7 @@ public class DefaultArtifactVersionTest
assertVersionOlder( "1.0-rc-1", "1.0-SNAPSHOT" );
}
@Test
public void testHashCode()
{
ArtifactVersion v1 = newArtifactVersion( "1" );
@ -183,41 +193,45 @@ public class DefaultArtifactVersionTest
assertEquals( v1.hashCode(), v2.hashCode() );
}
@Test
public void testEqualsNullSafe()
{
assertFalse( newArtifactVersion( "1" ).equals( null ) );
}
@Test
public void testEqualsTypeSafe()
{
assertFalse( newArtifactVersion( "1" ).equals( "non-an-artifact-version-instance" ) );
}
@Test
@Disabled("That one does not work")
public void testNonNumericVersionRepresentationReturnsANumberFormatException()
{
try
{
new DefaultArtifactVersion( "..." );
}
catch ( Exception e )
{
assertTrue( "We expect a NumberFormatException to be thrown.", e instanceof NumberFormatException );
}
assertThrows(
NumberFormatException.class,
() -> new DefaultArtifactVersion( "..." ),
"We expect a NumberFormatException to be thrown." );
}
private void assertVersionOlder( String left, String right )
{
assertTrue( left + " should be older than " + right,
newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) < 0 );
assertTrue( right + " should be newer than " + left,
newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) > 0 );
assertTrue(
newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) < 0,
left + " should be older than " + right );
assertTrue(
newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) > 0,
right + " should be newer than " + left );
}
private void assertVersionEqual( String left, String right )
{
assertTrue( left + " should be equal to " + right,
newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) == 0 );
assertTrue( right + " should be equal to " + left,
newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) == 0 );
assertTrue(
newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) == 0,
left + " should be equal to " + right );
assertTrue(
newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) == 0,
right + " should be equal to " + left );
}
}

View File

@ -21,9 +21,15 @@ package org.apache.maven.artifact.versioning;
import java.util.List;
import junit.framework.TestCase;
import org.apache.maven.artifact.Artifact;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
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 version range construction.
@ -31,7 +37,6 @@ import org.apache.maven.artifact.Artifact;
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class VersionRangeTest
extends TestCase
{
private static final String CHECK_NUM_RESTRICTIONS = "check number of restrictions";
@ -49,6 +54,7 @@ public class VersionRangeTest
private static final String CHECK_SELECTED_VERSION = "check selected version";
@Test
public void testRange()
throws InvalidVersionSpecificationException, OverConstrainedVersionException
{
@ -56,93 +62,93 @@ public class VersionRangeTest
VersionRange range = VersionRange.createFromVersionSpec( "(,1.0]" );
List<Restriction> restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
Restriction restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
range = VersionRange.createFromVersionSpec( "1.0" );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion().toString() );
assertEquals( "1.0", range.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertTrue( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertEquals( CHECK_SELECTED_VERSION, "1.0", range.getSelectedVersion( artifact ).toString() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertTrue( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
assertEquals( "1.0", range.getSelectedVersion( artifact ).toString(), CHECK_SELECTED_VERSION );
range = VersionRange.createFromVersionSpec( "[1.0]" );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
range = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
range = VersionRange.createFromVersionSpec( "[1.0,2.0)" );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "2.0", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "2.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
range = VersionRange.createFromVersionSpec( "[1.5,)" );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
range = VersionRange.createFromVersionSpec( "(,1.0],[1.2,)" );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
assertNull( range.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
assertFalse( range.isSelectedVersionKnown( artifact ), CHECK_SELECTED_VERSION_KNOWN );
assertNull( range.getSelectedVersion( artifact ), CHECK_SELECTED_VERSION );
range = VersionRange.createFromVersionSpec( "[1.0,)" );
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
@ -154,6 +160,7 @@ public class VersionRangeTest
assertTrue( range.containsVersion( new DefaultArtifactVersion( "5.0.9.0" ) ) );
}
@Test
public void testInvalidRanges()
{
checkInvalidRange( "(1.0)" );
@ -172,6 +179,7 @@ public class VersionRangeTest
checkInvalidRange( "(1.1,1.2],[1.0,1.1)" );
}
@Test
public void testIntersections()
throws InvalidVersionSpecificationException
{
@ -179,481 +187,482 @@ public class VersionRangeTest
VersionRange range2 = VersionRange.createFromVersionSpec( "1.1" );
VersionRange mergedRange = range1.restrict( range2 );
// TODO current policy is to retain the original version - is this correct, do we need strategies or is that handled elsewhere?
// assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", mergedRange.getRecommendedVersion().toString() );
// assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
assertEquals( "1.0", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
List<Restriction> restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
Restriction restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
mergedRange = range2.restrict( range1 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
// TODO test reversed restrictions on all below
range1 = VersionRange.createFromVersionSpec( "[1.0,)" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.0", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.1,)" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.1]" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(1.1,)" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.2,)" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.2]" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.1]" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( "1.1", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.1)" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.0]" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" );
range2 = VersionRange.createFromVersionSpec( "1.2" );
mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.2", mergedRange.getRecommendedVersion().toString() );
assertEquals( "1.2", mergedRange.getRecommendedVersion().toString(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" );
range2 = VersionRange.createFromVersionSpec( "1.0.5" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.0", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.1), (1.1,)" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( restriction.getLowerBound(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertNull( restriction.getUpperBound(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" );
range2 = VersionRange.createFromVersionSpec( "(1.1,)" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.3)" );
range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" );
range2 = VersionRange.createFromVersionSpec( "[1.2,)" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.3]" );
range2 = VersionRange.createFromVersionSpec( "[1.2,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(1.2,1.3]" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(1.2,1.3)" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.2,1.3)" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.2", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.3", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.1]" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.1)" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "[1.1]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.1", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "[1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.4", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.4", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertFalse( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertFalse( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "(,1.1),(1.4,)" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
range1 = VersionRange.createFromVersionSpec( "(,1.1],[1.4,)" );
range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.6,]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() );
assertEquals( 2, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() );
assertEquals( 3, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 2 );
assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.5", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.5", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.7]" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,1.6]" );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() );
assertEquals( 3, restrictions.size(), CHECK_NUM_RESTRICTIONS );
restriction = restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.1", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.2", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 1 );
assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.3", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.4", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
restriction = restrictions.get( 2 );
assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.6", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertEquals( "1.5", restriction.getLowerBound().toString(), CHECK_LOWER_BOUND );
assertTrue( restriction.isLowerBoundInclusive(), CHECK_LOWER_BOUND_INCLUSIVE );
assertEquals( "1.6", restriction.getUpperBound().toString(), CHECK_UPPER_BOUND );
assertTrue( restriction.isUpperBoundInclusive(), CHECK_UPPER_BOUND_INCLUSIVE );
// test restricting empty sets
range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
range1 = range1.restrict( range2 );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
range2 = range1.restrict( range2 );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
assertNull( mergedRange.getRecommendedVersion(), CHECK_VERSION_RECOMMENDATION );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
}
@Test
public void testReleaseRangeBoundsContainsSnapshots()
throws InvalidVersionSpecificationException
{
@ -664,6 +673,7 @@ public class VersionRangeTest
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
}
@Test
public void testSnapshotRangeBoundsCanContainSnapshots()
throws InvalidVersionSpecificationException
{
@ -678,6 +688,7 @@ public class VersionRangeTest
assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
}
@Test
public void testSnapshotSoftVersionCanContainSnapshot()
throws InvalidVersionSpecificationException
{
@ -688,17 +699,13 @@ public class VersionRangeTest
private void checkInvalidRange( String version )
{
try
{
VersionRange.createFromVersionSpec( version );
fail( "Version " + version + " should have failed to construct" );
}
catch ( InvalidVersionSpecificationException expected )
{
// expected
}
assertThrows(
InvalidVersionSpecificationException.class,
() -> VersionRange.createFromVersionSpec( version ),
"Version " + version + " should have failed to construct" );
}
@Test
public void testContains() throws InvalidVersionSpecificationException
{
ArtifactVersion actualVersion = new DefaultArtifactVersion( "2.0.5" );
@ -723,11 +730,13 @@ public class VersionRangeTest
return vr.containsVersion( actualVersion );
}
@Test
public void testOrder0()
{
// assertTrue( new DefaultArtifactVersion( "1.0-alpha10" ).compareTo( new DefaultArtifactVersion( "1.0-alpha1" ) ) > 0 );
}
@Test
public void testCache()
throws InvalidVersionSpecificationException
{
@ -737,13 +746,13 @@ public class VersionRangeTest
VersionRange spec = VersionRange.createFromVersionSpec( "1.0" );
assertSame( spec, VersionRange.createFromVersionSpec( "1.0" ) ); // same instance from spec cache
List<Restriction> restrictions = spec.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
assertEquals( 1, restrictions.size(), CHECK_NUM_RESTRICTIONS );
VersionRange version = VersionRange.createFromVersion( "1.0" );
assertSame( version, VersionRange.createFromVersion( "1.0" ) ); // same instance from version cache
restrictions = version.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( 0, restrictions.size(), CHECK_NUM_RESTRICTIONS );
assertFalse( "check !VersionRange.createFromVersionSpec(x).equals(VersionRange.createFromVersion(x))", spec.equals( version ) );
assertFalse( spec.equals( version ), "check !VersionRange.createFromVersionSpec(x).equals(VersionRange.createFromVersion(x))" );
}
}

View File

@ -19,10 +19,11 @@ package org.apache.maven.building;
* under the License.
*/
import static org.junit.Assert.*;
import org.apache.maven.building.Problem.Severity;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class DefaultProblemCollectorTest
{

View File

@ -19,11 +19,11 @@ package org.apache.maven.building;
* under the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import org.apache.maven.building.Problem.Severity;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
public class DefaultProblemTest
{

View File

@ -19,14 +19,14 @@ package org.apache.maven.building;
* under the License.
*/
import org.junit.Test;
import java.io.File;
import java.io.InputStream;
import java.util.Scanner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class FileSourceTest
{
@ -34,15 +34,11 @@ public class FileSourceTest
@Test
public void testFileSource()
{
try
{
new FileSource( null );
fail( "Should fail, since you must specify a file" );
}
catch ( NullPointerException e )
{
assertEquals( "file cannot be null", e.getMessage() );
}
NullPointerException e = assertThrows(
NullPointerException.class,
() -> new FileSource( null ),
"Should fail, since you must specify a file" );
assertEquals( "file cannot be null", e.getMessage() );
}
@Test

View File

@ -19,12 +19,12 @@ package org.apache.maven.building;
* under the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
public class ProblemCollectorFactoryTest
{

View File

@ -19,12 +19,12 @@ package org.apache.maven.building;
* under the License.
*/
import org.junit.Test;
import java.io.InputStream;
import java.util.Scanner;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class StringSourceTest
{

View File

@ -19,15 +19,15 @@ package org.apache.maven.building;
* under the License.
*/
import org.junit.Test;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class UrlSourceTest
{
@ -35,15 +35,11 @@ public class UrlSourceTest
@Test
public void testUrlSource()
{
try
{
new UrlSource( null );
fail( "Should fail, since you must specify a url" );
}
catch ( NullPointerException e )
{
assertEquals( "url cannot be null", e.getMessage() );
}
NullPointerException e = assertThrows(
NullPointerException.class,
() -> new UrlSource( null ),
"Should fail, since you must specify a url" );
assertEquals( "url cannot be null", e.getMessage() );
}
@Test

View File

@ -99,6 +99,11 @@ under the License.
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-cipher</artifactId>

View File

@ -19,6 +19,20 @@ package org.apache.maven.artifact;
* under the License.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.maven.test.PlexusTestCase;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@ -28,10 +42,6 @@ import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.collection.DependencyGraphTransformer;
@ -54,18 +64,11 @@ import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import javax.inject.Inject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -82,24 +85,15 @@ public abstract class AbstractArtifactComponentTestCase
@Inject
LegacySupport legacySupport;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Inject @Named( "default" )
ArtifactRepositoryLayout repoLayout;
@Override
protected void setUp()
@BeforeEach
public void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
RepositorySystemSession repoSession = initRepoSession();
MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(),
new DefaultMavenExecutionResult() );
@ -107,15 +101,6 @@ public abstract class AbstractArtifactComponentTestCase
legacySupport.setSession( session );
}
@Override
protected void tearDown()
throws Exception
{
release( artifactFactory );
super.tearDown();
}
protected abstract String component();
/**
@ -132,9 +117,6 @@ public abstract class AbstractArtifactComponentTestCase
f.createNewFile();
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, null,
null );
}
@ -151,9 +133,6 @@ public abstract class AbstractArtifactComponentTestCase
File f = new File( getBasedir(), path );
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + f.getPath(), repoLayout, null,
null );
}
@ -165,9 +144,6 @@ public abstract class AbstractArtifactComponentTestCase
File f = new File( getBasedir(), path );
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout,
new ArtifactRepositoryPolicy(),
new ArtifactRepositoryPolicy() );
@ -176,9 +152,6 @@ public abstract class AbstractArtifactComponentTestCase
protected ArtifactRepository badRemoteRepository()
throws Exception
{
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return artifactRepositoryFactory.createArtifactRepository( "test", "http://foo.bar/repository", repoLayout,
null, null );
}
@ -192,10 +165,7 @@ public abstract class AbstractArtifactComponentTestCase
File file = new File( remoteRepo.getBasedir(), path );
if ( !file.exists() )
{
fail( "Remote artifact " + file + " should be present." );
}
assertTrue( file.exists(), "Remote artifact " + file + " should be present." );
}
protected void assertLocalArtifactPresent( Artifact artifact )
@ -207,10 +177,7 @@ public abstract class AbstractArtifactComponentTestCase
File file = new File( localRepo.getBasedir(), path );
if ( !file.exists() )
{
fail( "Local artifact " + file + " should be present." );
}
assertTrue( file.exists(), "Local artifact " + file + " should be present." );
}
protected void assertRemoteArtifactNotPresent( Artifact artifact )
@ -222,10 +189,7 @@ public abstract class AbstractArtifactComponentTestCase
File file = new File( remoteRepo.getBasedir(), path );
if ( file.exists() )
{
fail( "Remote artifact " + file + " should not be present." );
}
assertFalse( file.exists(), "Remote artifact " + file + " should not be present." );
}
protected void assertLocalArtifactNotPresent( Artifact artifact )
@ -237,10 +201,7 @@ public abstract class AbstractArtifactComponentTestCase
File file = new File( localRepo.getBasedir(), path );
if ( file.exists() )
{
fail( "Local artifact " + file + " should not be present." );
}
assertFalse( file.exists(), "Local artifact " + file + " should not be present." );
}
// ----------------------------------------------------------------------

View File

@ -25,6 +25,11 @@ import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -42,6 +47,7 @@ public class ArtifactDeployerTest
return "deployer";
}
@Test
public void testArtifactInstallation()
throws Exception
{

View File

@ -19,19 +19,14 @@ package org.apache.maven.artifact.factory;
* under the License.
*/
import javax.inject.Inject;
import org.apache.maven.test.PlexusTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.Test;
import javax.inject.Inject;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DefaultArtifactFactoryTest
extends PlexusTestCase
@ -40,25 +35,7 @@ public class DefaultArtifactFactoryTest
@Inject
ArtifactFactory factory;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
@Test
public void testPropagationOfSystemScopeRegardlessOfInheritedScope()
{
Artifact artifact = factory.createDependencyArtifact( "test-grp", "test-artifact", VersionRange.createFromVersion("1.0"), "type", null, "system", "provided" );

View File

@ -23,6 +23,8 @@ import java.io.File;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.inject.Inject;
@ -40,6 +42,7 @@ public class ArtifactInstallerTest
return "installer";
}
@Test
public void testArtifactInstallation()
throws Exception
{

View File

@ -20,10 +20,12 @@ package org.apache.maven.artifact.repository;
*/
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MavenArtifactRepositoryTest
extends TestCase
{
private static class MavenArtifactRepositorySubclass extends MavenArtifactRepository
{
@ -41,6 +43,7 @@ public class MavenArtifactRepositoryTest
}
}
@Test
public void testHashCodeEquals()
{
MavenArtifactRepositorySubclass r1 = new MavenArtifactRepositorySubclass( "foo" );

View File

@ -22,7 +22,9 @@ package org.apache.maven.artifact.resolver;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test the artifact resolution exception message
@ -30,10 +32,10 @@ import junit.framework.TestCase;
* @author Mauro Talevi
*/
public class ArtifactResolutionExceptionTest
extends TestCase
{
private static final String LS = System.lineSeparator();
@Test
public void testMissingArtifactMessageFormat()
{
String message = "Missing artifact";

View File

@ -29,12 +29,18 @@ import java.util.Set;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -55,8 +61,9 @@ public class ArtifactResolverTest
private Artifact projectArtifact;
@BeforeEach
@Override
protected void setUp()
public void setUp()
throws Exception
{
super.setUp();
@ -64,8 +71,9 @@ public class ArtifactResolverTest
projectArtifact = createLocalArtifact( "project", "3.0" );
}
@AfterEach
@Override
protected void tearDown()
public void tearDown()
throws Exception
{
projectArtifact = null;
@ -78,6 +86,7 @@ public class ArtifactResolverTest
return "resolver";
}
@Test
public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository()
throws Exception
{
@ -88,6 +97,7 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( a );
}
@Test
public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepository()
throws Exception
{
@ -105,6 +115,7 @@ public class ArtifactResolverTest
return super.createArtifact( groupId, artifactId, version, type );
}
@Test
public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository()
throws Exception
{
@ -127,6 +138,7 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( h );
}
@Test
public void testTransitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository()
throws Exception
{
@ -151,22 +163,19 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( j );
}
@Test
public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository()
throws Exception
{
Artifact k = createArtifact( "k", "1.0" );
try
{
artifactResolver.resolve( k, remoteRepositories(), localRepository() );
fail( "Resolution succeeded when it should have failed" );
}
catch ( ArtifactNotFoundException expected )
{
assertTrue( true );
}
assertThrows(
ArtifactNotFoundException.class,
() -> artifactResolver.resolve( k, remoteRepositories(), localRepository() ),
"Resolution succeeded when it should have failed" );
}
@Test
public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood()
throws Exception
{
@ -182,6 +191,7 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( l );
}
@Test
public void testTransitiveResolutionOrder()
throws Exception
{
@ -237,8 +247,8 @@ public class ArtifactResolverTest
printErrors( result );
Iterator<Artifact> i = result.getArtifacts().iterator();
assertEquals( "n should be first", n, i.next() );
assertEquals( "m should be second", m, i.next() );
assertEquals( n, i.next(), "n should be first" );
assertEquals( m, i.next(), "m should be second" );
// inverse order
set = new LinkedHashSet<>();
@ -251,8 +261,8 @@ public class ArtifactResolverTest
printErrors( result );
i = result.getArtifacts().iterator();
assertEquals( "m should be first", m, i.next() );
assertEquals( "n should be second", n, i.next() );
assertEquals( m, i.next(), "m should be first" );
assertEquals( n, i.next(), "n should be second" );
}
private void printErrors( ArtifactResolutionResult result )

View File

@ -24,6 +24,11 @@ import java.util.Collections;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -35,16 +40,18 @@ public class DefaultArtifactResolverTest
private Artifact projectArtifact;
@BeforeEach
@Override
protected void setUp()
public void setUp()
throws Exception
{
super.setUp();
projectArtifact = createLocalArtifact( "project", "3.0" );
}
@AfterEach
@Override
protected void tearDown()
public void tearDown()
throws Exception
{
projectArtifact = null;
@ -57,6 +64,7 @@ public class DefaultArtifactResolverTest
return "resolver";
}
@Test
public void testMNG4738()
throws Exception
{
@ -94,14 +102,15 @@ public class DefaultArtifactResolverTest
{
String name = active.getName();
boolean daemon = active.isDaemon();
assertTrue( name + " is no daemon Thread.", daemon );
assertTrue( daemon, name + " is no daemon Thread." );
}
}
assertTrue( "Could not find ThreadGroup: " + DaemonThreadCreator.THREADGROUP_NAME, seen );
assertTrue( seen, "Could not find ThreadGroup: " + DaemonThreadCreator.THREADGROUP_NAME );
}
@Test
public void testLookup()
throws Exception
{

View File

@ -21,7 +21,11 @@ package org.apache.maven.artifact.resolver.filter;
import java.util.Arrays;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests {@link AndArtifactFilter}.
@ -29,7 +33,6 @@ import junit.framework.TestCase;
* @author Benjamin Bentmann
*/
public class AndArtifactFilterTest
extends TestCase
{
private ArtifactFilter newSubFilter()
@ -37,6 +40,7 @@ public class AndArtifactFilterTest
return artifact -> false;
}
@Test
public void testEquals()
{
AndArtifactFilter filter1 = new AndArtifactFilter();

View File

@ -22,15 +22,17 @@ package org.apache.maven.artifact.resolver.filter;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Igor Fedorenko
*/
public class FilterHashEqualsTest
extends TestCase
{
@Test
public void testIncludesExcludesArtifactFilter()
{
List<String> patterns = Arrays.asList( "c", "d", "e" );

View File

@ -21,7 +21,11 @@ package org.apache.maven.artifact.resolver.filter;
import java.util.Arrays;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests {@link OrArtifactFilter}.
@ -29,7 +33,6 @@ import junit.framework.TestCase;
* @author Benjamin Bentmann
*/
public class OrArtifactFilterTest
extends TestCase
{
private ArtifactFilter newSubFilter()
@ -37,6 +40,7 @@ public class OrArtifactFilterTest
return artifact -> false;
}
@Test
public void testEquals()
{
OrArtifactFilter filter1 = new OrArtifactFilter();

View File

@ -21,8 +21,10 @@ package org.apache.maven.artifact.resolver.filter;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests {@link ScopeArtifactFilter}.
@ -30,7 +32,6 @@ import junit.framework.TestCase;
* @author Benjamin Bentmann
*/
public class ScopeArtifactFilterTest
extends TestCase
{
private Artifact newArtifact( String scope )
@ -38,6 +39,7 @@ public class ScopeArtifactFilterTest
return new DefaultArtifact( "g", "a", "1.0", scope, "jar", "", null );
}
@Test
public void testInclude_Compile()
{
ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
@ -49,6 +51,7 @@ public class ScopeArtifactFilterTest
assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) );
}
@Test
public void testInclude_CompilePlusRuntime()
{
ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE_PLUS_RUNTIME );
@ -60,6 +63,7 @@ public class ScopeArtifactFilterTest
assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) );
}
@Test
public void testInclude_Runtime()
{
ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
@ -71,6 +75,7 @@ public class ScopeArtifactFilterTest
assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) );
}
@Test
public void testInclude_RuntimePlusSystem()
{
ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM );
@ -82,6 +87,7 @@ public class ScopeArtifactFilterTest
assertFalse( filter.include( newArtifact( Artifact.SCOPE_TEST ) ) );
}
@Test
public void testInclude_Test()
{
ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_TEST );

View File

@ -45,7 +45,10 @@ import java.util.Iterator;
import java.util.List;
import org.codehaus.plexus.util.FileUtils;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestFileManager
{
@ -157,11 +160,11 @@ public class TestFileManager
if ( shouldExist )
{
Assert.assertTrue( file.exists() );
assertTrue( file.exists() );
}
else
{
Assert.assertFalse( file.exists() );
assertFalse( file.exists() );
}
}
@ -174,7 +177,7 @@ public class TestFileManager
String contents = FileUtils.fileRead( file, encoding );
Assert.assertEquals( contentsTest, contents );
assertEquals( contentsTest, contents );
}
public File createFile( File dir, String filename, String contents, String encoding )

View File

@ -15,7 +15,6 @@ package org.apache.maven.artifact.transform;
* the License.
*/
import java.util.Collections;
import java.util.List;
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformation;
@ -23,10 +22,11 @@ import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformat
import org.apache.maven.repository.legacy.resolver.transform.LatestArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -37,36 +37,18 @@ public class TransformationManagerTest
@Inject
ArtifactTransformationManager tm;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
@Test
public void testTransformationManager()
{
List<ArtifactTransformation> tms = tm.getArtifactTransformations();
assertEquals( 3, tms.size() );
assertTrue( "We expected the release transformation and got " + tms.get(0), tms.get(0) instanceof ReleaseArtifactTransformation );
assertTrue( tms.get(0) instanceof ReleaseArtifactTransformation, "We expected the release transformation and got " + tms.get(0) );
assertTrue( "We expected the latest transformation and got " + tms.get(1), tms.get(1) instanceof LatestArtifactTransformation );
assertTrue( tms.get(1) instanceof LatestArtifactTransformation, "We expected the latest transformation and got " + tms.get(1) );
assertTrue( "We expected the snapshot transformation and got " + tms.get(2), tms.get(2) instanceof SnapshotTransformation );
assertTrue( tms.get(2) instanceof SnapshotTransformation, "We expected the snapshot transformation and got " + tms.get(2) );
}
}

View File

@ -19,36 +19,25 @@ package org.apache.maven.profiles.manager;
* under the License.
*/
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.test.PlexusTestCase;
import org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class DefaultProfileManagerTest
extends PlexusTestCase
{
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Test
public void testShouldActivateDefaultProfile()
throws Exception
{
@ -84,6 +73,7 @@ public class DefaultProfileManagerTest
assertEquals( "defaultActivated", ( (Profile) active.get( 0 ) ).getId() );
}
@Test
public void testShouldNotActivateDefaultProfile()
throws Exception
{
@ -123,6 +113,7 @@ public class DefaultProfileManagerTest
}
@Test
public void testShouldNotActivateReversalOfPresentSystemProperty()
throws Exception
{
@ -150,6 +141,7 @@ public class DefaultProfileManagerTest
assertEquals( 0, active.size() );
}
@Test
public void testShouldOverrideAndActivateInactiveProfile()
throws Exception
{
@ -180,6 +172,7 @@ public class DefaultProfileManagerTest
assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() );
}
@Test
public void testShouldOverrideAndDeactivateActiveProfile()
throws Exception
{

View File

@ -21,25 +21,21 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import javax.inject.Inject;
import org.apache.maven.test.PlexusTestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import javax.inject.Inject;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Jason van Zyl
@ -53,23 +49,12 @@ public abstract class AbstractMavenProjectTestCase
protected RepositorySystem repositorySystem;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
@BeforeEach
public void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) )
{
projectBuilder = lookup( ProjectBuilder.class, "test" );
@ -81,8 +66,8 @@ public abstract class AbstractMavenProjectTestCase
}
}
@Override
protected void tearDown()
@AfterEach
public void tearDown()
throws Exception
{
projectBuilder = null;

View File

@ -26,8 +26,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
@ -36,11 +34,17 @@ import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
public class ModelUtilsTest
extends TestCase
{
@Test
public void testShouldUseMainPluginDependencyVersionOverManagedDepVersion()
{
Plugin mgtPlugin = createPlugin( "group", "artifact", "1", Collections.EMPTY_MAP );
@ -68,6 +72,7 @@ public class ModelUtilsTest
return dep;
}
@Test
public void testShouldNotInheritPluginWithInheritanceSetToFalse()
{
PluginContainer parent = new PluginContainer();
@ -108,6 +113,7 @@ public class ModelUtilsTest
* X -&gt; Y -&gt; A -&gt; B -&gt; C -&gt; D -&gt; E -&gt; F
* </pre>
*/
@Test
public void testShouldPreserveChildOrderingOfPluginsAfterParentMerge()
{
PluginContainer parent = new PluginContainer();
@ -176,6 +182,7 @@ public class ModelUtilsTest
return plugin;
}
@Test
public void testShouldInheritOnePluginWithExecution()
{
Plugin parent = new Plugin();
@ -198,6 +205,7 @@ public class ModelUtilsTest
assertEquals( 1, child.getExecutions().size() );
}
@Test
public void testShouldMergeInheritedPluginHavingExecutionWithLocalPlugin()
{
Plugin parent = new Plugin();
@ -225,6 +233,7 @@ public class ModelUtilsTest
assertEquals( 2, child.getExecutions().size() );
}
@Test
public void testShouldMergeOnePluginWithInheritExecutionWithoutDuplicatingPluginInList()
{
Plugin parent = new Plugin();
@ -259,6 +268,7 @@ public class ModelUtilsTest
assertEquals( 1, plugin.getExecutions().size() );
}
@Test
public void testShouldMergePluginWithDifferentExecutionFromParentWithoutDuplicatingPluginInList()
{
Plugin parent = new Plugin();
@ -299,6 +309,7 @@ public class ModelUtilsTest
assertEquals( 2, plugin.getExecutions().size() );
}
@Test
public void testShouldNOTMergeInheritedPluginHavingInheritEqualFalse()
{
Plugin parent = new Plugin();
@ -326,6 +337,7 @@ public class ModelUtilsTest
* Verifies MNG-1499: The order of the merged list should be the plugins specified by the parent followed by the
* child list.
*/
@Test
public void testShouldKeepOriginalPluginOrdering()
{
Plugin parentPlugin1 = new Plugin();
@ -390,6 +402,7 @@ public class ModelUtilsTest
/**
* Verifies MNG-1499: The ordering of plugin executions should also be in the specified order.
*/
@Test
public void testShouldKeepOriginalPluginExecutionOrdering()
{
Plugin parent = new Plugin();
@ -439,6 +452,7 @@ public class ModelUtilsTest
assertEquals( dep.getManagementKey(), dep2.getManagementKey() );
}
@Test
public void testShouldOverwritePluginConfigurationSubItemsByDefault()
throws XmlPullParserException, IOException
{
@ -465,6 +479,7 @@ public class ModelUtilsTest
assertEquals( "three", item.getValue() );
}
@Test
public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet()
throws XmlPullParserException, IOException
{
@ -496,6 +511,7 @@ public class ModelUtilsTest
assertEquals( expected, actual );
}
@Test
public void testShouldNotMergePluginExecutionWhenExecInheritedIsFalseAndTreatAsInheritanceIsTrue()
{
String gid = "group";
@ -533,9 +549,10 @@ public class ModelUtilsTest
ModelUtils.mergePluginDefinitions( pChild, pParent, true );
Map executionMap = pChild.getExecutionsAsMap();
assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) );
assertNull( executionMap.get( testId ), "test execution should not be inherited from parent." );
}
@Test
public void testShouldNotMergePluginExecutionWhenPluginInheritedIsFalseAndTreatAsInheritanceIsTrue()
{
String gid = "group";
@ -573,9 +590,10 @@ public class ModelUtilsTest
ModelUtils.mergePluginDefinitions( pChild, pParent, true );
Map executionMap = pChild.getExecutionsAsMap();
assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) );
assertNull( executionMap.get( testId ), "test execution should not be inherited from parent." );
}
@Test
public void testShouldMergePluginExecutionWhenExecInheritedIsTrueAndTreatAsInheritanceIsTrue()
{
String gid = "group";
@ -613,7 +631,7 @@ public class ModelUtilsTest
ModelUtils.mergePluginDefinitions( pChild, pParent, true );
Map executionMap = pChild.getExecutionsAsMap();
assertNotNull( "test execution should be inherited from parent.", executionMap.get( testId ) );
assertNotNull( executionMap.get( testId ), "test execution should be inherited from parent." );
}
}

View File

@ -20,20 +20,17 @@ package org.apache.maven.project;
*/
import java.io.File;
import java.util.Collections;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.ArtifactResolver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
public class ProjectClasspathTest
extends AbstractMavenProjectTestCase
@ -41,23 +38,12 @@ public class ProjectClasspathTest
static final String dir = "projects/scope/";
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
@BeforeEach
public void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" );
DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class);
pomReader.setArtifactResolver( resolver );
@ -71,6 +57,7 @@ public class ProjectClasspathTest
return null;
}
@Test
public void testProjectClasspath()
throws Exception
{
@ -80,7 +67,7 @@ public class ProjectClasspathTest
Artifact artifact;
assertNotNull( "Test project can't be null!", project );
assertNotNull( project, "Test project can't be null!" );
checkArtifactIdScope( project, "provided", "provided" );
checkArtifactIdScope( project, "test", "test" );
@ -90,53 +77,53 @@ public class ProjectClasspathTest
// check all transitive deps of a test dependency are test, except test and provided which is skipped
artifact = getArtifact( project, "maven-test-test", "scope-provided" );
assertNull( "Check no provided dependencies are transitive", artifact );
assertNull( artifact, "Check no provided dependencies are transitive" );
artifact = getArtifact( project, "maven-test-test", "scope-test" );
assertNull( "Check no test dependencies are transitive", artifact );
assertNull( artifact, "Check no test dependencies are transitive" );
artifact = getArtifact( project, "maven-test-test", "scope-compile" );
assertNotNull( artifact );
System.out.println( "a = " + artifact );
System.out.println( "b = " + artifact.getScope() );
assertEquals( "Check scope", "test", artifact.getScope() );
assertEquals( "test", artifact.getScope(), "Check scope" );
artifact = getArtifact( project, "maven-test-test", "scope-default" );
assertEquals( "Check scope", "test", artifact.getScope() );
assertEquals( "test", artifact.getScope(), "Check scope" );
artifact = getArtifact( project, "maven-test-test", "scope-runtime" );
assertEquals( "Check scope", "test", artifact.getScope() );
assertEquals( "test", artifact.getScope(), "Check scope" );
// check all transitive deps of a provided dependency are provided scope, except for test
checkGroupIdScope( project, "provided", "maven-test-provided" );
artifact = getArtifact( project, "maven-test-provided", "scope-runtime" );
assertEquals( "Check scope", "provided", artifact.getScope() );
assertEquals( "provided", artifact.getScope(), "Check scope" );
// check all transitive deps of a runtime dependency are runtime scope, except for test
checkGroupIdScope( project, "runtime", "maven-test-runtime" );
artifact = getArtifact( project, "maven-test-runtime", "scope-runtime" );
assertEquals( "Check scope", "runtime", artifact.getScope() );
assertEquals( "runtime", artifact.getScope(), "Check scope" );
// check all transitive deps of a compile dependency are compile scope, except for runtime and test
checkGroupIdScope( project, "compile", "maven-test-compile" );
artifact = getArtifact( project, "maven-test-compile", "scope-runtime" );
assertEquals( "Check scope", "runtime", artifact.getScope() );
assertEquals( "runtime", artifact.getScope(), "Check scope" );
// check all transitive deps of a default dependency are compile scope, except for runtime and test
checkGroupIdScope( project, "compile", "maven-test-default" );
artifact = getArtifact( project, "maven-test-default", "scope-runtime" );
assertEquals( "Check scope", "runtime", artifact.getScope() );
assertEquals( "runtime", artifact.getScope(), "Check scope" );
}
private void checkGroupIdScope( MavenProject project, String scopeValue, String groupId )
{
Artifact artifact;
artifact = getArtifact( project, groupId, "scope-compile" );
assertEquals( "Check scope", scopeValue, artifact.getScope() );
assertEquals( scopeValue, artifact.getScope(), "Check scope" );
artifact = getArtifact( project, groupId, "scope-test" );
assertNull( "Check test dependency is not transitive", artifact );
assertNull( artifact, "Check test dependency is not transitive" );
artifact = getArtifact( project, groupId, "scope-provided" );
assertNull( "Check provided dependency is not transitive", artifact );
assertNull( artifact, "Check provided dependency is not transitive" );
artifact = getArtifact( project, groupId, "scope-default" );
assertEquals( "Check scope", scopeValue, artifact.getScope() );
assertEquals( scopeValue, artifact.getScope(), "Check scope" );
}
private void checkArtifactIdScope( MavenProject project, String scope, String scopeValue )
@ -144,7 +131,7 @@ public class ProjectClasspathTest
String artifactId = "scope-" + scope;
Artifact artifact = getArtifact( project, "maven-test", artifactId );
assertNotNull( artifact );
assertEquals( "Check scope", scopeValue, artifact.getScope() );
assertEquals( scopeValue, artifact.getScope(), "Check scope" );
}
private Artifact getArtifact( MavenProject project, String groupId, String artifactId )

View File

@ -21,6 +21,9 @@ package org.apache.maven.project.inheritance.t00;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* A test which demonstrates maven's recursive inheritance where
@ -50,6 +53,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testProjectInheritance()
throws Exception
{

View File

@ -21,6 +21,9 @@ package org.apache.maven.project.inheritance.t01;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* A test which demonstrates maven's recursive inheritance where
@ -46,6 +49,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testProjectInheritance()
throws Exception
{

View File

@ -26,8 +26,14 @@ import java.util.Map;
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A test which demonstrates maven's recursive inheritance where
@ -57,6 +63,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testProjectInheritance()
throws Exception
{
@ -134,33 +141,25 @@ public class ProjectInheritanceTest
{
String pluginArtifactId = plugin.getArtifactId();
if ( !validPluginCounts.containsKey( pluginArtifactId ) )
assertTrue( validPluginCounts.containsKey( pluginArtifactId ), "Illegal plugin found: " + pluginArtifactId );
if ( pluginArtifactId.equals( testPluginArtifactId ) )
{
fail( "Illegal plugin found: " + pluginArtifactId );
testPlugin = plugin;
}
else
{
if ( pluginArtifactId.equals( testPluginArtifactId ) )
{
testPlugin = plugin;
}
Integer count = validPluginCounts.get( pluginArtifactId );
Integer count = validPluginCounts.get( pluginArtifactId );
if ( count > 0 )
{
fail( "Multiple copies of plugin: " + pluginArtifactId + " found in POM." );
}
else
{
count = count + 1;
assertEquals( 0, (int) count, "Multiple copies of plugin: " + pluginArtifactId + " found in POM." );
validPluginCounts.put( pluginArtifactId, count );
}
}
count = count + 1;
validPluginCounts.put( pluginArtifactId, count );
}
List executions = testPlugin.getExecutions();
assertNotNull( testPlugin );
List<PluginExecution> executions = testPlugin.getExecutions();
assertEquals( 1, executions.size() );
}

View File

@ -23,6 +23,9 @@ import java.io.File;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* A test which demonstrates maven's recursive inheritance where
@ -49,6 +52,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testProjectInheritance()
throws Exception
{

View File

@ -25,6 +25,11 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Verifies the version of a dependency listed in a parent's
@ -51,6 +56,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testDependencyManagementOverridesTransitiveDependencyVersion()
throws Exception
{
@ -65,9 +71,9 @@ public class ProjectInheritanceTest
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
Set set = project1.getArtifacts();
assertNotNull( "No artifacts", set );
assertTrue( "No Artifacts", set.size() > 0 );
assertTrue( "Set size should be 3, is " + set.size(), set.size() == 3 );
assertNotNull( set, "No artifacts" );
assertTrue( set.size() > 0, "No Artifacts" );
assertTrue( set.size() == 3, "Set size should be 3, is " + set.size() );
for ( Object aSet : set )
{
@ -77,8 +83,8 @@ public class ProjectInheritanceTest
artifact.isOptional()
? "true"
: "false" ) );
assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(),
artifact.getVersion().equals( "1.0" ) );
assertTrue( artifact.getVersion().equals( "1.0" ),
"Incorrect version for " + artifact.getDependencyConflictId() );
}
}

View File

@ -25,6 +25,11 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A test which demonstrates maven's dependency management
@ -45,6 +50,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testDependencyManagement()
throws Exception
{
@ -61,8 +67,8 @@ public class ProjectInheritanceTest
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
Set set = project1.getArtifacts();
assertNotNull( "No artifacts", set );
assertTrue( "No Artifacts", set.size() > 0 );
assertNotNull( set, "No artifacts" );
assertTrue( set.size() > 0, "No Artifacts" );
for ( Object aSet : set )
{
@ -70,8 +76,8 @@ public class ProjectInheritanceTest
System.out.println(
"Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Scope: "
+ artifact.getScope() );
assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(),
artifact.getVersion().equals( "1.0" ) );
assertTrue( artifact.getVersion().equals( "1.0" ),
"Incorrect version for " + artifact.getDependencyConflictId() );
}
}

View File

@ -26,6 +26,11 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A test which demonstrates maven's dependency management
@ -46,6 +51,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testDependencyManagement()
throws Exception
{
@ -62,18 +68,18 @@ public class ProjectInheritanceTest
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
Set set = project1.getArtifacts();
assertNotNull( "No artifacts", set );
assertTrue( "No Artifacts", set.size() > 0 );
assertNotNull( set, "No artifacts" );
assertTrue( set.size() > 0, "No Artifacts" );
Iterator iter = set.iterator();
assertTrue( "Set size should be 4, is " + set.size(), set.size() == 4 );
assertTrue( set.size() == 4, "Set size should be 4, is " + set.size() );
while ( iter.hasNext() )
{
Artifact artifact = (Artifact) iter.next();
System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion()
+ " Optional=" + ( artifact.isOptional() ? "true" : "false" ) );
assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(),
artifact.getVersion().equals( "1.0" ) );
assertTrue( artifact.getVersion().equals( "1.0" ),
"Incorrect version for " + artifact.getDependencyConflictId() );
}
}

View File

@ -25,6 +25,12 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A test which demonstrates maven's dependency management
@ -45,6 +51,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testDependencyManagement()
throws Exception
{
@ -61,21 +68,21 @@ public class ProjectInheritanceTest
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
System.out.println("Project " + project1.getId() + " " + project1);
Set set = project1.getArtifacts();
assertNotNull("No artifacts", set);
assertTrue("No Artifacts", set.size() > 0);
assertTrue("Set size should be 3, is " + set.size(), set.size() == 3 );
assertNotNull( set, "No artifacts" );
assertTrue( set.size() > 0, "No Artifacts" );
assertTrue( set.size() == 3, "Set size should be 3, is " + set.size() );
for ( Object aSet : set )
{
Artifact artifact = (Artifact) aSet;
assertFalse( "", artifact.getArtifactId().equals( "t07-d" ) );
assertFalse( artifact.getArtifactId().equals( "t07-d" ) );
System.out.println(
"Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + (
artifact.isOptional()
? "true"
: "false" ) );
assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(),
artifact.getVersion().equals( "1.0" ) );
assertTrue( artifact.getVersion().equals( "1.0" ),
"Incorrect version for " + artifact.getDependencyConflictId() );
}
}
}

View File

@ -26,6 +26,11 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A test which demonstrates maven's dependency management
@ -46,6 +51,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testDependencyManagement()
throws Exception
{
@ -63,18 +69,17 @@ public class ProjectInheritanceTest
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
System.out.println( "Project " + project1.getId() + " " + project1 );
Set set = project1.getArtifacts();
assertNotNull( "No artifacts", set );
assertTrue( "No Artifacts", set.size() > 0 );
assertNotNull( set, "No artifacts" );
assertTrue( set.size() > 0, "No Artifacts" );
Iterator iter = set.iterator();
assertTrue( "Set size should be 4, is " + set.size(), set.size() == 4 );
assertTrue( set.size() == 4, "Set size should be 4, is " + set.size() );
while ( iter.hasNext() )
{
Artifact artifact = (Artifact) iter.next();
System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion()
+ " Optional=" + ( artifact.isOptional() ? "true" : "false" ) );
assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(),
artifact.getVersion().equals( "1.0" ) );
assertTrue( artifact.getVersion().equals( "1.0" ), "Incorrect version for " + artifact.getDependencyConflictId() );
}
}

View File

@ -23,6 +23,12 @@ import java.util.Map;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Verifies exclusions listed in dependencyManagement are valid for
@ -56,6 +62,7 @@ public class ProjectInheritanceTest
* We should see that the resulting size of collected artifacts is two:
* a &amp; b only.
*/
@Test
public void testDependencyManagementExclusionsExcludeTransitively()
throws Exception
{
@ -69,17 +76,17 @@ public class ProjectInheritanceTest
MavenProject project0 = getProjectWithDependencies( pom0 );
MavenProject project1 = getProjectWithDependencies( pom1 );
assertNotNull("Parent is null", project1.getParent());
assertNotNull( project1.getParent(), "Parent is null" );
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
Map map = project1.getArtifactMap();
assertNotNull("No artifacts", map);
assertTrue("No Artifacts", map.size() > 0);
assertTrue("Set size should be 2, is " + map.size(), map.size() == 2);
assertNotNull( map, "No artifacts" );
assertTrue( map.size() > 0, "No Artifacts" );
assertTrue( map.size() == 2, "Set size should be 2, is " + map.size() );
assertTrue("maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ));
assertTrue("maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ));
assertFalse("maven-test:t09-c is in the project", map.containsKey( "maven-test:t09-c" ));
assertTrue( map.containsKey( "maven-test:t09-a" ), "maven-test:t09-a is not in the project" );
assertTrue( map.containsKey( "maven-test:t09-b" ), "maven-test:t09-b is not in the project" );
assertFalse( map.containsKey( "maven-test:t09-c" ), "maven-test:t09-c is in the project" );
}
/**
@ -92,6 +99,7 @@ public class ProjectInheritanceTest
*
* @throws Exception
*/
@Test
public void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives()
throws Exception
{
@ -107,13 +115,13 @@ public class ProjectInheritanceTest
assertEquals( pom0Basedir, project2.getParent().getBasedir() );
Map map = project2.getArtifactMap();
assertNotNull( "No artifacts", map );
assertTrue( "No Artifacts", map.size() > 0 );
assertTrue( "Set size should be 4, is " + map.size(), map.size() == 4 );
assertNotNull( map, "No artifacts" );
assertTrue( map.size() > 0, "No Artifacts" );
assertTrue( map.size() == 4, "Set size should be 4, is " + map.size() );
assertTrue( "maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ) );
assertTrue( "maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ) );
assertTrue( "maven-test:t09-c is not in the project", map.containsKey( "maven-test:t09-c" ) );
assertTrue( "maven-test:t09-d is not in the project", map.containsKey( "maven-test:t09-d" ) );
assertTrue( map.containsKey( "maven-test:t09-a" ), "maven-test:t09-a is not in the project" );
assertTrue( map.containsKey( "maven-test:t09-b" ), "maven-test:t09-b is not in the project" );
assertTrue( map.containsKey( "maven-test:t09-c" ), "maven-test:t09-c is not in the project" );
assertTrue( map.containsKey( "maven-test:t09-d" ), "maven-test:t09-d is not in the project" );
}
}

View File

@ -25,6 +25,11 @@ import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Verifies scope inheritance of direct and transitive dependencies.
@ -52,6 +57,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testDependencyManagementOverridesTransitiveDependencyVersion()
throws Exception
{
@ -68,9 +74,9 @@ public class ProjectInheritanceTest
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
System.out.println("Project " + project1.getId() + " " + project1);
Map map = project1.getArtifactMap();
assertNotNull("No artifacts", map);
assertTrue("No Artifacts", map.size() > 0);
assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
assertNotNull( map, "No artifacts" );
assertTrue( map.size() > 0, "No Artifacts" );
assertTrue( map.size() == 3, "Set size should be 3, is " + map.size() );
Artifact a = (Artifact) map.get("maven-test:t10-a");
Artifact b = (Artifact) map.get("maven-test:t10-b");
@ -82,13 +88,13 @@ public class ProjectInheritanceTest
// inherited from depMgmt
System.out.println(a.getScope());
assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test"));
assertTrue( a.getScope().equals("test"), "Incorrect scope for " + a.getDependencyConflictId() );
// transitive dep, overridden b depMgmt
assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime"));
assertTrue( b.getScope().equals("runtime"), "Incorrect scope for " + b.getDependencyConflictId() );
// direct dep, overrides depMgmt
assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime"));
assertTrue( c.getScope().equals("runtime"), "Incorrect scope for " + c.getDependencyConflictId() );
}
}

View File

@ -23,6 +23,10 @@ import java.io.File;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Verifies scope of root project is preserved regardless of parent dependency management.
@ -44,6 +48,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testDependencyManagementDoesNotOverrideScopeOfCurrentArtifact()
throws Exception
{
@ -58,7 +63,7 @@ public class ProjectInheritanceTest
MavenProject project1 = getProjectWithDependencies( pom1 );
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
assertNull( "dependencyManagement has overwritten the scope of the currently building child project",
project1.getArtifact().getScope() );
assertNull( project1.getArtifact().getScope(),
"dependencyManagement has overwritten the scope of the currently building child project" );
}
}

View File

@ -25,6 +25,10 @@ import java.util.Map;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Verifies that plugin execution sections in the parent POM that have
@ -43,6 +47,7 @@ public class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase
//
// ----------------------------------------------------------------------
@Test
public void testFalsePluginExecutionInheritValue() throws Exception
{
File localRepo = getLocalRepositoryPath();
@ -60,6 +65,6 @@ public class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase
assertNotNull( compilerPlugin );
Map executionMap = compilerPlugin.getExecutionsAsMap();
assertNull( "Plugin execution: \'test\' should NOT exist in the compiler plugin specification for the child project!", executionMap.get( "test" ) );
assertNull( executionMap.get( "test" ), "Plugin execution: \'test\' should NOT exist in the compiler plugin specification for the child project!" );
}
}

View File

@ -23,6 +23,9 @@ import java.io.File;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Verifies SCM inheritance uses modules statement from parent.
@ -43,6 +46,7 @@ public class ProjectInheritanceTest
//
// ----------------------------------------------------------------------
@Test
public void testScmInfoCalculatedCorrectlyOnParentAndChildRead()
throws Exception
{
@ -76,6 +80,7 @@ public class ProjectInheritanceTest
+ "/modules/p1" );
}
@Test
public void testScmInfoCalculatedCorrectlyOnChildOnlyRead()
throws Exception
{

View File

@ -21,13 +21,14 @@ package org.apache.maven.project.path;
import java.io.File;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SuppressWarnings( "deprecation" )
public class DefaultPathTranslatorTest
extends TestCase
{
@Test
public void testAlignToBasedirWhereBasedirExpressionIsTheCompleteValue()
{
File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile();
@ -37,6 +38,7 @@ public class DefaultPathTranslatorTest
assertEquals( basedir.getAbsolutePath(), aligned );
}
@Test
public void testAlignToBasedirWhereBasedirExpressionIsTheValuePrefix()
{
File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile();
@ -46,6 +48,7 @@ public class DefaultPathTranslatorTest
assertEquals( new File( basedir, "dir" ).getAbsolutePath(), aligned );
}
@Test
public void testUnalignToBasedirWherePathEqualsBasedir()
{
File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile();

View File

@ -21,9 +21,9 @@ package org.apache.maven.repository;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class DefaultMirrorSelectorTest
{

View File

@ -17,7 +17,6 @@ package org.apache.maven.repository;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.maven.artifact.Artifact;
@ -32,16 +31,18 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.legacy.LegacyRepositorySystem;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -58,25 +59,6 @@ public class LegacyRepositorySystemTest
@Inject
private ResolutionErrorHandler resolutionErrorHandler;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
protected List<ArtifactRepository> getRemoteRepositories()
throws Exception
{
@ -104,6 +86,7 @@ public class LegacyRepositorySystemTest
return repositorySystem.createLocalRepository( repoDir );
}
@Test
public void testThatASystemScopedDependencyIsNotResolvedFromRepositories()
throws Exception
{
@ -186,6 +169,7 @@ public class LegacyRepositorySystemTest
}
}
@Test
public void testLocalRepositoryBasedir()
throws Exception
{

View File

@ -20,17 +20,21 @@ package org.apache.maven.repository;
*/
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.maven.test.PlexusTestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.apache.maven.settings.Mirror;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -39,28 +43,11 @@ public class MirrorProcessorTest
{
@Inject
private DefaultMirrorSelector mirrorSelector;
@Inject
private ArtifactRepositoryFactory repositorySystem;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
@Test
public void testExternalURL()
{
assertTrue( DefaultMirrorSelector.isExternalRepo( getRepo( "foo", "http://somehost" ) ) );
@ -83,6 +70,7 @@ public class MirrorProcessorTest
assertFalse( DefaultMirrorSelector.isExternalRepo( getRepo( "foo", "" ) ) );
}
@Test
public void testMirrorLookup()
{
Mirror mirrorA = newMirror( "a", "a", "http://a" );
@ -97,6 +85,7 @@ public class MirrorProcessorTest
assertNull( mirrorSelector.getMirror( getRepo( "c", "http://c.c" ), mirrors ) );
}
@Test
public void testMirrorWildcardLookup()
{
Mirror mirrorA = newMirror( "a", "a", "http://a" );
@ -112,6 +101,7 @@ public class MirrorProcessorTest
assertSame( mirrorC, mirrorSelector.getMirror( getRepo( "c", "http://c.c" ), mirrors ) );
}
@Test
public void testMirrorStopOnFirstMatch()
{
// exact matches win first
@ -140,6 +130,7 @@ public class MirrorProcessorTest
assertSame( mirrorC2, mirrorSelector.getMirror( getRepo( "f", "http://f" ), mirrors ) );
}
@Test
public void testPatterns()
{
assertTrue( DefaultMirrorSelector.matchPattern( getRepo( "a" ), "*" ) );
@ -176,6 +167,7 @@ public class MirrorProcessorTest
assertFalse( DefaultMirrorSelector.matchPattern( getRepo( "d" ), "!a,!c*" ) );
}
@Test
public void testPatternsWithExternal()
{
assertTrue( DefaultMirrorSelector.matchPattern( getRepo( "a", "http://localhost" ), "*" ) );
@ -190,6 +182,7 @@ public class MirrorProcessorTest
assertTrue( DefaultMirrorSelector.matchPattern( getRepo( "c", "http://somehost" ), "!a,external:*" ) );
}
@Test
public void testLayoutPattern()
{
assertTrue( DefaultMirrorSelector.matchesLayout( "default", null ) );
@ -209,6 +202,7 @@ public class MirrorProcessorTest
assertFalse( DefaultMirrorSelector.matchesLayout( "default", "!default,*" ) );
}
@Test
public void testMirrorLayoutConsideredForMatching()
{
ArtifactRepository repo = getRepo( "a" );

View File

@ -21,20 +21,32 @@ package org.apache.maven.repository.legacy;
import java.io.File;
import javax.inject.Inject;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.repository.legacy.DefaultUpdateCheckManager;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class DefaultUpdateCheckManagerTest
extends AbstractArtifactComponentTestCase
{
@Inject
private ArtifactFactory artifactFactory;
DefaultUpdateCheckManager updateCheckManager;
@Override
@ -43,8 +55,9 @@ public class DefaultUpdateCheckManagerTest
return "updateCheckManager";
}
@BeforeEach
@Override
protected void setUp()
public void setUp()
throws Exception
{
super.setUp();
@ -52,6 +65,7 @@ public class DefaultUpdateCheckManagerTest
updateCheckManager = new DefaultUpdateCheckManager( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
}
@Test
public void testArtifact() throws Exception
{
ArtifactRepository remoteRepository = remoteRepository();
@ -81,6 +95,7 @@ public class DefaultUpdateCheckManagerTest
assertFalse( updateCheckManager.getTouchfile( a ).exists() );
}
@Test
public void testMissingArtifact()
throws Exception
{
@ -108,6 +123,7 @@ public class DefaultUpdateCheckManagerTest
updateCheckManager.getRepositoryKey( remoteRepository ) ) );
}
@Test
public void testPom() throws Exception
{
ArtifactRepository remoteRepository = remoteRepository();
@ -137,6 +153,7 @@ public class DefaultUpdateCheckManagerTest
assertFalse( updateCheckManager.getTouchfile( a ).exists() );
}
@Test
public void testMissingPom()
throws Exception
{
@ -164,6 +181,7 @@ public class DefaultUpdateCheckManagerTest
updateCheckManager.getRepositoryKey( remoteRepository ) ) );
}
@Test
public void testMetadata() throws Exception
{
ArtifactRepository remoteRepository = remoteRepository();
@ -191,6 +209,7 @@ public class DefaultUpdateCheckManagerTest
assertNotNull( updateCheckManager.readLastUpdated( touchFile, updateCheckManager.getMetadataKey( remoteRepository, file ) ) );
}
@Test
public void testMissingMetadata() throws Exception
{
ArtifactRepository remoteRepository = remoteRepository();
@ -216,10 +235,9 @@ public class DefaultUpdateCheckManagerTest
assertNotNull( updateCheckManager.readLastUpdated( touchFile, updateCheckManager.getMetadataKey( remoteRepository, file ) ) );
}
@Test
public void testArtifactTouchFileName() throws Exception
{
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
ArtifactRepository localRepository = localRepository();
Artifact a = artifactFactory.createArtifactWithClassifier( "groupdId", "a", "0.0.1-SNAPSHOT", "jar", null );

View File

@ -22,7 +22,6 @@ package org.apache.maven.repository.legacy;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.maven.artifact.Artifact;
@ -30,25 +29,32 @@ import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.observers.AbstractTransferListener;
import org.apache.maven.wagon.observers.Debug;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -69,25 +75,7 @@ public class DefaultWagonManagerTest
@Inject
private ArtifactRepositoryFactory artifactRepositoryFactory;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
@Test
public void testUnnecessaryRepositoryLookup()
throws Exception
{
@ -123,46 +111,33 @@ public class DefaultWagonManagerTest
assertEquals( 1, listener.events.size() );
}
@Test
public void testGetMissingJar() throws TransferFailedException, UnsupportedProtocolException, IOException
{
Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" );
ArtifactRepository repo = createStringRepo();
try
{
wagonManager.getArtifact( artifact, repo, null, false );
fail();
}
catch ( ResourceDoesNotExistException e )
{
assertTrue( true );
}
assertThrows( ResourceDoesNotExistException.class,
() -> wagonManager.getArtifact( artifact, repo, null, false ) );
assertFalse( artifact.getFile().exists() );
}
@Test
public void testGetMissingJarForced() throws TransferFailedException, UnsupportedProtocolException, IOException
{
Artifact artifact = createTestArtifact( "target/test-data/get-missing-jar", "jar" );
ArtifactRepository repo = createStringRepo();
try
{
wagonManager.getArtifact( artifact, repo, null, true );
fail();
}
catch ( ResourceDoesNotExistException e )
{
assertTrue( true );
}
assertThrows( ResourceDoesNotExistException.class,
() -> wagonManager.getArtifact( artifact, repo, null, true ) );
assertFalse( artifact.getFile().exists() );
}
@Test
public void testGetRemoteJar()
throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException
{
@ -240,6 +215,7 @@ public class DefaultWagonManagerTest
return getRepo( id, "http://something" );
}
@Test
public void testDefaultWagonManager()
throws Exception
{
@ -251,22 +227,13 @@ public class DefaultWagonManagerTest
assertWagon( "string" );
try
{
assertWagon( "d" );
fail( "Expected :" + UnsupportedProtocolException.class.getName() );
}
catch ( UnsupportedProtocolException e )
{
// ok
assertTrue( true );
}
assertThrows( UnsupportedProtocolException.class, () -> assertWagon( "d" ) );
}
/**
* Check that transfer listeners are properly removed after getArtifact and putArtifact
*/
@Test
public void testWagonTransferListenerRemovedAfterGetArtifactAndPutArtifact()
throws Exception
{
@ -277,25 +244,29 @@ public class DefaultWagonManagerTest
wagon.addExpectedContent( repo.getLayout().pathOf( artifact ) + ".md5", "cd26d9e10ce691cc69aa2b90dcebbdac" );
/* getArtifact */
assertFalse( "Transfer listener is registered before test",
wagon.getTransferEventSupport().hasTransferListener( transferListener ) );
assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ),
"Transfer listener is registered before test" );
wagonManager.getArtifact( artifact, repo, transferListener, false );
assertFalse( "Transfer listener still registered after getArtifact",
wagon.getTransferEventSupport().hasTransferListener( transferListener ) );
assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ),
"Transfer listener still registered after getArtifact" );
/* putArtifact */
File sampleFile = getTestFile( "target/test-file" );
FileUtils.fileWrite( sampleFile.getAbsolutePath(), "sample file" );
assertFalse( "Transfer listener is registered before test", wagon.getTransferEventSupport().hasTransferListener( transferListener ) );
assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ),
"Transfer listener is registered before test" );
wagonManager.putArtifact( sampleFile, artifact, repo, transferListener );
assertFalse( "Transfer listener still registered after putArtifact", wagon.getTransferEventSupport().hasTransferListener( transferListener ) );
assertFalse( wagon.getTransferEventSupport().hasTransferListener( transferListener ),
"Transfer listener still registered after putArtifact" );
}
/**
* Checks the verification of checksums.
*/
public void xtestChecksumVerification()
@Disabled
@Test
public void testChecksumVerification()
throws Exception
{
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
@ -312,84 +283,41 @@ public class DefaultWagonManagerTest
wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "lower-case-checksum" );
wagon.addExpectedContent( "path.sha1", "2a25dc564a3b34f68237fc849066cbc7bb7a36a1" );
try
{
wagonManager.getArtifact( artifact, repo, null, false );
}
catch ( ChecksumFailedException e )
{
fail( "Checksum verification did not pass: " + e.getMessage() );
}
wagonManager.getArtifact( artifact, repo, null, false );
wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "upper-case-checksum" );
wagon.addExpectedContent( "path.sha1", "B7BB97D7D0B9244398D9B47296907F73313663E6" );
try
{
wagonManager.getArtifact( artifact, repo, null, false );
}
catch ( ChecksumFailedException e )
{
fail( "Checksum verification did not pass: " + e.getMessage() );
}
wagonManager.getArtifact( artifact, repo, null, false );
wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "expected-failure" );
wagon.addExpectedContent( "path.sha1", "b7bb97d7d0b9244398d9b47296907f73313663e6" );
try
{
wagonManager.getArtifact( artifact, repo, null, false );
fail( "Checksum verification did not fail" );
}
catch ( ChecksumFailedException e )
{
// expected
}
assertThrows(
ChecksumFailedException.class, () ->
wagonManager.getArtifact( artifact, repo, null, false ),
"Checksum verification did not fail" );
wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "lower-case-checksum" );
wagon.addExpectedContent( "path.md5", "50b2cf50a103a965efac62b983035cac" );
try
{
wagonManager.getArtifact( artifact, repo, null, false );
}
catch ( ChecksumFailedException e )
{
fail( "Checksum verification did not pass: " + e.getMessage() );
}
wagonManager.getArtifact( artifact, repo, null, false );
wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "upper-case-checksum" );
wagon.addExpectedContent( "path.md5", "842F568FCCFEB7E534DC72133D42FFDC" );
try
{
wagonManager.getArtifact( artifact, repo, null, false );
}
catch ( ChecksumFailedException e )
{
fail( "Checksum verification did not pass: " + e.getMessage() );
}
wagonManager.getArtifact( artifact, repo, null, false );
wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "expected-failure" );
wagon.addExpectedContent( "path.md5", "b7bb97d7d0b9244398d9b47296907f73313663e6" );
try
{
wagonManager.getArtifact( artifact, repo, null, false );
fail( "Checksum verification did not fail" );
}
catch ( ChecksumFailedException e )
{
// expected
}
assertThrows(
ChecksumFailedException.class,
() -> wagonManager.getArtifact( artifact, repo, null, false ),
"Checksum verification did not fail" );
}
@Test
public void testPerLookupInstantiation()
throws Exception
{
@ -406,7 +334,7 @@ public class DefaultWagonManagerTest
{
Wagon wagon = wagonManager.getWagon( protocol );
assertNotNull( "Check wagon, protocol=" + protocol, wagon );
assertNotNull( wagon, "Check wagon, protocol=" + protocol );
}
private final class ArtifactRepositoryLayoutStub

View File

@ -17,16 +17,18 @@ package org.apache.maven.repository.legacy;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.Authentication;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Server;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import javax.inject.Inject;
@ -41,25 +43,7 @@ public class LegacyRepositorySystemTest
@Inject
private RepositorySystem repositorySystem;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
@Test
public void testThatLocalRepositoryWithSpacesIsProperlyHandled()
throws Exception
{
@ -68,6 +52,7 @@ public class LegacyRepositorySystemTest
assertEquals( basedir, new File( repo.getBasedir() ) );
}
@Test
public void testAuthenticationHandling()
{
Server server = new Server();

View File

@ -19,6 +19,18 @@ package org.apache.maven.repository.legacy.resolver;
* under the License.
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
@ -37,19 +49,16 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test the default artifact collector.
@ -59,8 +68,10 @@ import java.util.Set;
public class DefaultArtifactCollectorTest
extends PlexusTestCase
{
@Inject
private LegacyArtifactCollector artifactCollector;
@Inject
private ArtifactFactory artifactFactory;
private ArtifactSpec projectArtifact;
@ -69,72 +80,47 @@ public class DefaultArtifactCollectorTest
private static final String GROUP_ID = "test";
@BeforeEach
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
public void setUp()
throws Exception
{
super.setUp();
source = new Source();
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifactCollector = lookup( LegacyArtifactCollector.class );
projectArtifact = createArtifactSpec( "project", "1.0", null );
}
@Override
protected void tearDown()
throws Exception
{
artifactCollector = null;
artifactFactory = null;
super.tearDown();
}
// works, but we don't fail on cycles presently
public void disabledtestCircularDependencyNotIncludingCurrentProject()
@Test
@Disabled("works, but we don't fail on cycles presently")
public void testCircularDependencyNotIncludingCurrentProject()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
ArtifactSpec a = createArtifactSpec( "a", "1.0" );
ArtifactSpec b = a.addDependency( "b", "1.0" );
b.addDependency( "a", "1.0" );
try
{
collect( a );
fail( "Should have failed on cyclic dependency not involving project" );
}
catch ( CyclicDependencyException expected )
{
assertTrue( true );
}
assertThrows(
CyclicDependencyException.class,
() -> collect( a ),
"Should have failed on cyclic dependency not involving project" );
}
// works, but we don't fail on cycles presently
public void disabledtestCircularDependencyIncludingCurrentProject()
@Test
@Disabled("works, but we don't fail on cycles presently")
public void testCircularDependencyIncludingCurrentProject()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
ArtifactSpec a = createArtifactSpec( "a", "1.0" );
ArtifactSpec b = a.addDependency( "b", "1.0" );
b.addDependency( "project", "1.0" );
try
{
collect( a );
fail( "Should have failed on cyclic dependency involving project" );
}
catch ( CyclicDependencyException expected )
{
assertTrue( true );
}
assertThrows(
CyclicDependencyException.class,
() -> collect( a ),
"Should have failed on cyclic dependency not involving project" );
}
@Test
public void testResolveWithFilter()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -146,14 +132,15 @@ public class DefaultArtifactCollectorTest
ArtifactSpec d = b.addDependency( "d", "4.0" );
ArtifactResolutionResult res = collect( a );
assertEquals( "Check artifact list",
createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact } ), res.getArtifacts(),
"Check artifact list" );
ArtifactFilter filter = new ExclusionSetFilter( new String[] { "b" } );
res = collect( a, filter );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" );
}
@Test
public void testResolveCorrectDependenciesWhenDifferentDependenciesOnNearest()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -167,12 +154,14 @@ public class DefaultArtifactCollectorTest
ArtifactSpec f = c1.addDependency( "f", "1.0" );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, e.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, e.artifact, c1.artifact,
f.artifact } ), res.getArtifacts() );
assertEquals( "Check version", "1.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, e.artifact, c1.artifact, f.artifact } ),
res.getArtifacts(), "Check artifact list" );
assertEquals( "1.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" );
}
public void disabledtestResolveCorrectDependenciesWhenDifferentDependenciesOnNewest()
@Test
@Disabled
public void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewest()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
// TODO use newest conflict resolver
@ -186,12 +175,13 @@ public class DefaultArtifactCollectorTest
c1.addDependency( "f", "1.0" );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, e.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, e.artifact, c2.artifact,
d.artifact } ), res.getArtifacts() );
assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, e.artifact, c2.artifact, d.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" );
}
public void disabledtestResolveCorrectDependenciesWhenDifferentDependenciesOnNewestVersionReplaced()
@Test
@Disabled
public void testResolveCorrectDependenciesWhenDifferentDependenciesOnNewestVersionReplaced()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
// TODO use newest conflict resolver
@ -207,11 +197,12 @@ public class DefaultArtifactCollectorTest
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact } ) );
Object[] artifacts = new Object[] { a.artifact, c.artifact, d1.artifact, b2.artifact, e.artifact, g.artifact };
assertEquals( "Check artifact list", createSet( artifacts ), res.getArtifacts() );
assertEquals( "Check version", "1.0", getArtifact( "d", res.getArtifacts() ).getVersion() );
assertEquals( "Check version", "2.0", getArtifact( "b", res.getArtifacts() ).getVersion() );
assertEquals( createSet( artifacts ), res.getArtifacts(), "Check artifact list" );
assertEquals( "1.0", getArtifact( "d", res.getArtifacts() ).getVersion(), "Check version" );
assertEquals( "2.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testResolveNearestNewestIsNearest()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -222,11 +213,11 @@ public class DefaultArtifactCollectorTest
b.addDependency( "c", "2.0" );
ArtifactResolutionResult res = collect( a );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ),
res.getArtifacts() );
assertEquals( "Check version", "3.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "3.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testResolveNearestOldestIsNearest()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -237,11 +228,11 @@ public class DefaultArtifactCollectorTest
b.addDependency( "c", "3.0" );
ArtifactResolutionResult res = collect( a );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ),
res.getArtifacts() );
assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testResolveLocalNewestIsLocal()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -250,10 +241,11 @@ public class DefaultArtifactCollectorTest
ArtifactSpec b = createArtifactSpec( "b", "3.0" );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( "Check version", "3.0", getArtifact( "b", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "3.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testResolveLocalOldestIsLocal()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -262,10 +254,11 @@ public class DefaultArtifactCollectorTest
ArtifactSpec b = createArtifactSpec( "b", "2.0" );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( "Check version", "2.0", getArtifact( "b", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "2.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testResolveLocalWithNewerVersionButLesserScope()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -274,11 +267,12 @@ public class DefaultArtifactCollectorTest
ArtifactSpec b = createArtifactSpec( "junit", "3.8.1", Artifact.SCOPE_TEST );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( "Check version", "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion() );
assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion(), "Check version" );
assertEquals( Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope(), "Check artifactScope" );
}
@Test
public void testResolveLocalWithNewerVersionButLesserScopeResolvedFirst()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -287,11 +281,12 @@ public class DefaultArtifactCollectorTest
a.addDependency( "junit", "3.7" );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( "Check version", "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion() );
assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "3.8.1", getArtifact( "junit", res.getArtifacts() ).getVersion(), "Check version" );
assertEquals( Artifact.SCOPE_TEST, getArtifact( "junit", res.getArtifacts() ).getScope(), "Check artifactScope" );
}
@Test
public void testResolveNearestWithRanges()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -302,11 +297,11 @@ public class DefaultArtifactCollectorTest
b.addDependency( "c", "[1.0,3.0]" );
ArtifactResolutionResult res = collect( a );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ),
res.getArtifacts() );
assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testResolveRangeWithManagedVersion()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -316,11 +311,11 @@ public class DefaultArtifactCollectorTest
ArtifactSpec managedB = createArtifactSpec( "b", "5.0" );
ArtifactResolutionResult res = collect( a, managedB.artifact );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, managedB.artifact } ),
res.getArtifacts() );
assertEquals( "Check version", "5.0", getArtifact( "b", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, managedB.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "5.0", getArtifact( "b", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testCompatibleRanges()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -332,11 +327,11 @@ public class DefaultArtifactCollectorTest
ArtifactResolutionResult res = collect( a );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact } ),
res.getArtifacts() );
assertEquals( "Check version", "2.5", getArtifact( "c", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "2.5", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testIncompatibleRanges()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -351,6 +346,7 @@ public class DefaultArtifactCollectorTest
assertTrue( res.hasVersionRangeViolations() );
}
@Test
public void testUnboundedRangeWhenVersionUnavailable()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -364,6 +360,7 @@ public class DefaultArtifactCollectorTest
assertTrue( res.hasVersionRangeViolations() );
}
@Test
public void testUnboundedRangeBelowLastRelease()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -375,10 +372,11 @@ public class DefaultArtifactCollectorTest
ArtifactResolutionResult res = collect( a );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts() );
assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
assertEquals( createSet( new Object[] { a.artifact, c.artifact } ), res.getArtifacts(), "Check artifact list" );
assertEquals( "2.0", getArtifact( "c", res.getArtifacts() ).getVersion(), "Check version" );
}
@Test
public void testUnboundedRangeAboveLastRelease()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -391,6 +389,7 @@ public class DefaultArtifactCollectorTest
assertTrue( res.hasVersionRangeViolations() );
}
@Test
public void testResolveManagedVersion()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -401,9 +400,10 @@ public class DefaultArtifactCollectorTest
Artifact modifiedB = createArtifactSpec( "b", "5.0", Artifact.SCOPE_RUNTIME ).artifact;
ArtifactResolutionResult res = collect( a, managedVersion );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedB } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, modifiedB } ), res.getArtifacts(), "Check artifact list" );
}
@Test
public void testCollectChangesVersionOfOriginatingArtifactIfInDependencyManagementHasDifferentVersion()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -414,13 +414,14 @@ public class DefaultArtifactCollectorTest
ArtifactResolutionResult result = collect( a, managedVersion );
assertEquals( "collect has modified version in originating artifact", "1.0", artifact.getVersion() );
assertEquals( "1.0", artifact.getVersion(), "collect has modified version in originating artifact" );
Artifact resolvedArtifact = result.getArtifacts().iterator().next();
assertEquals( "Resolved version don't match original artifact version", "1.0", resolvedArtifact.getVersion() );
assertEquals( "1.0", resolvedArtifact.getVersion(), "Resolved version don't match original artifact version" );
}
@Test
public void testResolveCompileScopeOverTestScope()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -432,13 +433,14 @@ public class DefaultArtifactCollectorTest
Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
// local wins now, and irrelevant if not local as test/provided aren't transitive
// assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getArtifactScope() );
assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, artifact.getScope() );
// assertEquals( Artifact.SCOPE_COMPILE, artifact.getArtifactScope(), "Check artifactScope" );
assertEquals( Artifact.SCOPE_TEST, artifact.getScope(), "Check artifactScope" );
}
@Test
public void testResolveRuntimeScopeOverTestScope()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -450,13 +452,14 @@ public class DefaultArtifactCollectorTest
Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact;
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
// local wins now, and irrelevant if not local as test/provided aren't transitive
// assertEquals( "Check artifactScope", Artifact.SCOPE_RUNTIME, artifact.getArtifactScope() );
assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, artifact.getScope() );
// assertEquals( Artifact.SCOPE_RUNTIME, artifact.getArtifactScope(), "Check artifactScope" );
assertEquals( Artifact.SCOPE_TEST, artifact.getScope(), "Check artifactScope" );
}
@Test
public void testResolveCompileScopeOverRuntimeScope()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -469,12 +472,12 @@ public class DefaultArtifactCollectorTest
Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
ArtifactResolutionResult res = collect( createSet( new Object[] { root.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, root.artifact, modifiedC } ),
res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, root.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getScope() );
assertEquals( Artifact.SCOPE_COMPILE, artifact.getScope(), "Check artifactScope" );
}
@Test
public void testResolveCompileScopeOverProvidedScope()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -486,13 +489,14 @@ public class DefaultArtifactCollectorTest
Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
// local wins now, and irrelevant if not local as test/provided aren't transitive
// assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getArtifactScope() );
assertEquals( "Check artifactScope", Artifact.SCOPE_PROVIDED, artifact.getScope() );
// assertEquals( Artifact.SCOPE_COMPILE, artifact.getArtifactScope(), "Check artifactScope" );
assertEquals( Artifact.SCOPE_PROVIDED, artifact.getScope(), "Check artifactScope" );
}
@Test
public void testResolveRuntimeScopeOverProvidedScope()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -504,13 +508,14 @@ public class DefaultArtifactCollectorTest
Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact;
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, c.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, modifiedC } ), res.getArtifacts(), "Check artifact list" );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
// local wins now, and irrelevant if not local as test/provided aren't transitive
// assertEquals( "Check artifactScope", Artifact.SCOPE_RUNTIME, artifact.getArtifactScope() );
assertEquals( "Check artifactScope", Artifact.SCOPE_PROVIDED, artifact.getScope() );
// assertEquals( Artifact.SCOPE_RUNTIME, artifact.getArtifactScope(), "Check artifactScope" );
assertEquals( Artifact.SCOPE_PROVIDED, artifact.getScope(), "Check artifactScope" );
}
@Test
public void testProvidedScopeNotTransitive()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -519,9 +524,10 @@ public class DefaultArtifactCollectorTest
b.addDependency( "c", "3.0", Artifact.SCOPE_PROVIDED );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
}
@Test
public void testOptionalNotTransitive()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -530,9 +536,10 @@ public class DefaultArtifactCollectorTest
b.addDependency( "c", "3.0", true );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
}
@Test
public void testOptionalIncludedAtRoot()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -541,9 +548,10 @@ public class DefaultArtifactCollectorTest
ArtifactSpec b = createArtifactSpec( "b", "1.0", true );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
}
@Test
public void testScopeUpdate()
throws InvalidVersionSpecificationException, ArtifactResolutionException
{
@ -643,19 +651,21 @@ public class DefaultArtifactCollectorTest
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ), filter );
Artifact artifact = getArtifact( "d", res.getArtifacts() );
assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact );
assertEquals( "Check artifactScope", expectedScope, artifact.getScope() );
assertEquals( "Check version", expectedVersion, artifact.getVersion() );
assertNotNull( artifact, "MNG-1895 Dependency was not added to resolution" );
assertEquals( expectedScope, artifact.getScope(), "Check artifactScope" );
assertEquals( expectedVersion, artifact.getVersion(), "Check version" );
ArtifactSpec d = createArtifactSpec( "d", "1.0" );
res = collect( createSet( new Object[] { a.artifact, b.artifact, d.artifact } ), filter );
artifact = getArtifact( "d", res.getArtifacts() );
assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact );
assertEquals( "Check artifactScope", d.artifact.getScope(), artifact.getScope() );
assertEquals( "Check version", "1.0", artifact.getVersion() );
assertNotNull( artifact, "MNG-1895 Dependency was not added to resolution" );
assertEquals( d.artifact.getScope(), artifact.getScope(), "Check artifactScope" );
assertEquals( "1.0", artifact.getVersion(), "Check version" );
}
public void disabledtestOptionalNotTransitiveButVersionIsInfluential()
@Test
@Disabled
public void testOptionalNotTransitiveButVersionIsInfluential()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
ArtifactSpec a = createArtifactSpec( "a", "1.0" );
@ -668,12 +678,12 @@ public class DefaultArtifactCollectorTest
ArtifactSpec c = createArtifactSpec( "c", "3.0" );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact,
e.artifact } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact, c.artifact, d.artifact, e.artifact } ), res.getArtifacts(), "Check artifact list" );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
assertEquals( "Check version", "3.0", artifact.getVersion() );
assertEquals( "3.0", artifact.getVersion(), "Check version" );
}
@Test
public void testTestScopeNotTransitive()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -682,9 +692,10 @@ public class DefaultArtifactCollectorTest
b.addDependency( "c", "3.0", Artifact.SCOPE_TEST );
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ) );
assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts() );
assertEquals( createSet( new Object[] { a.artifact, b.artifact } ), res.getArtifacts(), "Check artifact list" );
}
@Test
public void testSnapshotNotIncluded()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -703,6 +714,8 @@ public class DefaultArtifactCollectorTest
*/
}
@Test
@Disabled("that one does not work")
public void testOverConstrainedVersionException()
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
@ -715,15 +728,11 @@ public class DefaultArtifactCollectorTest
ArtifactSpec c = createArtifactSpec( "c", "3.2.1-v3235e" );
try
{
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact } ) );
}
catch ( OverConstrainedVersionException e )
{
assertTrue( "Versions unordered", e.getMessage().contains( "[3.2.1-v3235e, 3.3.0-v3346]" ) );
assertTrue( "DependencyTrail unresolved", e.getMessage().contains( "Path to dependency:" ) );
}
OverConstrainedVersionException e = assertThrows(
OverConstrainedVersionException.class,
() -> collect( createSet( new Object[] { a.artifact } ) ) );
assertTrue( e.getMessage().contains( "[3.2.1-v3235e, 3.3.0-v3346]" ), "Versions unordered" );
assertTrue( e.getMessage().contains( "Path to dependency:" ), "DependencyTrail unresolved" );
}
private Artifact getArtifact( String id, Set artifacts )

View File

@ -19,20 +19,22 @@ package org.apache.maven.repository.legacy.resolver.conflict;
* under the License.
*/
import java.util.Collections;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ResolutionNode;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import javax.inject.Inject;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Provides a basis for testing conflict resolvers.
@ -71,25 +73,17 @@ public abstract class AbstractConflictResolverTest
// TestCase methods -------------------------------------------------------
/*
* @see junit.framework.TestCase#setUp()
*/
@BeforeEach
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
super.customizeContainerConfiguration( containerConfiguration );
containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
public void setUp()
throws Exception
{
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
conflictResolver = (ConflictResolver) lookup( ConflictResolver.ROLE, roleHint );
conflictResolver = lookup( ConflictResolver.ROLE, roleHint );
a1 = createArtifact( "a", "1.0" );
a2 = createArtifact( "a", "2.0" );
@ -99,7 +93,9 @@ public abstract class AbstractConflictResolverTest
/*
* @see org.codehaus.plexus.PlexusTestCase#tearDown()
*/
protected void tearDown() throws Exception
@AfterEach
@Override
public void tearDown() throws Exception
{
a1 = null;
a2 = null;
@ -121,8 +117,8 @@ public abstract class AbstractConflictResolverTest
{
ResolutionNode resolvedNode = getConflictResolver().resolveConflict( actualNode1, actualNode2 );
assertNotNull( "Expected resolvable", resolvedNode );
assertEquals( "Resolution node", expectedNode, resolvedNode );
assertNotNull( resolvedNode, "Expected resolvable" );
assertEquals( expectedNode, resolvedNode, "Resolution node" );
}
protected Artifact createArtifact( String id, String version ) throws InvalidVersionSpecificationException

View File

@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict;
*/
import org.apache.maven.artifact.resolver.ResolutionNode;
import org.junit.jupiter.api.Test;
/**
* Tests <code>FarthestConflictResolver</code>.
@ -47,6 +48,7 @@ public class FarthestConflictResolverTest
* b:1.0 -&gt; a:2.0
* </pre>
*/
@Test
public void testDepth()
{
ResolutionNode a1n = createResolutionNode( a1);
@ -63,6 +65,7 @@ public class FarthestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testDepthReversed()
{
ResolutionNode b1n = createResolutionNode( b1 );
@ -79,6 +82,7 @@ public class FarthestConflictResolverTest
* a:2.0
* </pre>
*/
@Test
public void testEqual()
{
ResolutionNode a1n = createResolutionNode( a1 );
@ -94,6 +98,7 @@ public class FarthestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testEqualReversed()
{
ResolutionNode a2n = createResolutionNode( a2);

View File

@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict;
*/
import org.apache.maven.artifact.resolver.ResolutionNode;
import org.junit.jupiter.api.Test;
/**
* Tests <code>NearestConflictResolver</code>.
@ -47,6 +48,7 @@ public class NearestConflictResolverTest
* b:1.0 -&gt; a:2.0
* </pre>
*/
@Test
public void testDepth()
{
ResolutionNode a1n = createResolutionNode( a1);
@ -63,6 +65,7 @@ public class NearestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testDepthReversed()
{
ResolutionNode b1n = createResolutionNode( b1 );
@ -79,6 +82,7 @@ public class NearestConflictResolverTest
* a:2.0
* </pre>
*/
@Test
public void testEqual()
{
ResolutionNode a1n = createResolutionNode( a1 );
@ -94,6 +98,7 @@ public class NearestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testEqualReversed()
{
ResolutionNode a2n = createResolutionNode( a2);

View File

@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict;
*/
import org.apache.maven.artifact.resolver.ResolutionNode;
import org.junit.jupiter.api.Test;
/**
* Tests <code>NewestConflictResolver</code>.
@ -47,6 +48,7 @@ public class NewestConflictResolverTest
* b:1.0 -&gt; a:2.0
* </pre>
*/
@Test
public void testDepth()
{
ResolutionNode a1n = createResolutionNode( a1 );
@ -63,6 +65,7 @@ public class NewestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testDepthReversed()
{
ResolutionNode b1n = createResolutionNode( b1 );
@ -79,6 +82,7 @@ public class NewestConflictResolverTest
* a:2.0
* </pre>
*/
@Test
public void testEqual()
{
ResolutionNode a1n = createResolutionNode( a1 );
@ -94,6 +98,7 @@ public class NewestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testEqualReversed()
{
ResolutionNode a2n = createResolutionNode( a2 );

View File

@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.resolver.conflict;
*/
import org.apache.maven.artifact.resolver.ResolutionNode;
import org.junit.jupiter.api.Test;
/**
* Tests <code>OldestConflictResolver</code>.
@ -47,6 +48,7 @@ public class OldestConflictResolverTest
* b:1.0 -&gt; a:2.0
* </pre>
*/
@Test
public void testDepth()
{
ResolutionNode a1n = createResolutionNode( a1 );
@ -64,6 +66,7 @@ public class OldestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testDepthReversed()
{
ResolutionNode b1n = createResolutionNode( b1 );
@ -80,6 +83,7 @@ public class OldestConflictResolverTest
* a:2.0
* </pre>
*/
@Test
public void testEqual()
{
ResolutionNode a1n = createResolutionNode( a1 );
@ -95,6 +99,7 @@ public class OldestConflictResolverTest
* a:1.0
* </pre>
*/
@Test
public void testEqualReversed()
{
ResolutionNode a2n = createResolutionNode( a2);

View File

@ -15,14 +15,15 @@ package org.apache.maven.repository.metadata;
* the License.
*/
import javax.inject.Inject;
import org.apache.maven.artifact.ArtifactScopeEnum;
import org.apache.maven.repository.metadata.ArtifactMetadata;
import org.apache.maven.repository.metadata.ClasspathContainer;
import org.apache.maven.repository.metadata.ClasspathTransformation;
import org.apache.maven.repository.metadata.MetadataGraph;
import org.apache.maven.repository.metadata.MetadataGraphEdge;
import org.apache.maven.repository.metadata.MetadataGraphVertex;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
*
@ -33,6 +34,7 @@ import org.codehaus.plexus.PlexusTestCase;
public class DefaultClasspathTransformationTest
extends PlexusTestCase
{
@Inject
ClasspathTransformation transform;
MetadataGraph graph;
@ -42,11 +44,11 @@ extends PlexusTestCase
MetadataGraphVertex v3;
MetadataGraphVertex v4;
//------------------------------------------------------------------------------------------
@BeforeEach
@Override
protected void setUp() throws Exception
public void setUp() throws Exception
{
super.setUp();
transform = (ClasspathTransformation) lookup( ClasspathTransformation.ROLE, "default" );
graph = new MetadataGraph( 4, 3 );
/*
@ -74,6 +76,7 @@ extends PlexusTestCase
graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.test, null, 2, 2 ) );
}
//------------------------------------------------------------------------------------------
@Test
public void testCompileClasspathTransform()
throws Exception
{
@ -81,11 +84,12 @@ extends PlexusTestCase
res = transform.transform( graph, ArtifactScopeEnum.compile, false );
assertNotNull("null classpath container after compile transform", res );
assertNotNull("null classpath after compile transform", res.getClasspath() );
assertEquals("compile classpath should have 3 entries", 3, res.getClasspath().size() );
assertNotNull( res, "null classpath container after compile transform" );
assertNotNull( res.getClasspath(), "null classpath after compile transform" );
assertEquals( 3, res.getClasspath().size(), "compile classpath should have 3 entries" );
}
//------------------------------------------------------------------------------------------
@Test
public void testRuntimeClasspathTransform()
throws Exception
{
@ -93,14 +97,15 @@ extends PlexusTestCase
res = transform.transform( graph, ArtifactScopeEnum.runtime, false );
assertNotNull("null classpath container after runtime transform", res );
assertNotNull("null classpath after runtime transform", res.getClasspath() );
assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() );
assertNotNull( res, "null classpath container after runtime transform" );
assertNotNull( res.getClasspath(), "null classpath after runtime transform" );
assertEquals( 4, res.getClasspath().size(), "runtime classpath should have 4 entries" );
ArtifactMetadata md = res.getClasspath().get(3);
assertEquals("runtime artifact version should be 1.1", "1.1", md.getVersion() );
assertEquals("1.1", md.getVersion(), "runtime artifact version should be 1.1" );
}
//------------------------------------------------------------------------------------------
@Test
public void testTestClasspathTransform()
throws Exception
{
@ -108,12 +113,12 @@ extends PlexusTestCase
res = transform.transform( graph, ArtifactScopeEnum.test, false );
assertNotNull("null classpath container after runtime transform", res );
assertNotNull("null classpath after runtime transform", res.getClasspath() );
assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() );
assertNotNull( res, "null classpath container after test transform" );
assertNotNull( res.getClasspath(), "null classpath after test transform" );
assertEquals( 4, res.getClasspath().size(), "test classpath should have 4 entries" );
ArtifactMetadata md = res.getClasspath().get(3);
assertEquals("test artifact version should be 1.2", "1.2", md.getVersion() );
assertEquals("1.2", md.getVersion(), "test artifact version should be 1.2" );
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------

View File

@ -15,10 +15,10 @@ package org.apache.maven.repository.metadata;
* the License.
*/
import org.apache.maven.repository.metadata.GraphConflictResolutionPolicy;
import org.apache.maven.repository.metadata.MetadataGraphEdge;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
*
@ -27,33 +27,32 @@ import junit.framework.TestCase;
*/
public class DefaultGraphConflictResolutionPolicyTest
extends TestCase
{
GraphConflictResolutionPolicy policy;
MetadataGraphEdge e1;
MetadataGraphEdge e2;
MetadataGraphEdge e3;
//------------------------------------------------------------------------------------------
@Override
protected void setUp() throws Exception
{
super.setUp();
policy = new DefaultGraphConflictResolutionPolicy();
e1 = new MetadataGraphEdge( "1.1", true, null, null, 2, 1 );
e2 = new MetadataGraphEdge( "1.2", true, null, null, 3, 2 );
e3 = new MetadataGraphEdge( "1.2", true, null, null, 2, 3 );
}
@BeforeEach
public void setUp() throws Exception
{
policy = new DefaultGraphConflictResolutionPolicy();
e1 = new MetadataGraphEdge( "1.1", true, null, null, 2, 1 );
e2 = new MetadataGraphEdge( "1.2", true, null, null, 3, 2 );
e3 = new MetadataGraphEdge( "1.2", true, null, null, 2, 3 );
}
//------------------------------------------------------------------------------------------
@Test
public void testDefaultPolicy()
throws Exception
{
MetadataGraphEdge res;
res = policy.apply( e1, e2 );
assertEquals( "Wrong depth edge selected", "1.1", res.getVersion() );
assertEquals( "1.1", res.getVersion(), "Wrong depth edge selected" );
res = policy.apply( e1, e3 );
assertEquals( "Wrong version edge selected", "1.2", res.getVersion() );
assertEquals( "1.2", res.getVersion(), "Wrong version edge selected" );
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------

View File

@ -15,14 +15,15 @@ package org.apache.maven.repository.metadata;
* the License.
*/
import javax.inject.Inject;
import org.apache.maven.artifact.ArtifactScopeEnum;
import org.apache.maven.repository.metadata.ArtifactMetadata;
import org.apache.maven.repository.metadata.GraphConflictResolver;
import org.apache.maven.repository.metadata.MetadataGraph;
import org.apache.maven.repository.metadata.MetadataGraphEdge;
import org.apache.maven.repository.metadata.MetadataGraphVertex;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
*
@ -33,8 +34,7 @@ import org.codehaus.plexus.logging.Logger;
public class DefaultGraphConflictResolverTest
extends PlexusTestCase
{
Logger log;
@Inject
GraphConflictResolver resolver;
MetadataGraph graph;
@ -44,11 +44,11 @@ extends PlexusTestCase
MetadataGraphVertex v3;
MetadataGraphVertex v4;
//------------------------------------------------------------------------------------------
@BeforeEach
@Override
protected void setUp() throws Exception
public void setUp() throws Exception
{
super.setUp();
resolver = (GraphConflictResolver) lookup( GraphConflictResolver.ROLE, "default" );
/*
* v2
@ -76,6 +76,7 @@ extends PlexusTestCase
graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.provided, null, 2, 2 ) );
}
//------------------------------------------------------------------------------------------
@Test
public void testCompileResolution()
throws Exception
{
@ -83,24 +84,25 @@ extends PlexusTestCase
res = resolver.resolveConflicts( graph, ArtifactScopeEnum.compile );
assertNotNull("null graph after resolver", res );
assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() );
assertNotNull( res, "null graph after resolver" );
assertNotNull( res.getVertices(), "no vertices in the resulting graph after resolver" );
assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) );
assertNotNull( res.getExcidentEdges(v1), "no edges in the resulting graph after resolver" );
assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() );
assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() );
assertEquals( 4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver" );
assertEquals( 2, res.getExcidentEdges(v1).size(), "wrong # of excident edges in the resulting graph entry after resolver" );
assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() );
assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v2).size(), "wrong # of v2 incident edges in the resulting graph after resolver" );
assertEquals( "1.2", res.getIncidentEdges(v2).get(0).getVersion(), "wrong edge v1-v2 in the resulting graph after resolver" );
assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() );
assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver" );
assertEquals( "1.1", res.getIncidentEdges(v3).get(0).getVersion(), "wrong edge v1-v3 in the resulting graph after resolver" );
assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() );
assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver" );
assertEquals( "1.2", res.getIncidentEdges(v4).get(0).getVersion(), "wrong edge v3-v4 in the resulting graph after resolver" );
}
//------------------------------------------------------------------------------------------
@Test
public void testRuntimeResolution()
throws Exception
{
@ -108,23 +110,24 @@ extends PlexusTestCase
res = resolver.resolveConflicts( graph, ArtifactScopeEnum.runtime );
assertNotNull("null graph after resolver", res );
assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() );
assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) );
assertNotNull( res, "null graph after resolver" );
assertNotNull( res.getVertices(), "no vertices in the resulting graph after resolver" );
assertNotNull( res.getExcidentEdges(v1), "no edges in the resulting graph after resolver" );
assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() );
assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() );
assertEquals( 4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver" );
assertEquals( 2, res.getExcidentEdges(v1).size(), "wrong # of excident edges in the resulting graph entry after resolver" );
assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() );
assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v2).size(), "wrong # of v2 incident edges in the resulting graph after resolver" );
assertEquals( "1.2", res.getIncidentEdges(v2).get(0).getVersion(), "wrong edge v1-v2 in the resulting graph after resolver" );
assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() );
assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver" );
assertEquals( "1.1", res.getIncidentEdges(v3).get(0).getVersion(), "wrong edge v1-v3 in the resulting graph after resolver" );
assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() );
assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v4).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver" );
assertEquals( "1.1", res.getIncidentEdges(v4).get(0).getVersion(), "wrong edge v3-v4 in the resulting graph after resolver" );
}
//------------------------------------------------------------------------------------------
@Test
public void testTestResolution()
throws Exception
{
@ -132,21 +135,21 @@ extends PlexusTestCase
res = resolver.resolveConflicts( graph, ArtifactScopeEnum.test );
assertNotNull("null graph after resolver", res );
assertNotNull("no vertices in the resulting graph after resolver", res.getVertices() );
assertNotNull("no edges in the resulting graph after resolver", res.getExcidentEdges(v1) );
assertNotNull( res, "null graph after resolver" );
assertNotNull( res.getVertices(), "no vertices in the resulting graph after resolver" );
assertNotNull( res.getExcidentEdges(v1), "no edges in the resulting graph after resolver" );
assertEquals( "wrong # of vertices in the resulting graph after resolver", 4, res.getVertices().size() );
assertEquals( "wrong # of excident edges in the resulting graph entry after resolver", 2, res.getExcidentEdges(v1).size() );
assertEquals( 4, res.getVertices().size(), "wrong # of vertices in the resulting graph after resolver" );
assertEquals( 2, res.getExcidentEdges(v1).size(), "wrong # of excident edges in the resulting graph entry after resolver" );
assertEquals( "wrong # of v2 incident edges in the resulting graph after resolver", 1, res.getIncidentEdges(v2).size() );
assertEquals( "wrong edge v1-v2 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v2).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v2).size(), "wrong # of v2 incident edges in the resulting graph after resolver" );
assertEquals( "1.2", res.getIncidentEdges(v2).get(0).getVersion(), "wrong edge v1-v2 in the resulting graph after resolver" );
assertEquals( "wrong # of edges v1-v3 in the resulting graph after resolver", 1, res.getIncidentEdges(v3).size() );
assertEquals( "wrong edge v1-v3 in the resulting graph after resolver", "1.1", res.getIncidentEdges(v3).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v3).size(), "wrong # of edges v1-v3 in the resulting graph after resolver" );
assertEquals( "1.1", res.getIncidentEdges(v3).get(0).getVersion(), "wrong edge v1-v3 in the resulting graph after resolver" );
assertEquals( "wrong # of edges v3-v4 in the resulting graph after resolver", 1, res.getIncidentEdges(v4).size() );
assertEquals( "wrong edge v3-v4 in the resulting graph after resolver", "1.2", res.getIncidentEdges(v4).get(0).getVersion() );
assertEquals( 1, res.getIncidentEdges(v4).size(), "wrong # of edges v3-v4 in the resulting graph after resolver" );
assertEquals( "1.2", res.getIncidentEdges(v4).get(0).getVersion(), "wrong edge v3-v4 in the resulting graph after resolver" );
}
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------

View File

@ -19,6 +19,10 @@ package org.apache.maven.repository.metadata;
* under the License.
*/
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -31,9 +35,6 @@ import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Named
@Singleton

View File

@ -156,6 +156,11 @@ under the License.
<artifactId>xmlunit-assertj</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-test-support</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -22,7 +22,6 @@ package org.apache.maven;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
@ -45,14 +44,14 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.test.PlexusTestCase;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.junit.jupiter.api.BeforeEach;
import javax.inject.Inject;
@ -65,22 +64,6 @@ public abstract class AbstractCoreMavenComponentTestCase
@Inject
protected org.apache.maven.project.ProjectBuilder projectBuilder;
@Override
protected void setUp() throws Exception
{
super.setUp();
getContainer();
}
@Override
protected synchronized void setupContainer()
{
super.setupContainer();
( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
abstract protected String getProjectsDirectory();
protected File getProject( String name )

View File

@ -1,5 +1,3 @@
package org.apache.maven;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -18,6 +16,12 @@ package org.apache.maven;
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven;
import java.io.File;
import java.nio.file.Files;
import javax.inject.Inject;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
@ -25,13 +29,10 @@ import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import java.io.File;
import java.nio.file.Files;
import javax.inject.Inject;
import org.junit.jupiter.api.Test;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DefaultMavenTest
extends AbstractCoreMavenComponentTestCase
@ -40,6 +41,14 @@ public class DefaultMavenTest
@Inject
private Maven maven;
@Override
protected String getProjectsDirectory()
{
return "src/test/projects/default-maven";
}
@Test
public void testThatErrorDuringProjectDependencyGraphCreationAreStored()
throws Exception
{
@ -50,13 +59,7 @@ public class DefaultMavenTest
assertEquals( ProjectCycleException.class, result.getExceptions().get( 0 ).getClass() );
}
@Override
protected String getProjectsDirectory()
{
return "src/test/projects/default-maven";
}
@Test
public void testMavenProjectNoDuplicateArtifacts()
throws Exception
{

View File

@ -29,6 +29,10 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class MavenLifecycleParticipantTest
extends AbstractCoreMavenComponentTestCase
@ -109,6 +113,7 @@ public class MavenLifecycleParticipantTest
return "src/test/projects/lifecycle-listener";
}
@Test
public void testDependencyInjection()
throws Exception
{
@ -126,7 +131,7 @@ public class MavenLifecycleParticipantTest
request.setGoals( Arrays.asList( "validate" ) );
MavenExecutionResult result = maven.execute( request );
assertFalse( result.getExceptions().toString(), result.hasExceptions() );
assertFalse( result.hasExceptions(), result.getExceptions().toString() );
MavenProject project = result.getProject();
@ -138,6 +143,7 @@ public class MavenLifecycleParticipantTest
assertEquals( INJECTED_ARTIFACT_ID, artifacts.get( 0 ).getArtifactId() );
}
@Test
public void testReactorDependencyInjection()
throws Exception
{
@ -161,7 +167,7 @@ public class MavenLifecycleParticipantTest
request.setGoals( Arrays.asList( "validate" ) );
MavenExecutionResult result = maven.execute( request );
assertFalse( result.getExceptions().toString(), result.hasExceptions() );
assertFalse( result.hasExceptions(), result.getExceptions().toString() );
List<String> order = new ArrayList<>();
for ( MavenProject project : result.getTopologicallySortedProjects() )

View File

@ -17,14 +17,9 @@ package org.apache.maven;
import org.apache.maven.exception.ExceptionHandler;
import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.junit.jupiter.api.Test;
import javax.inject.Inject;
import java.io.File;
import java.util.Collections;
public class MavenTest
extends AbstractCoreMavenComponentTestCase
@ -35,20 +30,12 @@ public class MavenTest
@Inject
private ExceptionHandler exceptionHandler;
@Override
protected synchronized void setupContainer()
{
super.setupContainer();
( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
protected String getProjectsDirectory()
{
return "src/test/projects/lifecycle-executor";
}
@Test
public void testLifecycleExecutionUsingADefaultLifecyclePhase()
throws Exception
{

View File

@ -15,9 +15,6 @@ package org.apache.maven;
* the License.
*/
import static org.hamcrest.Matchers.endsWith;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.util.Collections;
import java.util.List;
@ -29,6 +26,11 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import javax.inject.Inject;
import org.junit.jupiter.api.Test;
import static org.hamcrest.Matchers.endsWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
public class ProjectDependenciesResolverTest
extends AbstractCoreMavenComponentTestCase
@ -42,6 +44,7 @@ public class ProjectDependenciesResolverTest
}
/*
@Test
public void testExclusionsInDependencies()
throws Exception
{
@ -65,6 +68,7 @@ public class ProjectDependenciesResolverTest
}
*/
@Test
public void testSystemScopeDependencies()
throws Exception
{
@ -79,6 +83,7 @@ public class ProjectDependenciesResolverTest
assertEquals( 1, artifactDependencies.size() );
}
@Test
public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements()
throws Exception
{

View File

@ -22,12 +22,16 @@ package org.apache.maven.artifact.handler;
import java.io.File;
import java.util.List;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ArtifactHandlerTest
extends PlexusTestCase
{
@Test
public void testAptConsistency()
throws Exception
{
@ -47,7 +51,7 @@ public class ArtifactHandlerTest
int i = 0;
for ( String col : cols )
{
assertEquals( "Wrong column header", expected[i++], col.trim() );
assertEquals( expected[i++], col.trim(), "Wrong column header" );
}
}
else if ( line.startsWith( "|" ) )
@ -63,12 +67,12 @@ public class ArtifactHandlerTest
String includesDependencies = trimApt( cols[7] );
ArtifactHandler handler = lookup( ArtifactHandler.class, type );
assertEquals( type + " extension", handler.getExtension(), extension );
assertEquals( type + " packaging", handler.getPackaging(), packaging );
assertEquals( type + " classifier", handler.getClassifier(), classifier );
assertEquals( type + " language", handler.getLanguage(), language );
assertEquals( type + " addedToClasspath", handler.isAddedToClasspath() ? "true" : null, addedToClasspath );
assertEquals( type + " includesDependencies", handler.isIncludesDependencies() ? "true" : null, includesDependencies );
assertEquals( handler.getExtension(), extension, type + " extension" );
assertEquals( handler.getPackaging(), packaging, type + " packaging" );
assertEquals( handler.getClassifier(), classifier, type + " classifier" );
assertEquals( handler.getLanguage(), language, type + " language" );
assertEquals( handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath" );
assertEquals( handler.isIncludesDependencies() ? "true" : null, includesDependencies, type + " includesDependencies" );
}
}
}

View File

@ -21,14 +21,14 @@ package org.apache.maven.artifact.resolver.filter;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Exclusion;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -36,7 +36,7 @@ public class ExclusionArtifactFilterTest
{
private Artifact artifact;
@Before
@BeforeEach
public void setup()
{
artifact = mock( Artifact.class );

View File

@ -27,34 +27,32 @@ import org.apache.maven.configuration.internal.DefaultBeanConfigurator;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Benjamin Bentmann
*/
public class DefaultBeanConfiguratorTest
extends TestCase
{
private BeanConfigurator configurator;
@Override
protected void setUp()
@BeforeEach
public void setUp()
throws Exception
{
super.setUp();
configurator = new DefaultBeanConfigurator();
}
@Override
protected void tearDown()
@AfterEach
public void tearDown()
throws Exception
{
configurator = null;
super.tearDown();
}
private Xpp3Dom toConfig( String xml )
@ -69,6 +67,7 @@ public class DefaultBeanConfiguratorTest
}
}
@Test
public void testMinimal()
throws BeanConfigurationException
{
@ -84,6 +83,7 @@ public class DefaultBeanConfiguratorTest
assertEquals( new File( "test" ), bean.file );
}
@Test
public void testPreAndPostProcessing()
throws BeanConfigurationException
{
@ -111,6 +111,7 @@ public class DefaultBeanConfiguratorTest
assertEquals( new File( "base/test" ).getAbsoluteFile(), bean.file );
}
@Test
public void testChildConfigurationElement()
throws BeanConfigurationException
{

View File

@ -30,9 +30,9 @@ import org.apache.maven.plugin.PluginContainerException;
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author <a href="mailto:baerrach@apache.org">Barrie Treloar</a>

View File

@ -22,8 +22,8 @@ package org.apache.maven.execution;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Optional;
@ -40,7 +40,7 @@ public class DefaultBuildResumptionAnalyzerTest
private MavenExecutionResult executionResult;
@Before
@BeforeEach
public void before() {
executionResult = new DefaultMavenExecutionResult();
}

View File

@ -21,9 +21,7 @@ package org.apache.maven.execution;
import org.apache.maven.model.Build;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
@ -34,7 +32,6 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
@RunWith( MockitoJUnitRunner.class )
public class DefaultBuildResumptionDataRepositoryTest
{
private final DefaultBuildResumptionDataRepository repository = new DefaultBuildResumptionDataRepository();

View File

@ -8,7 +8,10 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.settings.Profile;
import org.apache.maven.settings.Repository;
import org.apache.maven.settings.Settings;
import org.eclipse.sisu.launch.InjectedTestCase;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -30,11 +33,12 @@ import org.eclipse.sisu.launch.InjectedTestCase;
*/
public class DefaultMavenExecutionRequestPopulatorTest
extends InjectedTestCase
extends PlexusTestCase
{
@Inject
MavenExecutionRequestPopulator testee;
@Test
public void testPluginRepositoryInjection()
throws Exception
{

View File

@ -20,14 +20,14 @@ package org.apache.maven.execution;
*/
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.List;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Benjamin Bentmann

View File

@ -16,17 +16,19 @@ package org.apache.maven.execution.scope.internal;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.inject.Key;
import org.apache.maven.execution.MojoExecutionEvent;
import org.apache.maven.execution.scope.WeakMojoExecutionListener;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
import com.google.inject.Key;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class MojoExecutionScopeTest
extends TestCase
{
@Test
public void testNestedEnter()
throws Exception
{
@ -48,16 +50,10 @@ public class MojoExecutionScopeTest
scope.exit();
try
{
scope.exit();
fail();
}
catch ( IllegalStateException expected )
{
}
assertThrows( IllegalStateException.class, () -> scope.exit() );
}
@Test
public void testMultiKeyInstance()
throws Exception
{

View File

@ -37,12 +37,12 @@ import org.apache.maven.project.collector.MultiModuleCollectionStrategy;
import org.apache.maven.project.collector.PomlessCollectionStrategy;
import org.apache.maven.project.collector.ProjectsSelector;
import org.apache.maven.project.collector.RequestPomCollectionStrategy;
import org.apache.maven.test.Parameter;
import org.apache.maven.test.Parameterized;
import org.apache.maven.test.Parameters;
import org.apache.maven.test.Test;
import org.codehaus.plexus.util.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import java.io.File;
import java.util.ArrayList;
@ -56,15 +56,15 @@ import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.function.Function.identity;
import static junit.framework.TestCase.assertEquals;
import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM;
import static org.apache.maven.execution.MavenExecutionRequest.REACTOR_MAKE_UPSTREAM;
import static org.apache.maven.graph.DefaultGraphBuilderTest.ScenarioBuilder.scenario;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith( Parameterized.class )
@Parameterized
public class DefaultGraphBuilderTest
{
/*
@ -104,13 +104,20 @@ public class DefaultGraphBuilderTest
private Map<String, MavenProject> artifactIdProjectMap;
// Parameters for the test
private final String parameterDescription;
private final List<String> parameterSelectedProjects;
private final List<String> parameterExcludedProjects;
private final String parameterResumeFrom;
private final String parameterMakeBehavior;
private final List<String> parameterExpectedResult;
private final File parameterRequestedPom;
@Parameter( 0 )
private String parameterDescription;
@Parameter( 1 )
private List<String> parameterSelectedProjects;
@Parameter( 2 )
private List<String> parameterExcludedProjects;
@Parameter( 3 )
private String parameterResumeFrom;
@Parameter( 4 )
private String parameterMakeBehavior;
@Parameter( 5 )
private List<String> parameterExpectedResult;
@Parameter( 6 )
private File parameterRequestedPom;
@Parameters(name = "{index}. {0}")
public static Collection<Object[]> parameters()
@ -191,17 +198,6 @@ public class DefaultGraphBuilderTest
);
}
public DefaultGraphBuilderTest( String description, List<String> selectedProjects, List<String> excludedProjects, String resumedFrom, String makeBehavior, List<String> expectedReactorProjects, File requestedPom )
{
this.parameterDescription = description;
this.parameterSelectedProjects = selectedProjects;
this.parameterExcludedProjects = excludedProjects;
this.parameterResumeFrom = resumedFrom;
this.parameterMakeBehavior = makeBehavior;
this.parameterExpectedResult = expectedReactorProjects;
this.parameterRequestedPom = requestedPom;
}
@Test
public void testGetReactorProjects()
{
@ -226,10 +222,10 @@ public class DefaultGraphBuilderTest
List<MavenProject> expectedReactorProjects = parameterExpectedResult.stream()
.map( artifactIdProjectMap::get )
.collect( Collectors.toList());
assertEquals( parameterDescription, expectedReactorProjects, actualReactorProjects );
assertEquals( expectedReactorProjects, actualReactorProjects, parameterDescription );
}
@Before
@BeforeEach
public void before() throws Exception
{
graphBuilder = new DefaultGraphBuilder(

View File

@ -14,21 +14,22 @@
*/
package org.apache.maven.graph;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.List;
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Kristian Rosenvold
*/
public class DefaultProjectDependencyGraphTest
extends TestCase
{
private final MavenProject aProject = createA();
@ -45,6 +46,7 @@ public class DefaultProjectDependencyGraphTest
private final MavenProject transitiveOnly =
createProject( Arrays.asList( toDependency( depender3 ) ), "depender5" );
@Test
public void testGetSortedProjects()
throws DuplicateProjectException, CycleDetectedException
{
@ -54,6 +56,7 @@ public class DefaultProjectDependencyGraphTest
assertEquals( depender1, sortedProjects.get( 1 ) );
}
@Test
public void testVerifyExpectedParentStructure()
throws CycleDetectedException, DuplicateProjectException
{
@ -66,6 +69,7 @@ public class DefaultProjectDependencyGraphTest
assertEquals( depender3, sortedProjects.get( 3 ) );
}
@Test
public void testVerifyThatDownstreamProjectsComeInSortedOrder()
throws CycleDetectedException, DuplicateProjectException
{
@ -76,6 +80,7 @@ public class DefaultProjectDependencyGraphTest
assertEquals( depender3, downstreamProjects.get( 2 ) );
}
@Test
public void testTransitivesInOrder()
throws CycleDetectedException, DuplicateProjectException
{
@ -89,6 +94,7 @@ public class DefaultProjectDependencyGraphTest
assertEquals( depender2, downstreamProjects.get( 3 ) );
}
@Test
public void testNonTransitivesInOrder()
throws CycleDetectedException, DuplicateProjectException
{
@ -102,6 +108,7 @@ public class DefaultProjectDependencyGraphTest
assertEquals( depender2, downstreamProjects.get( 3 ) );
}
@Test
public void testWithTransitiveOnly()
throws CycleDetectedException, DuplicateProjectException
{
@ -115,6 +122,7 @@ public class DefaultProjectDependencyGraphTest
assertEquals( depender2, downstreamProjects.get( 3 ) );
}
@Test
public void testWithMissingTransitiveOnly()
throws CycleDetectedException, DuplicateProjectException
{
@ -127,6 +135,7 @@ public class DefaultProjectDependencyGraphTest
assertEquals( depender2, downstreamProjects.get( 2 ) );
}
@Test
public void testGetUpstreamProjects()
throws CycleDetectedException, DuplicateProjectException
{

View File

@ -26,7 +26,7 @@ import java.nio.file.Paths;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.TransformerContext;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.xmlunit.assertj.XmlAssert;
public class ConsumerModelSourceTransformerTest

View File

@ -15,25 +15,22 @@ package org.apache.maven.lifecycle;
* the License.
*/
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.hasSize;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
import java.util.Collections;
import java.util.List;
import org.apache.maven.test.PlexusTestCase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
/**
* @author Kristian Rosenvold
@ -45,30 +42,7 @@ public class DefaultLifecyclesTest
@Inject
private DefaultLifecycles defaultLifeCycles;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration configuration )
{
super.customizeContainerConfiguration( configuration );
configuration.setAutoWiring( true );
configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp() throws Exception
{
super.setUp();
getContainer();
}
@Override
protected synchronized void setupContainer()
{
super.setupContainer();
( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
@Test
public void testDefaultLifecycles()
{
final List<Lifecycle> lifecycles = defaultLifeCycles.getLifeCycles();
@ -76,6 +50,7 @@ public class DefaultLifecyclesTest
assertThat( DefaultLifecycles.STANDARD_LIFECYCLES, arrayWithSize( 4 ) );
}
@Test
public void testDefaultLifecycle()
{
final Lifecycle lifecycle = getLifeCycleById( "default" );
@ -83,6 +58,7 @@ public class DefaultLifecyclesTest
assertThat( lifecycle.getPhases(), hasSize( 23 ) );
}
@Test
public void testCleanLifecycle()
{
final Lifecycle lifecycle = getLifeCycleById( "clean" );
@ -90,6 +66,7 @@ public class DefaultLifecyclesTest
assertThat( lifecycle.getPhases(), hasSize( 3 ) );
}
@Test
public void testSiteLifecycle()
{
final Lifecycle lifecycle = getLifeCycleById( "site" );
@ -97,6 +74,7 @@ public class DefaultLifecyclesTest
assertThat( lifecycle.getPhases(), hasSize( 4 ) );
}
@Test
public void testWrapperLifecycle()
{
final Lifecycle lifecycle = getLifeCycleById( "wrapper" );
@ -104,6 +82,7 @@ public class DefaultLifecyclesTest
assertThat( lifecycle.getPhases(), hasSize( 1 ) );
}
@Test
public void testCustomLifecycle()
{
List<Lifecycle> myLifecycles = new ArrayList<>();

View File

@ -25,6 +25,11 @@ import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
import org.apache.maven.lifecycle.internal.MojoExecutor;
import javax.inject.Inject;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Just asserts that it's able to create those components. Handy when CDI container gets a nervous breakdown.
@ -64,6 +69,7 @@ public class LifecycleExecutorSubModulesTest
return "src/test/projects/lifecycle-executor";
}
@Test
public void testCreation()
throws Exception
{

View File

@ -15,9 +15,6 @@ package org.apache.maven.lifecycle;
* the License.
*/
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@ -45,6 +42,16 @@ import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import javax.inject.Inject;
@ -72,6 +79,7 @@ public class LifecycleExecutorTest
// Tests which exercise the lifecycle executor when it is dealing with default lifecycle phases.
// -----------------------------------------------------------------------------------------------
@Test
public void testCalculationOfBuildPlanWithIndividualTaskWherePluginIsSpecifiedInThePom()
throws Exception
{
@ -92,6 +100,7 @@ public class LifecycleExecutorTest
assertEquals( "0.1", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() );
}
@Test
public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanLifecycle()
throws Exception
{
@ -111,6 +120,7 @@ public class LifecycleExecutorTest
assertEquals( "0.1", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() );
}
@Test
public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanCleanGoal()
throws Exception
{
@ -233,6 +243,7 @@ public class LifecycleExecutorTest
"configuration/models[1]/model" ) );
}
@Test
public void testLifecycleQueryingUsingADefaultLifecyclePhase()
throws Exception
{
@ -263,6 +274,7 @@ public class LifecycleExecutorTest
assertEquals( "jar:jar", executionPlan.get( 7 ).getMojoDescriptor().getFullGoalName() );
}
@Test
public void testLifecyclePluginsRetrievalForDefaultLifecycle()
throws Exception
{
@ -272,6 +284,7 @@ public class LifecycleExecutorTest
assertThat( plugins.toString(), plugins, hasSize( 9 ) );
}
@Test
public void testPluginConfigurationCreation()
throws Exception
{
@ -301,33 +314,27 @@ public class LifecycleExecutorTest
mergedSegment.getTasks() );
}
@Test
public void testInvalidGoalName()
throws Exception
{
File pom = getProject( "project-basic" );
MavenSession session = createMavenSession( pom );
try
{
getExecutions( calculateExecutionPlan( session, "resources:" ) );
fail( "expected a MojoNotFoundException" );
}
catch ( MojoNotFoundException e )
{
assertEquals( "", e.getGoal() );
}
MojoNotFoundException e = assertThrows(
MojoNotFoundException.class,
() -> getExecutions( calculateExecutionPlan( session, "resources:" ) ),
"expected a MojoNotFoundException" );
assertEquals( "", e.getGoal() );
try
{
getExecutions( calculateExecutionPlan( session, "org.apache.maven.plugins:maven-resources-plugin:0.1:resources:toomany" ) );
fail( "expected a MojoNotFoundException" );
}
catch ( MojoNotFoundException e )
{
assertEquals( "resources:toomany", e.getGoal() );
}
e = assertThrows(
MojoNotFoundException.class,
() -> getExecutions( calculateExecutionPlan( session, "org.apache.maven.plugins:maven-resources-plugin:0.1:resources:toomany" ) ),
"expected a MojoNotFoundException" );
assertEquals( "resources:toomany", e.getGoal() );
}
@Test
public void testPluginPrefixRetrieval()
throws Exception
{
@ -340,6 +347,7 @@ public class LifecycleExecutorTest
// Prefixes
@Test
public void testFindingPluginPrefixforCleanClean()
throws Exception
{
@ -349,6 +357,7 @@ public class LifecycleExecutorTest
assertNotNull( plugin );
}
@Test
public void testSetupMojoExecution()
throws Exception
{
@ -362,7 +371,7 @@ public class LifecycleExecutorTest
Arrays.asList( (Object) task ), false );
MojoExecution execution = executionPlan.getMojoExecutions().get(0);
assertEquals(execution.toString(), "maven-it-plugin", execution.getArtifactId());
assertEquals( "maven-it-plugin", execution.getArtifactId(), execution.toString() );
assertNull(execution.getConfiguration());
lifeCycleExecutionPlanCalculator.setupMojoExecution( session, session.getCurrentProject(), execution,
@ -371,6 +380,7 @@ public class LifecycleExecutorTest
assertEquals("1.0", execution.getConfiguration().getChild( "version" ).getAttribute( "default-value" ));
}
@Test
public void testExecutionListeners()
throws Exception
{

View File

@ -15,21 +15,24 @@
package org.apache.maven.lifecycle;
import junit.framework.TestCase;
import java.util.Set;
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
import org.apache.maven.model.Plugin;
import org.junit.jupiter.api.Test;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author Kristian Rosenvold
*/
public class MavenExecutionPlanTest
extends TestCase
{
@Test
public void testFindLastInPhase()
throws Exception
{
@ -41,6 +44,7 @@ public class MavenExecutionPlanTest
assertNotNull( expected );
}
@Test
public void testThreadSafeMojos()
throws Exception
{
@ -52,6 +56,7 @@ public class MavenExecutionPlanTest
}
@Test
public void testFindLastWhenFirst()
throws Exception
{
@ -62,6 +67,7 @@ public class MavenExecutionPlanTest
assertNull( beerPhase );
}
@Test
public void testFindLastInPhaseMisc()
throws Exception
{

View File

@ -15,17 +15,20 @@ package org.apache.maven.lifecycle.internal;
* the License.
*/
import junit.framework.TestCase;
import java.util.List;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class BuildListCalculatorTest
extends TestCase
{
@Test
public void testCalculateProjectBuilds()
throws Exception
{
@ -35,8 +38,8 @@ public class BuildListCalculatorTest
List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) );
assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() );
assertEquals( "Stub data contains 6 items", 6, segments.size() );
assertEquals( 3, taskSegments.size(), "Stub data contains 3 segments" );
assertEquals( 6, segments.size(), "Stub data contains 6 items" );
final ProjectSegment build = segments.get( 0 );
assertNotNull( build );
}

View File

@ -15,9 +15,7 @@ package org.apache.maven.lifecycle.internal;
* the License.
*/
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.util.HashSet;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MavenExecutionPlan;
@ -25,10 +23,11 @@ import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.codehaus.plexus.logging.Logger;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* @author Kristian Rosenvold
@ -78,16 +77,19 @@ public class BuilderCommonTest
+ "you should define versions in pluginManagement section of your pom.xml or parent");
}
@Test
public void testHandleBuildError()
throws Exception
{
}
@Test
public void testAttachToThread()
throws Exception
{
}
@Test
public void testGetKey()
throws Exception
{

View File

@ -15,6 +15,8 @@ package org.apache.maven.lifecycle.internal;
* the License.
*/
import java.util.List;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.lifecycle.LifecycleNotFoundException;
@ -29,17 +31,23 @@ import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.A;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.B;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.C;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.X;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Y;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.Z;
import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.getProjectBuildList;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Kristian Rosenvold
*/
public class ConcurrencyDependencyGraphTest
extends junit.framework.TestCase
{
@Test
public void testConcurrencyGraphPrimaryVersion()
throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
@ -70,6 +78,7 @@ public class ConcurrencyDependencyGraphTest
assertEquals( Z, cDescendants.get( 1 ) );
}
@Test
public void testConcurrencyGraphDifferentCompletionOrder()
throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,

View File

@ -32,6 +32,10 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import javax.inject.Inject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentTestCase
{
@ -44,6 +48,7 @@ public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentT
return null;
}
@Test
public void testCachedReactorProjectDependencies() throws Exception
{
MavenSession session = createMavenSession( new File( "src/test/projects/lifecycle-dependency-resolver/pom.xml" ), new Properties(), true );

View File

@ -23,6 +23,9 @@ import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
import org.apache.maven.lifecycle.internal.stub.PluginPrefixResolverStub;
import org.apache.maven.lifecycle.internal.stub.PluginVersionResolverStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Kristian Rosenvold
@ -31,6 +34,7 @@ public class LifecycleExecutionPlanCalculatorTest
extends AbstractCoreMavenComponentTestCase
{
@Test
public void testCalculateExecutionPlanWithGoalTasks()
throws Exception
{

View File

@ -19,19 +19,22 @@ package org.apache.maven.lifecycle.internal;
* under the License.
*/
import junit.framework.TestCase;
import java.util.List;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Kristian Rosenvold
*/
public class LifecycleTaskSegmentCalculatorImplTest
extends TestCase
{
@Test
public void testCalculateProjectBuilds()
throws Exception
{
@ -42,8 +45,8 @@ public class LifecycleTaskSegmentCalculatorImplTest
final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) );
assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() );
assertEquals( "Stub data contains 6 items", 6, segments.size() );
assertEquals( 3, taskSegments.size(), "Stub data contains 3 segments" );
assertEquals( 6, segments.size(), "Stub data contains 6 items" );
final ProjectSegment build = segments.get( 0 );
assertNotNull( build );
}

View File

@ -15,20 +15,23 @@ package org.apache.maven.lifecycle.internal;
* the License.
*/
import junit.framework.TestCase;
import java.util.List;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.apache.maven.plugin.MojoExecution;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Kristian Rosenvold
*/
public class PhaseRecorderTest extends TestCase
public class PhaseRecorderTest
{
@Test
public void testObserveExecution() throws Exception {
PhaseRecorder phaseRecorder = new PhaseRecorder( ProjectDependencyGraphStub.A);
MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();

View File

@ -17,12 +17,12 @@ package org.apache.maven.lifecycle.internal;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Kristian Rosenvold

View File

@ -14,17 +14,20 @@ package org.apache.maven.lifecycle.internal.builder.multithreaded;
* the License.
*/
import junit.framework.TestCase;
import java.util.List;
import java.util.Set;
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.lifecycle.internal.ProjectBuildList;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.apache.maven.project.MavenProject;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ConcurrencyDependencyGraphTest extends TestCase {
public class ConcurrencyDependencyGraphTest {
@Test
public void testGraph() throws Exception {
ProjectBuildList projectBuildList = ProjectDependencyGraphStub.getProjectBuildList(

View File

@ -15,23 +15,6 @@ package org.apache.maven.lifecycle.internal.builder.multithreaded;
* the License.
*/
import junit.framework.TestCase;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.lifecycle.internal.ProjectBuildList;
import org.apache.maven.lifecycle.internal.ProjectSegment;
import org.apache.maven.lifecycle.internal.builder.multithreaded.ThreadOutputMuxer;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
@ -45,11 +28,27 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.lifecycle.internal.ProjectBuildList;
import org.apache.maven.lifecycle.internal.ProjectSegment;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Kristian Rosenvold
*/
public class ThreadOutputMuxerTest
extends TestCase
{
final String paid = "Paid";
@ -58,6 +57,7 @@ public class ThreadOutputMuxerTest
final String full = "Full";
@Test
public void testSingleThreaded()
throws Exception
{
@ -86,6 +86,7 @@ public class ThreadOutputMuxerTest
assertEquals( ( paid + in + full ).length(), byteArrayOutputStream.size() );
}
@Test
public void testMultiThreaded()
throws Exception
{
@ -124,7 +125,7 @@ public class ThreadOutputMuxerTest
threadOutputMuxer.close();
final byte[] bytes = byteArrayOutputStream.toByteArray();
String result = new String( bytes );
assertEquals( result, expectedLength, bytes.length );
assertEquals( expectedLength, bytes.length, result );
}

View File

@ -15,11 +15,13 @@
package org.apache.maven.lifecycle.internal.stub;
import junit.framework.TestCase;
import org.apache.maven.project.MavenProject;
import java.util.List;
import org.apache.maven.project.MavenProject;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests the stub. Yeah, I know.
@ -28,30 +30,34 @@ import java.util.List;
*/
public class ProjectDependencyGraphStubTest
extends TestCase
{
ProjectDependencyGraphStub stub = new ProjectDependencyGraphStub();
@Test
public void testADependencies()
{
ProjectDependencyGraphStub stub = new ProjectDependencyGraphStub();
final List<MavenProject> mavenProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.A, false );
assertEquals( 0, mavenProjects.size() );
}
public void testBDepenencies( ProjectDependencyGraphStub stub )
@Test
public void testBDepenencies()
{
final List<MavenProject> bProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.B, false );
assertEquals( 1, bProjects.size() );
assertTrue( bProjects.contains( ProjectDependencyGraphStub.A ) );
}
public void testCDepenencies( ProjectDependencyGraphStub stub )
@Test
public void testCDepenencies()
{
final List<MavenProject> cProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.C, false );
assertEquals( 1, cProjects.size() );
assertTrue( cProjects.contains( ProjectDependencyGraphStub.C ) );
assertTrue( cProjects.contains( ProjectDependencyGraphStub.A ) );
}
public void testXDepenencies( ProjectDependencyGraphStub stub )
@Test
public void testXDepenencies()
{
final List<MavenProject> cProjects = stub.getUpstreamProjects( ProjectDependencyGraphStub.X, false );
assertEquals( 2, cProjects.size() );

View File

@ -15,13 +15,13 @@ package org.apache.maven.lifecycle.mapping;
* the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author atanasenko

View File

@ -32,6 +32,13 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import javax.inject.Inject;
@ -41,12 +48,12 @@ public class PluginManagerTest
@Inject
private DefaultBuildPluginManager pluginManager;
protected String getProjectsDirectory()
{
return "src/test/projects/plugin-manager";
}
@Test
public void testPluginLoading()
throws Exception
{
@ -61,6 +68,7 @@ public class PluginManagerTest
assertNotNull( pluginDescriptor );
}
@Test
public void testMojoDescriptorRetrieval()
throws Exception
{
@ -97,6 +105,7 @@ public class PluginManagerTest
// only deal in concrete terms -- all version finding mumbo jumbo is a customization to base functionality
// the plugin manager provides.
@Test
public void testRemoteResourcesPlugin()
throws Exception
{
@ -150,6 +159,7 @@ public class PluginManagerTest
*/
}
@Test
public void testMojoConfigurationIsMergedCorrectly()
throws Exception
{
@ -160,6 +170,7 @@ public class PluginManagerTest
* is in the Antlr plugin which comes bundled with a version of Antlr but the user often times needs
* to use a specific version. We need to make sure the version that they specify takes precedence.
*/
@Test
public void testMojoWhereInternallyStatedDependencyIsOverriddenByProject()
throws Exception
{
@ -169,6 +180,7 @@ public class PluginManagerTest
* The case where you have a plugin in the current build that you want to be used on projects in
* the current build.
*/
@Test
public void testMojoThatIsPresentInTheCurrentBuild()
throws Exception
{
@ -178,6 +190,7 @@ public class PluginManagerTest
* This is the case where the Mojo wants to execute on every project and then do something at the end
* with the results of each project.
*/
@Test
public void testAggregatorMojo()
throws Exception
{
@ -187,6 +200,7 @@ public class PluginManagerTest
* This is the case where a Mojo needs the lifecycle run to a certain phase before it can do
* anything useful.
*/
@Test
public void testMojoThatRequiresExecutionToAGivenPhaseBeforeExecutingItself()
throws Exception
{
@ -198,6 +212,7 @@ public class PluginManagerTest
// test a build where projects use different versions of the same plugin
@Test
public void testThatPluginDependencyThatHasSystemScopeIsResolved()
throws Exception
{
@ -241,6 +256,7 @@ public class PluginManagerTest
assertEquals( version, pd.getVersion() );
}
@Test
public void testPluginRealmCache()
throws Exception
{
@ -285,6 +301,7 @@ public class PluginManagerTest
}
}
@Test
public void testBuildExtensionsPluginLoading()
throws Exception
{

View File

@ -24,8 +24,9 @@ import java.util.Collections;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* MNG-3131
@ -34,11 +35,11 @@ import junit.framework.TestCase;
*
*/
public class PluginParameterExceptionTest
extends TestCase
{
private final String LS = System.lineSeparator();
@Test
public void testMissingRequiredStringArrayTypeParameter()
{
MojoDescriptor mojoDescriptor = new MojoDescriptor();
@ -69,6 +70,7 @@ public class PluginParameterExceptionTest
"</configuration>." + LS, exception.buildDiagnosticMessage() );
}
@Test
public void testMissingRequiredCollectionTypeParameter()
{
MojoDescriptor mojoDescriptor = new MojoDescriptor();
@ -99,6 +101,7 @@ public class PluginParameterExceptionTest
"</configuration>." + LS, exception.buildDiagnosticMessage() );
}
@Test
public void testMissingRequiredMapTypeParameter()
{
MojoDescriptor mojoDescriptor = new MojoDescriptor();
@ -129,6 +132,7 @@ public class PluginParameterExceptionTest
"</configuration>." + LS, exception.buildDiagnosticMessage() );
}
@Test
public void testMissingRequiredPropertiesTypeParameter()
{
MojoDescriptor mojoDescriptor = new MojoDescriptor();

View File

@ -46,6 +46,14 @@ import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.inject.Inject;
@ -60,14 +68,7 @@ public class PluginParameterExpressionEvaluatorTest
@Inject
private RepositorySystem factory;
@Override
protected void tearDown()
throws Exception
{
factory = null;
super.tearDown();
}
@Test
public void testPluginDescriptorExpressionReference()
throws Exception
{
@ -79,11 +80,12 @@ public class PluginParameterExpressionEvaluatorTest
System.out.println( "Result: " + result );
assertSame( "${plugin} expression does not return plugin descriptor.",
exec.getMojoDescriptor().getPluginDescriptor(),
result );
assertSame( exec.getMojoDescriptor().getPluginDescriptor(),
result,
"${plugin} expression does not return plugin descriptor." );
}
@Test
public void testPluginArtifactsExpressionReference()
throws Exception
{
@ -106,9 +108,10 @@ public class PluginParameterExpressionEvaluatorTest
assertNotNull( depResults );
assertEquals( 1, depResults.size() );
assertSame( "dependency artifact is wrong.", depArtifact, depResults.get( 0 ) );
assertSame( depArtifact, depResults.get( 0 ), "dependency artifact is wrong." );
}
@Test
public void testPluginArtifactMapExpressionReference()
throws Exception
{
@ -131,11 +134,12 @@ public class PluginParameterExpressionEvaluatorTest
assertNotNull( depResults );
assertEquals( 1, depResults.size() );
assertSame( "dependency artifact is wrong.",
depArtifact,
depResults.get( ArtifactUtils.versionlessKey( depArtifact ) ) );
assertSame( depArtifact,
depResults.get( ArtifactUtils.versionlessKey( depArtifact ) ),
"dependency artifact is wrong." );
}
@Test
public void testPluginArtifactIdExpressionReference()
throws Exception
{
@ -147,11 +151,12 @@ public class PluginParameterExpressionEvaluatorTest
System.out.println( "Result: " + result );
assertSame( "${plugin.artifactId} expression does not return plugin descriptor's artifactId.",
exec.getMojoDescriptor().getPluginDescriptor().getArtifactId(),
result );
assertSame( exec.getMojoDescriptor().getPluginDescriptor().getArtifactId(),
result,
"${plugin.artifactId} expression does not return plugin descriptor's artifactId." );
}
@Test
public void testValueExtractionWithAPomValueContainingAPath()
throws Exception
{
@ -174,6 +179,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( expected, actual );
}
@Test
public void testEscapedVariablePassthrough()
throws Exception
{
@ -191,6 +197,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( var, value );
}
@Test
public void testEscapedVariablePassthroughInLargerExpression()
throws Exception
{
@ -209,6 +216,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( "${var} with version: 1", value );
}
@Test
public void testMultipleSubExpressionsInLargerExpression()
throws Exception
{
@ -227,6 +235,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( "test with version: 1", value );
}
@Test
public void testMissingPOMPropertyRefInLargerExpression()
throws Exception
{
@ -241,6 +250,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( expr, value );
}
@Test
public void testPOMPropertyExtractionWithMissingProject_WithDotNotation()
throws Exception
{
@ -262,6 +272,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( checkValue, value );
}
@Test
public void testBasedirExtractionWithMissingProject()
throws Exception
{
@ -272,6 +283,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( System.getProperty( "user.dir" ), value );
}
@Test
public void testValueExtractionFromSystemPropertiesWithMissingProject()
throws Exception
{
@ -291,6 +303,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( "value", value );
}
@Test
public void testValueExtractionFromSystemPropertiesWithMissingProject_WithDotNotation()
throws Exception
{
@ -323,6 +336,7 @@ public class PluginParameterExpressionEvaluatorTest
return new MavenSession( container, request, new DefaultMavenExecutionResult(), Collections.<MavenProject>emptyList() );
}
@Test
public void testLocalRepositoryExtraction()
throws Exception
{
@ -333,6 +347,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( "local", ( (ArtifactRepository) value ).getId() );
}
@Test
public void testTwoExpressions()
throws Exception
{
@ -351,6 +366,7 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( "expected-directory" + File.separatorChar + "expected-finalName", value );
}
@Test
public void testShouldExtractPluginArtifacts()
throws Exception
{

Some files were not shown because too many files have changed in this diff Show More