forked from apache/maven
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MNG-6626] fix DefaultExceptionHandler NPE
Closes apache#241
- Loading branch information
1 parent
b26c0f5
commit 815032f
Showing
2 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,22 @@ | |
import java.io.IOException; | ||
import java.net.ConnectException; | ||
|
||
import org.apache.maven.model.Plugin; | ||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
|
||
import junit.framework.TestCase; | ||
import org.apache.maven.plugin.PluginContainerException; | ||
import org.apache.maven.plugin.PluginExecutionException; | ||
import org.apache.maven.plugin.descriptor.MojoDescriptor; | ||
import org.apache.maven.plugin.descriptor.PluginDescriptor; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Barrie Treloar</a> | ||
*/ | ||
public class DefaultExceptionHandlerTest | ||
extends TestCase | ||
{ | ||
/** | ||
* Running Maven under JDK7 may cause connection issues because IPv6 is used by default. | ||
|
@@ -42,11 +49,11 @@ public class DefaultExceptionHandlerTest | |
* http://cwiki.apache.org/confluence/display/MAVEN/ConnectException | ||
* </p> | ||
*/ | ||
@Test | ||
public void testJdk7ipv6() | ||
{ | ||
ConnectException connEx = new ConnectException( "Connection refused: connect" ); | ||
IOException ioEx = new IOException( "Unable to establish loopback connection" ); | ||
ioEx.initCause( connEx ); | ||
IOException ioEx = new IOException( "Unable to establish loopback connection", connEx ); | ||
MojoExecutionException mojoEx = | ||
new MojoExecutionException( "Error executing Jetty: Unable to establish loopback connection", ioEx ); | ||
|
||
|
@@ -57,4 +64,42 @@ public void testJdk7ipv6() | |
assertEquals( expectedReference, exceptionSummary.getReference() ); | ||
|
||
} | ||
|
||
@Test | ||
public void testHandleExceptionAetherClassNotFound() | ||
{ | ||
Throwable cause2 = new NoClassDefFoundError( "org/sonatype/aether/RepositorySystem" ); | ||
Plugin plugin = new Plugin(); | ||
Exception cause = new PluginContainerException( plugin, null, null, cause2 ); | ||
PluginDescriptor pluginDescriptor = new PluginDescriptor(); | ||
MojoDescriptor mojoDescriptor = new MojoDescriptor(); | ||
mojoDescriptor.setPluginDescriptor( pluginDescriptor ); | ||
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor); | ||
Throwable exception = new PluginExecutionException( mojoExecution, null, cause ); | ||
|
||
DefaultExceptionHandler handler = new DefaultExceptionHandler(); | ||
ExceptionSummary summary = handler.handleException( exception ); | ||
|
||
String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound"; | ||
assertEquals( expectedReference, summary.getReference() ); | ||
} | ||
|
||
@Test | ||
public void testHandleExceptionNoClassDefFoundErrorNull() | ||
{ | ||
Throwable cause2 = new NoClassDefFoundError(); | ||
Plugin plugin = new Plugin(); | ||
Exception cause = new PluginContainerException( plugin, null, null, cause2 ); | ||
PluginDescriptor pluginDescriptor = new PluginDescriptor(); | ||
MojoDescriptor mojoDescriptor = new MojoDescriptor(); | ||
mojoDescriptor.setPluginDescriptor( pluginDescriptor ); | ||
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor); | ||
Throwable exception = new PluginExecutionException( mojoExecution, null, cause ); | ||
|
||
DefaultExceptionHandler handler = new DefaultExceptionHandler(); | ||
ExceptionSummary summary = handler.handleException( exception ); | ||
|
||
String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException"; | ||
assertEquals( expectedReference, summary.getReference() ); | ||
} | ||
} |