Merge pull request #51959 from rvullriede

Closes gh-51959

* fix/logging-lifecycle-not-pauseable:
  Polish "Prevent pausing of the logging system"
  Prevent pausing of the logging system
This commit is contained in:
Stéphane Nicoll
2026-10-07 16:34:49 +02:00
3 changed files with 96 additions and 0 deletions
+1
View File
@@ -61,6 +61,7 @@ dependencies {
testRuntimeOnly("org.aspectj:aspectjrt")
testRuntimeOnly("org.aspectj:aspectjweaver")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testRuntimeOnly("org.slf4j:jul-to-slf4j")
}
tasks.named("compileTestJava") {
@@ -0,0 +1,90 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.test.context;
import java.util.logging.Logger;
import org.junit.jupiter.api.ClassOrderer;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestClassOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.boot.test.context.LoggingApplicationListenerWithContextPausingTests.TestConfig;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link LoggingApplicationListener} when the test context framework pauses a
* context while it's in the cache.
*
* @author Raphael Vullriede
*/
@SpringBootTest(classes = TestConfig.class)
@ExtendWith(OutputCaptureExtension.class)
@TestClassOrder(ClassOrderer.ClassName.class)
class LoggingApplicationListenerWithContextPausingTests {
private static void assertJulOutputIsLogged(CapturedOutput output) {
Logger.getLogger("test").severe("Hello from JUL");
assertThat(output).contains("Hello from JUL");
}
@Nested
@TestPropertySource(properties = "context=one")
class ContextOne {
@Test
void test(CapturedOutput output) {
assertJulOutputIsLogged(output);
}
}
@Nested
@TestPropertySource(properties = "context=two")
class ContextTwo {
@Test
void test(CapturedOutput output) {
assertJulOutputIsLogged(output);
}
}
@Nested
@TestPropertySource(properties = "context=one")
class ReuseContextOne {
@Test
void test(CapturedOutput output) {
assertJulOutputIsLogged(output);
}
}
@Configuration(proxyBeanMethods = false)
static class TestConfig {
}
}
@@ -488,6 +488,11 @@ public class LoggingApplicationListener implements GenericApplicationListener {
return Integer.MIN_VALUE + 1;
}
@Override
public boolean isPauseable() {
return false;
}
}
}