Relaxed test assertion

This commit is contained in:
Stephane Nicoll 2016-11-07 22:55:25 +01:00
parent 0a4a84d357
commit af82cbbfa9
1 changed files with 7 additions and 5 deletions

View File

@ -49,20 +49,22 @@ public class OnBeanConditionTypeDeductionFailureTests {
fail("Context refresh was successful"); fail("Context refresh was successful");
} }
catch (Exception ex) { catch (Exception ex) {
Throwable beanTypeDeductionException = findBeanTypeDeductionException(ex); Throwable beanTypeDeductionException = findNestedCause(ex,
BeanTypeDeductionException.class);
assertThat(beanTypeDeductionException) assertThat(beanTypeDeductionException)
.hasMessage("Failed to deduce bean type for " .hasMessage("Failed to deduce bean type for "
+ OnMissingBeanConfiguration.class.getName() + OnMissingBeanConfiguration.class.getName()
+ ".objectMapper"); + ".objectMapper");
assertThat(beanTypeDeductionException) assertThat(findNestedCause(beanTypeDeductionException,
.hasCauseInstanceOf(NoClassDefFoundError.class); NoClassDefFoundError.class)).isNotNull();
} }
} }
private Throwable findBeanTypeDeductionException(Throwable ex) { private Throwable findNestedCause(Throwable ex, Class<? extends Throwable> target) {
Throwable candidate = ex; Throwable candidate = ex;
while (candidate != null) { while (candidate != null) {
if (candidate instanceof BeanTypeDeductionException) { if (target.isInstance(candidate)) {
return candidate; return candidate;
} }
candidate = candidate.getCause(); candidate = candidate.getCause();