Home / Class/ LoggingApplicationListenerIntegrationTests Class — spring-boot Architecture

LoggingApplicationListenerIntegrationTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java lines 50–138

@WithResource(name = "META-INF/spring.factories",
		content = """
				org.springframework.boot.logging.LoggingSystemFactory=org.springframework.boot.context.logging.LoggingApplicationListenerIntegrationTests$MockLoggingSystemFactory
				""")
@ExtendWith(OutputCaptureExtension.class)
class LoggingApplicationListenerIntegrationTests {

	@Test
	void loggingSystemRegisteredInTheContext() {
		try (ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleService.class)
			.web(WebApplicationType.NONE)
			.run()) {
			SampleService service = context.getBean(SampleService.class);
			assertThat(service.loggingSystem).isNotNull();
		}
	}

	@Test
	void logFileRegisteredInTheContextWhenApplicable(@TempDir File tempDir) {
		String logFile = new File(tempDir, "test.log").getAbsolutePath();
		try (ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleService.class)
			.web(WebApplicationType.NONE)
			.properties("logging.file.name=" + logFile)
			.run()) {
			SampleService service = context.getBean(SampleService.class);
			assertThat(service.logFile).isNotNull();
			assertThat(service.logFile).hasToString(logFile);
		}
		finally {
			System.clearProperty(LoggingSystemProperty.LOG_FILE.getEnvironmentVariableName());
		}
	}

	@Test
	void loggingPerformedDuringChildApplicationStartIsNotLost(CapturedOutput output) {
		new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
			.child(Config.class)
			.web(WebApplicationType.NONE)
			.listeners(new ApplicationListener<ApplicationStartingEvent>() {

				private final Logger logger = LoggerFactory.getLogger(getClass());

				@Override
				public void onApplicationEvent(ApplicationStartingEvent event) {
					this.logger.info("Child application starting");
				}

			})
			.run();
		assertThat(output).contains("Child application starting");
	}

	@Component
	static class SampleService {

		private final LoggingSystem loggingSystem;

		private final @Nullable LogFile logFile;

		SampleService(LoggingSystem loggingSystem, ObjectProvider<LogFile> logFile) {
			this.loggingSystem = loggingSystem;
			this.logFile = logFile.getIfAvailable();
		}

	}

	static class Config {

	}

	static class MockLoggingSystemFactory implements LoggingSystemFactory {

		@Override
		public LoggingSystem getLoggingSystem(ClassLoader classLoader) {
			return new MockLoggingSystem();
		}

	}

	static class MockLoggingSystem extends LoggingSystem {

		@Override
		public void beforeInitialize() {

		}

	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free