1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.exception;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22
23 import java.io.IOException;
24 import java.net.ConnectException;
25 import org.apache.maven.model.Plugin;
26 import org.apache.maven.plugin.MojoExecution;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.PluginContainerException;
29 import org.apache.maven.plugin.PluginExecutionException;
30 import org.apache.maven.plugin.descriptor.MojoDescriptor;
31 import org.apache.maven.plugin.descriptor.PluginDescriptor;
32 import org.junit.jupiter.api.Test;
33
34
35
36
37 public class DefaultExceptionHandlerTest {
38
39
40
41
42
43
44
45
46
47
48 @Test
49 public void testJdk7ipv6() {
50 ConnectException connEx = new ConnectException("Connection refused: connect");
51 IOException ioEx = new IOException("Unable to establish loopback connection", connEx);
52 MojoExecutionException mojoEx =
53 new MojoExecutionException("Error executing Jetty: Unable to establish loopback connection", ioEx);
54
55 ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
56 ExceptionSummary exceptionSummary = exceptionHandler.handleException(mojoEx);
57
58 String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/ConnectException";
59 assertEquals(expectedReference, exceptionSummary.getReference());
60 }
61
62 @Test
63 public void testHandleExceptionAetherClassNotFound() {
64 Throwable cause2 = new NoClassDefFoundError("org/sonatype/aether/RepositorySystem");
65 Plugin plugin = new Plugin();
66 Exception cause = new PluginContainerException(plugin, null, null, cause2);
67 PluginDescriptor pluginDescriptor = new PluginDescriptor();
68 MojoDescriptor mojoDescriptor = new MojoDescriptor();
69 mojoDescriptor.setPluginDescriptor(pluginDescriptor);
70 MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
71 Throwable exception = new PluginExecutionException(mojoExecution, null, cause);
72
73 DefaultExceptionHandler handler = new DefaultExceptionHandler();
74 ExceptionSummary summary = handler.handleException(exception);
75
76 String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound";
77 assertEquals(expectedReference, summary.getReference());
78 }
79
80 @Test
81 public void testHandleExceptionNoClassDefFoundErrorNull() {
82 Throwable cause2 = new NoClassDefFoundError();
83 Plugin plugin = new Plugin();
84 Exception cause = new PluginContainerException(plugin, null, null, cause2);
85 PluginDescriptor pluginDescriptor = new PluginDescriptor();
86 MojoDescriptor mojoDescriptor = new MojoDescriptor();
87 mojoDescriptor.setPluginDescriptor(pluginDescriptor);
88 MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
89 Throwable exception = new PluginExecutionException(mojoExecution, null, cause);
90
91 DefaultExceptionHandler handler = new DefaultExceptionHandler();
92 ExceptionSummary summary = handler.handleException(exception);
93
94 String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException";
95 assertEquals(expectedReference, summary.getReference());
96 }
97 }