Home / Class/ LogbackLoggingSystemPropertiesTests Class — spring-boot Architecture

LogbackLoggingSystemPropertiesTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemPropertiesTests.java lines 45–124

class LogbackLoggingSystemPropertiesTests {

	private Set<Object> systemPropertyNames;

	private MockEnvironment environment;

	@BeforeEach
	void captureSystemPropertyNames() {
		for (LoggingSystemProperty property : LoggingSystemProperty.values()) {
			System.getProperties().remove(property.getEnvironmentVariableName());
		}
		this.systemPropertyNames = new HashSet<>(System.getProperties().keySet());
		this.environment = new MockEnvironment();
		this.environment
			.setConversionService((ConfigurableConversionService) ApplicationConversionService.getSharedInstance());

	}

	@AfterEach
	void restoreSystemProperties() {
		System.getProperties().keySet().retainAll(this.systemPropertyNames);
	}

	@Test
	void applySetsStandardSystemProperties() {
		this.environment.setProperty("logging.pattern.console", "boot");
		new LogbackLoggingSystemProperties(this.environment).apply();
		assertThat(System.getProperties())
			.containsEntry(LoggingSystemProperty.CONSOLE_PATTERN.getEnvironmentVariableName(), "boot");
	}

	@Test
	void applySetsLogbackSystemProperties() {
		this.environment.setProperty("logging.logback.rollingpolicy.file-name-pattern", "fnp");
		this.environment.setProperty("logging.logback.rollingpolicy.clean-history-on-start", "chos");
		this.environment.setProperty("logging.logback.rollingpolicy.max-file-size", "1KB");
		this.environment.setProperty("logging.logback.rollingpolicy.total-size-cap", "2KB");
		this.environment.setProperty("logging.logback.rollingpolicy.max-history", "mh");
		new LogbackLoggingSystemProperties(this.environment).apply();
		assertThat(System.getProperties())
			.containsEntry(RollingPolicySystemProperty.FILE_NAME_PATTERN.getEnvironmentVariableName(), "fnp")
			.containsEntry(RollingPolicySystemProperty.CLEAN_HISTORY_ON_START.getEnvironmentVariableName(), "chos")
			.containsEntry(RollingPolicySystemProperty.MAX_FILE_SIZE.getEnvironmentVariableName(), "1024")
			.containsEntry(RollingPolicySystemProperty.TOTAL_SIZE_CAP.getEnvironmentVariableName(), "2048")
			.containsEntry(RollingPolicySystemProperty.MAX_HISTORY.getEnvironmentVariableName(), "mh");
	}

	@Test
	void consoleCharsetWhenNoPropertyUsesDefault() {
		LogbackLoggingSystemProperties logbackLoggingSystemProperties = spy(
				new LogbackLoggingSystemProperties(new MockEnvironment(), null, null));
		given(logbackLoggingSystemProperties.getConsole()).willReturn(null);

		logbackLoggingSystemProperties.apply(null);
		assertThat(System.getProperty(LoggingSystemProperty.CONSOLE_CHARSET.getEnvironmentVariableName()))
			.isEqualTo(Charset.defaultCharset().name());
	}

	@Test
	void consoleCharsetWhenNoPropertyUsesSystemConsoleCharsetWhenAvailable() {
		LogbackLoggingSystemProperties logbackLoggingSystemProperties = spy(
				new LogbackLoggingSystemProperties(new MockEnvironment(), null, null));

		Console console = mock(Console.class);
		given(console.charset()).willReturn(StandardCharsets.UTF_16BE);
		given(logbackLoggingSystemProperties.getConsole()).willReturn(console);

		logbackLoggingSystemProperties.apply(null);
		assertThat(System.getProperty(LoggingSystemProperty.CONSOLE_CHARSET.getEnvironmentVariableName()))
			.isEqualTo(StandardCharsets.UTF_16BE.name());
	}

	@Test
	void fileCharsetWhenNoPropertyUsesUtf8() {
		new LoggingSystemProperties(new MockEnvironment()).apply(null);
		assertThat(System.getProperty(LoggingSystemProperty.FILE_CHARSET.getEnvironmentVariableName()))
			.isEqualTo(StandardCharsets.UTF_8.name());
	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free