Home / Class/ OverrideSourcesTests Class — spring-boot Architecture

OverrideSourcesTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/OverrideSourcesTests.java lines 37–107

class OverrideSourcesTests {

	private @Nullable ConfigurableApplicationContext context;

	@AfterEach
	void cleanUp() {
		if (this.context != null) {
			this.context.close();
		}
	}

	@Test
	void beanInjectedToMainConfiguration() {
		this.context = SpringApplication.run(new Class<?>[] { MainConfiguration.class },
				new String[] { "--spring.main.web-application-type=none" });
		assertThat(this.context.getBean(Service.class).bean.name).isEqualTo("foo");
	}

	@Test
	void primaryBeanInjectedProvingSourcesNotOverridden() {
		this.context = SpringApplication.run(new Class<?>[] { MainConfiguration.class, TestConfiguration.class },
				new String[] { "--spring.main.web-application-type=none",
						"--spring.main.allow-bean-definition-overriding=true",
						"--spring.main.sources=org.springframework.boot.OverrideSourcesTests.MainConfiguration" });
		assertThat(this.context.getBean(Service.class).bean.name).isEqualTo("bar");
	}

	@Configuration(proxyBeanMethods = false)
	static class TestConfiguration {

		@Bean
		@Primary
		TestBean another() {
			return new TestBean("bar");
		}

	}

	@Configuration(proxyBeanMethods = false)
	static class MainConfiguration {

		@Bean
		TestBean first() {
			return new TestBean("foo");
		}

		@Bean
		Service Service() {
			return new Service();
		}

	}

	static class Service {

		@Autowired
		private TestBean bean;

	}

	static class TestBean {

		private final String name;

		TestBean(String name) {
			this.name = name;
		}

	}

}

Analyze Your Own Codebase

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

Try Supermodel Free