Home / Class/ ConditionEvaluationReportLoggerTests Class — spring-boot Architecture

ConditionEvaluationReportLoggerTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggerTests.java lines 48–148

@ExtendWith(OutputCaptureExtension.class)
class ConditionEvaluationReportLoggerTests {

	@Test
	void noErrorIfNotInitialized(CapturedOutput output) {
		new ConditionEvaluationReportLogger(LogLevel.INFO, () -> null).logReport(true);
		assertThat(output).contains("Unable to provide the condition evaluation report");
	}

	@Test
	void supportsOnlyInfoAndDebugLogLevels() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> new ConditionEvaluationReportLogger(LogLevel.TRACE, () -> null))
			.withMessageContaining("'logLevel' must be INFO or DEBUG");
	}

	@Test
	void loggerWithInfoLevelShouldLogAtInfo(CapturedOutput output) {
		try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
			ConditionEvaluationReportLogger logger = new ConditionEvaluationReportLogger(LogLevel.INFO,
					() -> ConditionEvaluationReport.get(context.getBeanFactory()));
			context.register(Config.class);
			context.refresh();
			logger.logReport(false);
			assertThat(output).contains("CONDITIONS EVALUATION REPORT");
		}
	}

	@Test
	void loggerWithDebugLevelShouldLogAtDebug(CapturedOutput output) {
		try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
			ConditionEvaluationReportLogger logger = new ConditionEvaluationReportLogger(LogLevel.DEBUG,
					() -> ConditionEvaluationReport.get(context.getBeanFactory()));
			context.register(Config.class);
			context.refresh();
			logger.logReport(false);
			assertThat(output).doesNotContain("CONDITIONS EVALUATION REPORT");
			withDebugLogging(() -> logger.logReport(false));
			assertThat(output).contains("CONDITIONS EVALUATION REPORT");
		}
	}

	@Test
	void logsInfoOnErrorIfDebugDisabled(CapturedOutput output) {
		try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
			ConditionEvaluationReportLogger logger = new ConditionEvaluationReportLogger(LogLevel.DEBUG,
					() -> ConditionEvaluationReport.get(context.getBeanFactory()));
			context.register(Config.class);
			context.refresh();
			logger.logReport(true);
			assertThat(output).contains("Error starting ApplicationContext. To display the condition "
					+ "evaluation report re-run your application with 'debug' enabled.");
		}
	}

	@Test
	void logsOutput(CapturedOutput output) {
		try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
			ConditionEvaluationReportLogger logger = new ConditionEvaluationReportLogger(LogLevel.DEBUG,
					() -> ConditionEvaluationReport.get(context.getBeanFactory()));
			context.register(Config.class);
			ConditionEvaluationReport.get(context.getBeanFactory()).recordExclusions(Arrays.asList("com.foo.Bar"));
			context.refresh();
			withDebugLogging(() -> logger.logReport(false));
			assertThat(output).contains("did not find any beans of type java.time.Duration (OnBeanCondition)")
				.contains("@ConditionalOnProperty (com.example.property) matched (OnPropertyCondition)");
		}
	}

	private void withDebugLogging(Runnable runnable) {
		Logger logger = ((LoggerContext) LoggerFactory.getILoggerFactory())
			.getLogger(ConditionEvaluationReportLogger.class);
		Level currentLevel = logger.getLevel();
		logger.setLevel(Level.DEBUG);
		try {
			runnable.run();
		}
		finally {
			logger.setLevel(currentLevel);
		}
	}

	@Configuration(proxyBeanMethods = false)
	@ImportAutoConfiguration({ MatchingAutoConfiguration.class, NonMatchingAutoConfiguration.class })
	static class Config {

	}

	@AutoConfiguration
	@ConditionalOnProperty(name = "com.example.property", matchIfMissing = true)
	public static final class MatchingAutoConfiguration {

	}

	@AutoConfiguration
	@ConditionalOnBean(Duration.class)
	public static final class NonMatchingAutoConfiguration {

	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free