From dfebf13acedc4617810828bdc81be168e18d4685 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 24 Jul 2006 02:39:57 +0000 Subject: [PATCH] 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 --- .../DefaultArtifactDiscovererTest.java | 148 +++++++++--------- .../LegacyArtifactDiscovererTest.java | 75 +++++---- 2 files changed, 116 insertions(+), 107 deletions(-) diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java index 80370c501..9dba1e40f 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java @@ -462,75 +462,111 @@ public class DefaultArtifactDiscovererTest public void testShortPath() throws ComponentLookupException { - String testPath = "invalid/invalid-1.0.jar"; + try + { + getArtifactFromPath( "invalid/invalid-1.0.jar" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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"; + try + { + getArtifactFromPath( "invalid/invalid/1/invalid-1" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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"; + try + { + getArtifactFromPath( "invalid/invalid/1.0/invalid-2.0.jar" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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"; + try + { + getArtifactFromPath( "invalid/invalid/1.0/invalid-1.0b.jar" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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"; + try + { + getArtifactFromPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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"; + try + { + getArtifactFromPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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 ); } } diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java index eaa27f876..274721d14 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java @@ -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"; + try + { + getArtifactFromPath( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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"; + 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"; - - artifact = getArtifactFromPath( testPath ); - - 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"; + try + { + getArtifactFromPath( "invalid/invalid/1/invalid-1" ); - Artifact artifact = getArtifactFromPath( testPath ); - - 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 ); } }