2222import java .io .IOException ;
2323import java .net .ConnectException ;
2424
25+ import org .apache .maven .model .Plugin ;
26+ import org .apache .maven .plugin .MojoExecution ;
2527import org .apache .maven .plugin .MojoExecutionException ;
2628
27- import junit .framework .TestCase ;
29+ import org .apache .maven .plugin .PluginContainerException ;
30+ import org .apache .maven .plugin .PluginExecutionException ;
31+ import org .apache .maven .plugin .descriptor .MojoDescriptor ;
32+ import org .apache .maven .plugin .descriptor .PluginDescriptor ;
33+ import org .junit .Test ;
34+
35+ import static org .junit .Assert .assertEquals ;
2836
2937/**
3038 * @author <a href="mailto:baerrach@apache.org">Barrie Treloar</a>
3139 */
3240public class DefaultExceptionHandlerTest
33- extends TestCase
3441{
3542 /**
3643 * Running Maven under JDK7 may cause connection issues because IPv6 is used by default.
@@ -42,11 +49,11 @@ public class DefaultExceptionHandlerTest
4249 * http://cwiki.apache.org/confluence/display/MAVEN/ConnectException
4350 * </p>
4451 */
52+ @ Test
4553 public void testJdk7ipv6 ()
4654 {
4755 ConnectException connEx = new ConnectException ( "Connection refused: connect" );
48- IOException ioEx = new IOException ( "Unable to establish loopback connection" );
49- ioEx .initCause ( connEx );
56+ IOException ioEx = new IOException ( "Unable to establish loopback connection" , connEx );
5057 MojoExecutionException mojoEx =
5158 new MojoExecutionException ( "Error executing Jetty: Unable to establish loopback connection" , ioEx );
5259
@@ -57,4 +64,42 @@ public void testJdk7ipv6()
5764 assertEquals ( expectedReference , exceptionSummary .getReference () );
5865
5966 }
67+
68+ @ Test
69+ public void testHandleExceptionAetherClassNotFound ()
70+ {
71+ Throwable cause2 = new NoClassDefFoundError ( "org/sonatype/aether/RepositorySystem" );
72+ Plugin plugin = new Plugin ();
73+ Exception cause = new PluginContainerException ( plugin , null , null , cause2 );
74+ PluginDescriptor pluginDescriptor = new PluginDescriptor ();
75+ MojoDescriptor mojoDescriptor = new MojoDescriptor ();
76+ mojoDescriptor .setPluginDescriptor ( pluginDescriptor );
77+ MojoExecution mojoExecution = new MojoExecution (mojoDescriptor );
78+ Throwable exception = new PluginExecutionException ( mojoExecution , null , cause );
79+
80+ DefaultExceptionHandler handler = new DefaultExceptionHandler ();
81+ ExceptionSummary summary = handler .handleException ( exception );
82+
83+ String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound" ;
84+ assertEquals ( expectedReference , summary .getReference () );
85+ }
86+
87+ @ Test
88+ public void testHandleExceptionNoClassDefFoundErrorNull ()
89+ {
90+ Throwable cause2 = new NoClassDefFoundError ();
91+ Plugin plugin = new Plugin ();
92+ Exception cause = new PluginContainerException ( plugin , null , null , cause2 );
93+ PluginDescriptor pluginDescriptor = new PluginDescriptor ();
94+ MojoDescriptor mojoDescriptor = new MojoDescriptor ();
95+ mojoDescriptor .setPluginDescriptor ( pluginDescriptor );
96+ MojoExecution mojoExecution = new MojoExecution (mojoDescriptor );
97+ Throwable exception = new PluginExecutionException ( mojoExecution , null , cause );
98+
99+ DefaultExceptionHandler handler = new DefaultExceptionHandler ();
100+ ExceptionSummary summary = handler .handleException ( exception );
101+
102+ String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException" ;
103+ assertEquals ( expectedReference , summary .getReference () );
104+ }
60105}
0 commit comments