From c7ef3e3e3cd5b0e0b3a463c3e5a9bcdd483e9b77 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 7 Jan 2025 14:44:28 +0000 Subject: [PATCH] Simplify test for Throwable from LoggingSystem initialization Closes gh-43709 --- .../LoggingApplicationListenerTests.java | 42 ++++++++++++++++--- .../src/test/resources/logback-janino.xml | 18 -------- 2 files changed, 37 insertions(+), 23 deletions(-) delete mode 100644 spring-boot-project/spring-boot/src/test/resources/logback-janino.xml diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java index b44c893d5d70..0af577c72f0f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java @@ -168,13 +168,13 @@ void overrideConfigLocation() { } @Test - @ClassPathExclusions("janino-*.jar") - void tryingToUseJaninoWhenItIsNotOnTheClasspathFailsGracefully(CapturedOutput output) { - addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-janino.xml"); + void throwableFromInitializeResultsInGracefulFailure(CapturedOutput output) { + System.setProperty(LoggingSystem.SYSTEM_PROPERTY, BrokenInitializationLoggingSystem.class.getName()); + multicastEvent(this.listener, + new ApplicationStartingEvent(this.bootstrapContext, new SpringApplication(), NO_ARGS)); assertThatIllegalStateException() .isThrownBy(() -> this.listener.initialize(this.context.getEnvironment(), this.context.getClassLoader())); - assertThat(output) - .contains("Logging system failed to initialize using configuration from 'classpath:logback-janino.xml'"); + assertThat(output).contains("Deliberately broken"); } @Test @@ -712,6 +712,38 @@ public void cleanUp() { } + static final class BrokenInitializationLoggingSystem extends LoggingSystem { + + BrokenInitializationLoggingSystem(ClassLoader classLoader) { + + } + + @Override + public void beforeInitialize() { + } + + @Override + public void initialize(LoggingInitializationContext initializationContext, String configLocation, + LogFile logFile) { + throw new Error("Deliberately broken"); + } + + @Override + public void setLogLevel(String loggerName, LogLevel level) { + } + + @Override + public List getLoggerConfigurations() { + return null; + } + + @Override + public LoggerConfiguration getLoggerConfiguration(String loggerName) { + return null; + } + + } + @Configuration @Import(WebServerStyleLifecycle.class) static class TestConfiguration { diff --git a/spring-boot-project/spring-boot/src/test/resources/logback-janino.xml b/spring-boot-project/spring-boot/src/test/resources/logback-janino.xml deleted file mode 100644 index 5274e6f9693e..000000000000 --- a/spring-boot-project/spring-boot/src/test/resources/logback-janino.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - %property{LOG_FILE} [%t] ${PID:-????} %c{1}: %m%n BOOTBOOT - - - - return level <= DEBUG; - - DENY - NEUTRAL - - - - - -