Skip to content

Commit

Permalink
Merge branch '2.4.x' into 2.5.x
Browse files Browse the repository at this point in the history
Closes gh-26935
  • Loading branch information
scottfrederick committed Jun 16, 2021
2 parents 577c58b + 5147fca commit 79f47b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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 @@ -29,6 +29,7 @@
* {@link BeanNotOfRequiredTypeException}.
*
* @author Andy Wilkinson
* @author Scott Frederick
* @since 1.4.0
*/
public class BeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnalyzer<BeanNotOfRequiredTypeException> {
Expand All @@ -48,8 +49,12 @@ protected FailureAnalysis analyze(Throwable rootFailure, BeanNotOfRequiredTypeEx
private String getDescription(BeanNotOfRequiredTypeException ex) {
StringWriter description = new StringWriter();
PrintWriter printer = new PrintWriter(description);
printer.printf("The bean '%s' could not be injected as a '%s' because it is a "
+ "JDK dynamic proxy that implements:%n", ex.getBeanName(), ex.getRequiredType().getName());
printer.printf("The bean '%s' could not be injected because it is a JDK dynamic proxy%n%n", ex.getBeanName());
printer.printf("The bean is of type '%s' and implements:%n", ex.getActualType().getName());
for (Class<?> actualTypeInterface : ex.getActualType().getInterfaces()) {
printer.println("\t" + actualTypeInterface.getName());
}
printer.printf("%nExpected a bean of type '%s' which implements:%n", ex.getRequiredType().getName());
for (Class<?> requiredTypeInterface : ex.getRequiredType().getInterfaces()) {
printer.println("\t" + requiredTypeInterface.getName());
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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 @@ -35,6 +35,7 @@
* Tests for {@link BeanNotOfRequiredTypeFailureAnalyzer}.
*
* @author Andy Wilkinson
* @author Scott Frederick
*/
class BeanNotOfRequiredTypeFailureAnalyzerTests {

Expand All @@ -44,8 +45,11 @@ class BeanNotOfRequiredTypeFailureAnalyzerTests {
void jdkProxyCausesInjectionFailure() {
FailureAnalysis analysis = performAnalysis(JdkProxyConfiguration.class);
assertThat(analysis.getDescription()).startsWith("The bean 'asyncBean'");
assertThat(analysis.getDescription()).contains("'" + AsyncBean.class.getName() + "'");
assertThat(analysis.getDescription()).endsWith(String.format("%s%n", SomeInterface.class.getName()));
assertThat(analysis.getDescription())
.containsPattern("The bean is of type '" + AsyncBean.class.getPackage().getName() + ".\\$Proxy.*'");
assertThat(analysis.getDescription()).contains("and implements:\n\t" + SomeInterface.class.getName());
assertThat(analysis.getDescription()).contains("Expected a bean of type '" + AsyncBean.class.getName() + "'");
assertThat(analysis.getDescription()).contains("which implements:\n\t" + SomeInterface.class.getName());
}

private FailureAnalysis performAnalysis(Class<?> configuration) {
Expand Down

0 comments on commit 79f47b1

Please sign in to comment.