From af82cbbfa9362a9fd0dd11ff2055c29ef13e77b4 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 7 Nov 2016 22:55:25 +0100 Subject: [PATCH] Relaxed test assertion --- .../OnBeanConditionTypeDeductionFailureTests.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java index 272834d4a5..c477d9115b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java @@ -49,20 +49,22 @@ public class OnBeanConditionTypeDeductionFailureTests { fail("Context refresh was successful"); } catch (Exception ex) { - Throwable beanTypeDeductionException = findBeanTypeDeductionException(ex); + Throwable beanTypeDeductionException = findNestedCause(ex, + BeanTypeDeductionException.class); assertThat(beanTypeDeductionException) .hasMessage("Failed to deduce bean type for " + OnMissingBeanConfiguration.class.getName() + ".objectMapper"); - assertThat(beanTypeDeductionException) - .hasCauseInstanceOf(NoClassDefFoundError.class); + assertThat(findNestedCause(beanTypeDeductionException, + NoClassDefFoundError.class)).isNotNull(); + } } - private Throwable findBeanTypeDeductionException(Throwable ex) { + private Throwable findNestedCause(Throwable ex, Class target) { Throwable candidate = ex; while (candidate != null) { - if (candidate instanceof BeanTypeDeductionException) { + if (target.isInstance(candidate)) { return candidate; } candidate = candidate.getCause();