]> source.dussan.org Git - archiva.git/commitdiff
refactor tests to more appropriate testing of exceptional method
authorBrett Porter <brett@apache.org>
Mon, 24 Jul 2006 02:39:57 +0000 (02:39 +0000)
committerBrett Porter <brett@apache.org>
Mon, 24 Jul 2006 02:39:57 +0000 (02:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@424884 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java

index 80370c5014c1f514db70e8f16ba5725abcb629d4..9dba1e40fa87247bbf93257b2a1b9c9a03556aa6 100644 (file)
@@ -462,75 +462,111 @@ public class DefaultArtifactDiscovererTest
     public void testShortPath()
         throws ComponentLookupException
     {
-        String testPath = "invalid/invalid-1.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "invalid/invalid-1.0.jar" );
 
-        assertNull( "Artifact should be null for short paths", artifact );
+            fail( "Artifact should be null for short paths" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testWrongArtifactId()
         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()
         throws ComponentLookupException
     {
-        String testPath = "invalid/invalid/1/invalid-1";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "invalid/invalid/1/invalid-1" );
 
-        assertNull( "Artifact should be null for no type", artifact );
+            fail( "Artifact should be null for no type" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testWrongVersion()
         throws ComponentLookupException
     {
-        String testPath = "invalid/invalid/1.0/invalid-2.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "invalid/invalid/1.0/invalid-2.0.jar" );
 
-        assertNull( "Artifact should be null for wrong version", artifact );
+            fail( "Artifact should be null for wrong version" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testLongVersion()
         throws ComponentLookupException
     {
-        String testPath = "invalid/invalid/1.0/invalid-1.0b.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "invalid/invalid/1.0/invalid-1.0b.jar" );
 
-        assertNull( "Artifact should be null for long version", artifact );
+            fail( "Artifact should be null for long version" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testWrongSnapshotVersion()
         throws ComponentLookupException
     {
-        String testPath = "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" );
 
-        assertNull( "Artifact should be null for wrong snapshot version", artifact );
+            fail( "Artifact should be null for wrong snapshot version" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testSnapshotBaseVersion()
         throws ComponentLookupException
     {
-        String testPath = "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
 
-        assertNull( "Artifact should be null for snapshot base version", artifact );
+            fail( "Artifact should be null for snapshot base version" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testPathWithClassifier()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
         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()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
         String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar";
 
@@ -554,7 +590,7 @@ public class DefaultArtifactDiscovererTest
     }
 
     public void testDistributionArtifacts()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
         String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz";
 
@@ -574,7 +610,7 @@ public class DefaultArtifactDiscovererTest
     }
 
     public void testSnapshot()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
         String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar";
 
@@ -594,43 +630,7 @@ public class DefaultArtifactDiscovererTest
     }
 
     public void testNormal()
-        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 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
+        throws ComponentLookupException, DiscovererException
     {
         String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
 
@@ -642,7 +642,7 @@ public class DefaultArtifactDiscovererTest
     }
 
     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";
 
@@ -655,14 +655,8 @@ public class DefaultArtifactDiscovererTest
     }
 
     private Artifact getArtifactFromPath( String path )
+        throws DiscovererException
     {
-        try
-        {
-            return discoverer.buildArtifact( path );
-        }
-        catch ( DiscovererException e )
-        {
-            return null;
-        }
+        return discoverer.buildArtifact( path );
     }
 }
index eaa27f876d68c38eb818d8106677b29ed54461b1..274721d14c43ff86d3d4857e613f8828d203b347 100644 (file)
@@ -375,42 +375,63 @@ public class LegacyArtifactDiscovererTest
     }
 
     public void testWrongArtifactPackaging()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
-        String testPath = "org.apache.maven.test/jars/artifactId-1.0.jar.md5";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" );
 
-        assertNull( "Artifact should be null for wrong package extension", artifact );
+            fail( "Artifact should be null for wrong package extension" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
-    public void testNoArtifactid()
+    public void testNoArtifactId()
+        throws DiscovererException
     {
-        String testPath = "groupId/jars/-1.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        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" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
 
-        artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "groupId/jars/1.0.jar" );
 
-        assertNull( "Artifact should be null when artifactId is missing", artifact );
+            fail( "Artifact should be null when artifactId is missing" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testNoType()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
-        String testPath = "invalid/invalid/1/invalid-1";
-
-        Artifact artifact = getArtifactFromPath( testPath );
+        try
+        {
+            getArtifactFromPath( "invalid/invalid/1/invalid-1" );
 
-        assertNull( "Artifact should be null for no type", artifact );
+            fail( "Artifact should be null for no type" );
+        }
+        catch ( DiscovererException e )
+        {
+            // excellent
+        }
     }
 
     public void testSnapshot()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
         String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar";
 
@@ -422,7 +443,7 @@ public class LegacyArtifactDiscovererTest
     }
 
     public void testFinal()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
         String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar";
 
@@ -434,7 +455,7 @@ public class LegacyArtifactDiscovererTest
     }
 
     public void testNormal()
-        throws ComponentLookupException
+        throws ComponentLookupException, DiscovererException
     {
         String testPath = "javax.sql/jars/jdbc-2.0.jar";
 
@@ -446,14 +467,8 @@ public class LegacyArtifactDiscovererTest
     }
 
     private Artifact getArtifactFromPath( String path )
+        throws DiscovererException
     {
-        try
-        {
-            return discoverer.buildArtifact( path );
-        }
-        catch ( DiscovererException e )
-        {
-            return null;
-        }
+        return discoverer.buildArtifact( path );
     }
 }