Skip to content

Commit

Permalink
Include source of NoSuchMethodError in its failure analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Feb 19, 2019
1 parent 971b608 commit 52aa7e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -93,11 +93,19 @@ private String getDescription(NoSuchMethodError cause, String className,
List<URL> candidates, URL actual) {
StringWriter description = new StringWriter();
PrintWriter writer = new PrintWriter(description);
writer.print("An attempt was made to call the method ");
writer.print(cause.getMessage());
writer.print(" but it does not exist. Its class, ");
writer.print(className);
writer.println(", is available from the following locations:");
writer.println("An attempt was made to call a method that does not"
+ " exist. The attempt was made from the following location:");
writer.println();
writer.print(" ");
writer.println(cause.getStackTrace()[0]);
writer.println();
writer.println("The following method did not exist:");
writer.println();
writer.print(" ");
writer.println(cause.getMessage());
writer.println();
writer.println("The method's class, " + className
+ ", is available from the following locations:");
writer.println();
for (URL candidate : candidates) {
writer.print(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public void noSuchMethodErrorIsAnalyzed() {
assertThat(failure).isNotNull();
FailureAnalysis analysis = new NoSuchMethodFailureAnalyzer().analyze(failure);
assertThat(analysis).isNotNull();
System.out.println(analysis.getDescription());
assertThat(analysis.getDescription())
.contains("the method javax.servlet.ServletContext.addServlet"
.contains(NoSuchMethodFailureAnalyzerTests.class.getName()
+ ".createFailure(")
.contains("javax.servlet.ServletContext.addServlet"
+ "(Ljava/lang/String;Ljavax/servlet/Servlet;)"
+ "Ljavax/servlet/ServletRegistration$Dynamic;")
.contains("class, javax.servlet.ServletContext,");
Expand Down

0 comments on commit 52aa7e1

Please sign in to comment.