|
38 | 38 | import ch.qos.logback.core.encoder.LayoutWrappingEncoder; |
39 | 39 | import ch.qos.logback.core.rolling.RollingFileAppender; |
40 | 40 | import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy; |
| 41 | +import ch.qos.logback.core.util.DynamicClassLoadingException; |
41 | 42 | import org.junit.jupiter.api.AfterEach; |
42 | 43 | import org.junit.jupiter.api.BeforeEach; |
43 | 44 | import org.junit.jupiter.api.Test; |
@@ -519,7 +520,7 @@ void initializeShouldApplyLogbackSystemPropertiesToTheContext() { |
519 | 520 | initialize(this.initializationContext, null, null); |
520 | 521 | LoggerContext loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory(); |
521 | 522 | Map<String, String> properties = loggerContext.getCopyOfPropertyMap(); |
522 | | - Set<String> expectedProperties = new HashSet<String>(); |
| 523 | + Set<String> expectedProperties = new HashSet<>(); |
523 | 524 | ReflectionUtils.doWithFields(LogbackLoggingSystemProperties.class, |
524 | 525 | (field) -> expectedProperties.add((String) field.get(null)), this::isPublicStaticFinal); |
525 | 526 | expectedProperties.removeAll(Arrays.asList("LOG_FILE", "LOG_PATH")); |
@@ -624,6 +625,16 @@ void customCharset() { |
624 | 625 | assertThat(encoder.getCharset()).isEqualTo(StandardCharsets.UTF_16); |
625 | 626 | } |
626 | 627 |
|
| 628 | + @Test |
| 629 | + void whenConfigurationErrorIsDetectedUnderlyingCausesAreIncludedAsSuppressedExceptions() { |
| 630 | + this.loggingSystem.beforeInitialize(); |
| 631 | + assertThatIllegalStateException() |
| 632 | + .isThrownBy(() -> initialize(this.initializationContext, "classpath:logback-broken.xml", |
| 633 | + getLogFile(tmpDir() + "/tmp.log", null))) |
| 634 | + .satisfies((ex) -> assertThat(ex.getSuppressed()) |
| 635 | + .hasAtLeastOneElementOfType(DynamicClassLoadingException.class)); |
| 636 | + } |
| 637 | + |
627 | 638 | private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) { |
628 | 639 | this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile); |
629 | 640 | this.loggingSystem.initialize(context, configLocation, logFile); |
|
0 commit comments