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