Skip to content

Commit

Permalink
[MNG-7035] Migrate unit tests to Unit 5
Browse files Browse the repository at this point in the history
Signed-off-by: rfscholte <rfscholte@apache.org>
  • Loading branch information
gnodet authored and rfscholte committed Jan 15, 2021
1 parent 83dc690 commit bb916d0
Show file tree
Hide file tree
Showing 221 changed files with 3,687 additions and 2,517 deletions.
Expand Up @@ -19,31 +19,33 @@
* 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) )
{
Expand Down
Expand Up @@ -24,23 +24,25 @@
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}.
*
* @author Benjamin Bentmann
*/
public class ArtifactUtilsTest
extends TestCase
{

private Artifact newArtifact( String aid )
{
return new DefaultArtifact( "group", aid, VersionRange.createFromVersion( "1.0" ), "test", "jar", "tests", null );
}

@Test
public void testIsSnapshot()
{
assertEquals( false, ArtifactUtils.isSnapshot( null ) );
Expand All @@ -52,6 +54,7 @@ public void testIsSnapshot()
assertEquals( false, ArtifactUtils.isSnapshot( "1.2.3-20090413X094722-2"));
}

@Test
public void testToSnapshotVersion()
{
assertEquals( "1.2.3", ArtifactUtils.toSnapshotVersion( "1.2.3" ) );
Expand All @@ -63,6 +66,7 @@ public void testToSnapshotVersion()
/**
* Tests that the ordering of the map resembles the ordering of the input collection of artifacts.
*/
@Test
public void testArtifactMapByVersionlessIdOrdering()
throws Exception
{
Expand Down
Expand Up @@ -19,13 +19,15 @@
* 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;
Expand All @@ -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 );
Expand All @@ -55,6 +57,7 @@ protected void setUp()
snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotVersionRange, scope, type, classifier, artifactHandler );
}

@Test
public void testGetVersionReturnsResolvedVersionOnSnapshot()
{
assertEquals( snapshotResolvedVersion, snapshotArtifact.getVersion() );
Expand All @@ -65,53 +68,62 @@ public void testGetVersionReturnsResolvedVersionOnSnapshot()
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,
Expand All @@ -128,6 +140,7 @@ public void testComparisonByVersion()
assertTrue( artifact1.compareTo( artifact ) == 0 );
}

@Test
public void testNonResolvedVersionRangeConsistentlyYieldsNullVersions()
throws Exception
{
Expand Down
Expand Up @@ -19,10 +19,8 @@
* 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;
Expand All @@ -31,7 +29,9 @@
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
{
Expand Down Expand Up @@ -60,11 +60,11 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )

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;
}
Expand Down
Expand Up @@ -21,7 +21,10 @@

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.
Expand All @@ -30,7 +33,6 @@
*/
@SuppressWarnings( "unchecked" )
public class ComparableVersionTest
extends TestCase
{
private Comparable newComparable( String version )
{
Expand All @@ -39,8 +41,8 @@ private Comparable newComparable( String version )
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;
}
Expand Down Expand Up @@ -68,8 +70,8 @@ private void checkVersionsOrder( String[] versions )
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 );
}
}
}
Expand All @@ -78,11 +80,11 @@ private void checkVersionsEqual( String v1, String v2 )
{
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 )
Expand All @@ -97,20 +99,23 @@ private void checkVersionsOrder( String v1, String v2 )
{
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" );
Expand Down Expand Up @@ -164,6 +169,7 @@ public void testVersionsEqual()
checkVersionsEqual( "1m3", "1MILESTONE3" );
}

@Test
public void testVersionComparing()
{
checkVersionsOrder( "1", "2" );
Expand Down Expand Up @@ -202,6 +208,7 @@ public void testVersionComparing()
* 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";
Expand All @@ -216,6 +223,7 @@ public void testMng5568()
/**
* 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
Expand All @@ -235,6 +243,7 @@ public void testMng6572()
* 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
Expand Down Expand Up @@ -267,6 +276,7 @@ public void testVersionEqualWithLeadingZeroes()
* 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
Expand Down Expand Up @@ -299,6 +309,7 @@ public void testVersionZeroEqualWithLeadingZeroes()
* 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";
Expand All @@ -310,6 +321,7 @@ public void testMng6964()
checkVersionsOrder( a, b ); // Should still be true
}

@Test
public void testLocaleIndependent()
{
Locale orig = Locale.getDefault();
Expand All @@ -328,13 +340,14 @@ public void testLocaleIndependent()
}
}

@Test
public void testReuse()
{
ComparableVersion c1 = new ComparableVersion( "1" );
c1.parseVersion( "2" );

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" );
}
}

0 comments on commit bb916d0

Please sign in to comment.