22
22
import java .io .IOException ;
23
23
import java .net .ConnectException ;
24
24
25
+ import org .apache .maven .model .Plugin ;
26
+ import org .apache .maven .plugin .MojoExecution ;
25
27
import org .apache .maven .plugin .MojoExecutionException ;
26
28
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 ;
28
36
29
37
/**
30
38
* @author <a href="mailto:baerrach@apache.org">Barrie Treloar</a>
31
39
*/
32
40
public class DefaultExceptionHandlerTest
33
- extends TestCase
34
41
{
35
42
/**
36
43
* Running Maven under JDK7 may cause connection issues because IPv6 is used by default.
@@ -42,11 +49,11 @@ public class DefaultExceptionHandlerTest
42
49
* http://cwiki.apache.org/confluence/display/MAVEN/ConnectException
43
50
* </p>
44
51
*/
52
+ @ Test
45
53
public void testJdk7ipv6 ()
46
54
{
47
55
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 );
50
57
MojoExecutionException mojoEx =
51
58
new MojoExecutionException ( "Error executing Jetty: Unable to establish loopback connection" , ioEx );
52
59
@@ -57,4 +64,42 @@ public void testJdk7ipv6()
57
64
assertEquals ( expectedReference , exceptionSummary .getReference () );
58
65
59
66
}
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
+ }
60
105
}
0 commit comments