Home / Class/ OnBeanConditionTypeDeductionFailureTests Class — spring-boot Architecture

OnBeanConditionTypeDeductionFailureTests Class — spring-boot Architecture

Architecture documentation for the OnBeanConditionTypeDeductionFailureTests class in OnBeanConditionTypeDeductionFailureTests.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnBeanConditionTypeDeductionFailureTests.java lines 40–94

@ClassPathExclusions("jackson-core-*.jar")
class OnBeanConditionTypeDeductionFailureTests {

	@Test
	void conditionalOnMissingBeanWithDeducedTypeThatIsPartiallyMissingFromClassPath() {
		assertThatException()
			.isThrownBy(() -> new AnnotationConfigApplicationContext(ImportingConfiguration.class).close())
			.satisfies((ex) -> {
				Throwable beanTypeDeductionException = findNestedCause(ex, BeanTypeDeductionException.class);
				assertThat(beanTypeDeductionException).isNotNull();
				assertThat(beanTypeDeductionException).hasMessage("Failed to deduce bean type for "
						+ OnMissingBeanConfiguration.class.getName() + ".objectMapper");
				assertThat(findNestedCause(beanTypeDeductionException, NoClassDefFoundError.class)).isNotNull();

			});
	}

	private @Nullable Throwable findNestedCause(Throwable ex, Class<? extends Throwable> target) {
		Throwable candidate = ex;
		while (candidate != null) {
			if (target.isInstance(candidate)) {
				return candidate;
			}
			candidate = candidate.getCause();
		}
		return null;
	}

	@Configuration(proxyBeanMethods = false)
	@Import(OnMissingBeanImportSelector.class)
	static class ImportingConfiguration {

	}

	@Configuration(proxyBeanMethods = false)
	static class OnMissingBeanConfiguration {

		@Bean
		@ConditionalOnMissingBean
		ObjectMapper objectMapper() {
			return new ObjectMapper();
		}

	}

	static class OnMissingBeanImportSelector implements ImportSelector {

		@Override
		public String[] selectImports(AnnotationMetadata importingClassMetadata) {
			return new String[] { OnMissingBeanConfiguration.class.getName() };
		}

	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free