Home / Class/ AnyNestedConditionTests Class — spring-boot Architecture

AnyNestedConditionTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AnyNestedConditionTests.java lines 39–118

class AnyNestedConditionTests {

	private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();

	@Test
	void neither() {
		this.contextRunner.withUserConfiguration(Config.class).run(match(false));
	}

	@Test
	void propertyA() {
		this.contextRunner.withUserConfiguration(Config.class).withPropertyValues("a:a").run(match(true));
	}

	@Test
	void propertyB() {
		this.contextRunner.withUserConfiguration(Config.class).withPropertyValues("b:b").run(match(true));
	}

	@Test
	void both() {
		this.contextRunner.withUserConfiguration(Config.class).withPropertyValues("a:a", "b:b").run(match(true));
	}

	private ContextConsumer<AssertableApplicationContext> match(boolean expected) {
		return (context) -> {
			if (expected) {
				assertThat(context).hasBean("myBean");
			}
			else {
				assertThat(context).doesNotHaveBean("myBean");
			}
		};
	}

	@Configuration(proxyBeanMethods = false)
	@Conditional(OnPropertyAorBCondition.class)
	static class Config {

		@Bean
		String myBean() {
			return "myBean";
		}

	}

	static class OnPropertyAorBCondition extends AnyNestedCondition {

		OnPropertyAorBCondition() {
			super(ConfigurationPhase.PARSE_CONFIGURATION);
		}

		@ConditionalOnProperty("a")
		static class HasPropertyA {

		}

		@ConditionalOnExpression("true")
		@ConditionalOnProperty("b")
		static class HasPropertyB {

		}

		@Conditional(NonSpringBootCondition.class)
		static class SubclassC {

		}

	}

	static class NonSpringBootCondition implements Condition {

		@Override
		public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
			return false;
		}

	}

}

Analyze Your Own Codebase

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

Try Supermodel Free