1 package org.apache.maven.usability; 2 3 import org.apache.maven.artifact.Artifact; 4 import org.apache.maven.artifact.factory.ArtifactFactory; 5 import org.codehaus.plexus.PlexusTestCase; 6 7 22 23 public class InvalidArtifactDiagnoserTest 24 extends PlexusTestCase 25 { 26 private InvalidArtifactDiagnoser diagnoser = new InvalidArtifactDiagnoser(); 27 28 public void testShouldDiagnoseArtifactWithMissingGroupId() throws Throwable 29 { 30 testDiagnosis( "Test diagnosis for missing groupId", null, "test-artifact", "1.0", "jar" ); 31 } 32 33 public void testShouldDiagnoseArtifactWithMissingArtifactId() throws Throwable 34 { 35 testDiagnosis( "Test diagnosis for missing artifactId", "test.group.id", null, "1.0", "jar" ); 36 } 37 38 public void testShouldDiagnoseArtifactWithMissingVersion() throws Throwable 39 { 40 testDiagnosis( "Test diagnosis for missing version", "test.group.id", "test-artifact", null, "jar" ); 41 } 42 43 public void testShouldDiagnoseArtifactWithMissingType() throws Throwable 44 { 45 testDiagnosis( "Test diagnosis for missing type", "test.group.id", "test-artifact", "1.0", null ); 46 } 47 48 public void testShouldDiagnoseArtifactWithMissingGroupIdAndArtifactId() throws Throwable 49 { 50 testDiagnosis( "Test diagnosis for missing groupId and artifactId", null, null, "1.0", "jar" ); 51 } 52 53 private void testDiagnosis( String testHeader, String groupId, String artifactId, String version, String type ) 54 throws Throwable 55 { 56 System.out.println( "------------------------------------------------------------" ); 57 System.out.println( "| " + testHeader ); 58 System.out.println( "------------------------------------------------------------" ); 59 System.out.println(); 60 61 try 62 { 63 createArtifact( groupId, artifactId, version, type ); 64 65 fail( "artifact creation did not fail; nothing to diagnose." ); 66 } 67 catch ( Throwable error ) 68 { 69 assertTrue( "Unexpected error while constructing artifact: " + error, diagnoser.canDiagnose( error ) ); 70 71 if ( diagnoser.canDiagnose( error ) ) 72 { 73 System.out.println( diagnoser.diagnose( error ) ); 74 } 75 else 76 { 77 throw error; 78 } 79 } 80 } 81 82 private Artifact createArtifact( String groupId, String artifactId, String version, String type ) 83 throws Exception 84 { 85 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); 86 return artifactFactory.createBuildArtifact( groupId, artifactId, version, type ); 87 } 88 89 } 90 | Popular Tags |