refactor tests to more appropriate testing of exceptional method

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@424884 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-07-24 02:39:57 +00:00
parent e840139821
commit dfebf13ace
2 changed files with 116 additions and 107 deletions

View File

@ -462,75 +462,111 @@ public class DefaultArtifactDiscovererTest
public void testShortPath() public void testShortPath()
throws ComponentLookupException throws ComponentLookupException
{ {
String testPath = "invalid/invalid-1.0.jar"; try
{
getArtifactFromPath( "invalid/invalid-1.0.jar" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for short paths" );
}
assertNull( "Artifact should be null for short paths", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testWrongArtifactId() public void testWrongArtifactId()
throws ComponentLookupException throws ComponentLookupException
{ {
String testPath = "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar";
Artifact artifact = getArtifactFromPath( testPath ); try
{
getArtifactFromPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" );
assertNull( "Artifact should be null for wrong ArtifactId", artifact ); fail( "Artifact should be null for wrong ArtifactId" );
}
catch ( DiscovererException e )
{
// excellent
}
} }
public void testNoType() public void testNoType()
throws ComponentLookupException throws ComponentLookupException
{ {
String testPath = "invalid/invalid/1/invalid-1"; try
{
getArtifactFromPath( "invalid/invalid/1/invalid-1" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for no type" );
}
assertNull( "Artifact should be null for no type", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testWrongVersion() public void testWrongVersion()
throws ComponentLookupException throws ComponentLookupException
{ {
String testPath = "invalid/invalid/1.0/invalid-2.0.jar"; try
{
getArtifactFromPath( "invalid/invalid/1.0/invalid-2.0.jar" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for wrong version" );
}
assertNull( "Artifact should be null for wrong version", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testLongVersion() public void testLongVersion()
throws ComponentLookupException throws ComponentLookupException
{ {
String testPath = "invalid/invalid/1.0/invalid-1.0b.jar"; try
{
getArtifactFromPath( "invalid/invalid/1.0/invalid-1.0b.jar" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for long version" );
}
assertNull( "Artifact should be null for long version", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testWrongSnapshotVersion() public void testWrongSnapshotVersion()
throws ComponentLookupException throws ComponentLookupException
{ {
String testPath = "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar"; try
{
getArtifactFromPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for wrong snapshot version" );
}
assertNull( "Artifact should be null for wrong snapshot version", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testSnapshotBaseVersion() public void testSnapshotBaseVersion()
throws ComponentLookupException throws ComponentLookupException
{ {
String testPath = "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar"; try
{
getArtifactFromPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for snapshot base version" );
}
assertNull( "Artifact should be null for snapshot base version", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testPathWithClassifier() public void testPathWithClassifier()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar"; String testPath = "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar";
@ -542,7 +578,7 @@ public class DefaultArtifactDiscovererTest
} }
public void testWithJavaSourceInclusion() public void testWithJavaSourceInclusion()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar"; String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar";
@ -554,7 +590,7 @@ public class DefaultArtifactDiscovererTest
} }
public void testDistributionArtifacts() public void testDistributionArtifacts()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz"; String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz";
@ -574,7 +610,7 @@ public class DefaultArtifactDiscovererTest
} }
public void testSnapshot() public void testSnapshot()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar"; String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar";
@ -594,43 +630,7 @@ public class DefaultArtifactDiscovererTest
} }
public void testNormal() public void testNormal()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{
String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
Artifact artifact = getArtifactFromPath( testPath );
assertNotNull( "Normal artifact path error", artifact );
assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
}
public void testUpdatedInRepository()
throws ComponentLookupException
{
String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
Artifact artifact = getArtifactFromPath( testPath );
assertNotNull( "Normal artifact path error", artifact );
assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
}
public void testNotUpdatedInRepository()
throws ComponentLookupException
{
String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
Artifact artifact = getArtifactFromPath( testPath );
assertNotNull( "Normal artifact path error", artifact );
assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
}
public void testNotUpdatedInRepositoryForcedDiscovery()
throws ComponentLookupException
{ {
String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar"; String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
@ -642,7 +642,7 @@ public class DefaultArtifactDiscovererTest
} }
public void testSnapshotWithClassifier() public void testSnapshotWithClassifier()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar"; String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar";
@ -655,14 +655,8 @@ public class DefaultArtifactDiscovererTest
} }
private Artifact getArtifactFromPath( String path ) private Artifact getArtifactFromPath( String path )
throws DiscovererException
{ {
try return discoverer.buildArtifact( path );
{
return discoverer.buildArtifact( path );
}
catch ( DiscovererException e )
{
return null;
}
} }
} }

View File

@ -375,42 +375,63 @@ public class LegacyArtifactDiscovererTest
} }
public void testWrongArtifactPackaging() public void testWrongArtifactPackaging()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org.apache.maven.test/jars/artifactId-1.0.jar.md5"; try
{
getArtifactFromPath( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for wrong package extension" );
}
assertNull( "Artifact should be null for wrong package extension", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testNoArtifactid() public void testNoArtifactId()
throws DiscovererException
{ {
String testPath = "groupId/jars/-1.0.jar"; try
{
getArtifactFromPath( "groupId/jars/-1.0.jar" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null when artifactId is missing" );
}
catch ( DiscovererException e )
{
// excellent
}
assertNull( "Artifact should be null when artifactId is missing", artifact ); try
{
getArtifactFromPath( "groupId/jars/1.0.jar" );
testPath = "groupId/jars/1.0.jar"; fail( "Artifact should be null when artifactId is missing" );
}
artifact = getArtifactFromPath( testPath ); catch ( DiscovererException e )
{
assertNull( "Artifact should be null when artifactId is missing", artifact ); // excellent
}
} }
public void testNoType() public void testNoType()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "invalid/invalid/1/invalid-1"; try
{
getArtifactFromPath( "invalid/invalid/1/invalid-1" );
Artifact artifact = getArtifactFromPath( testPath ); fail( "Artifact should be null for no type" );
}
assertNull( "Artifact should be null for no type", artifact ); catch ( DiscovererException e )
{
// excellent
}
} }
public void testSnapshot() public void testSnapshot()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar"; String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar";
@ -422,7 +443,7 @@ public class LegacyArtifactDiscovererTest
} }
public void testFinal() public void testFinal()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar"; String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar";
@ -434,7 +455,7 @@ public class LegacyArtifactDiscovererTest
} }
public void testNormal() public void testNormal()
throws ComponentLookupException throws ComponentLookupException, DiscovererException
{ {
String testPath = "javax.sql/jars/jdbc-2.0.jar"; String testPath = "javax.sql/jars/jdbc-2.0.jar";
@ -446,14 +467,8 @@ public class LegacyArtifactDiscovererTest
} }
private Artifact getArtifactFromPath( String path ) private Artifact getArtifactFromPath( String path )
throws DiscovererException
{ {
try return discoverer.buildArtifact( path );
{
return discoverer.buildArtifact( path );
}
catch ( DiscovererException e )
{
return null;
}
} }
} }