SystemStatusListenerTests Class — spring-boot Architecture
Architecture documentation for the SystemStatusListenerTests class in SystemStatusListenerTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/java/org/springframework/boot/logging/logback/SystemStatusListenerTests.java lines 44–140
@ExtendWith(OutputCaptureExtension.class)
class SystemStatusListenerTests {
private static final String TEST_MESSAGE = "testtesttest";
private final StatusManager statusManager = new BasicStatusManager();
private final LoggerContext loggerContext = new LoggerContext();
SystemStatusListenerTests() {
this.loggerContext.setStatusManager(this.statusManager);
}
@Test
void addStatusWithInfoLevelWhenNoDebugDoesNotPrint(CapturedOutput output) {
addStatus(false, () -> new InfoStatus(TEST_MESSAGE, null));
assertThat(output.getOut()).doesNotContain(TEST_MESSAGE);
assertThat(output.getErr()).doesNotContain(TEST_MESSAGE);
}
@Test
void addStatusWithWarningLevelWhenNoDebugPrintsToSystemErr(CapturedOutput output) {
addStatus(false, () -> new WarnStatus(TEST_MESSAGE, null));
assertThat(output.getOut()).doesNotContain(TEST_MESSAGE);
assertThat(output.getErr()).contains(TEST_MESSAGE);
}
@Test
void addStatusWithErrorLevelWhenNoDebugPrintsToSystemErr(CapturedOutput output) {
addStatus(false, () -> new ErrorStatus(TEST_MESSAGE, null));
assertThat(output.getOut()).doesNotContain(TEST_MESSAGE);
assertThat(output.getErr()).contains(TEST_MESSAGE);
}
@Test
void addStatusWithInfoLevelWhenDebugPrintsToSystemOut(CapturedOutput output) {
addStatus(true, () -> new InfoStatus(TEST_MESSAGE, null));
assertThat(output.getOut()).contains(TEST_MESSAGE);
assertThat(output.getErr()).doesNotContain(TEST_MESSAGE);
}
@Test
void addStatusWithWarningLevelWhenDebugPrintsToSystemOut(CapturedOutput output) {
addStatus(true, () -> new WarnStatus(TEST_MESSAGE, null));
assertThat(output.getOut()).contains(TEST_MESSAGE);
assertThat(output.getErr()).doesNotContain(TEST_MESSAGE);
}
@Test
void addStatusWithErrorLevelWhenDebugPrintsToSystemOut(CapturedOutput output) {
addStatus(true, () -> new ErrorStatus(TEST_MESSAGE, null));
assertThat(output.getOut()).contains(TEST_MESSAGE);
assertThat(output.getErr()).doesNotContain(TEST_MESSAGE);
}
@Test
void shouldRetrospectivePrintStatusOnStartAndDebugIsDisabled(CapturedOutput output) {
this.statusManager.add(new ErrorStatus(TEST_MESSAGE, null));
this.statusManager.add(new WarnStatus(TEST_MESSAGE, null));
this.statusManager.add(new InfoStatus(TEST_MESSAGE, null));
addStatus(false, () -> new InfoStatus(TEST_MESSAGE, null));
assertThat(output.getErr()).contains("WARN " + TEST_MESSAGE);
assertThat(output.getErr()).contains("ERROR " + TEST_MESSAGE);
assertThat(output.getErr()).doesNotContain("INFO");
assertThat(output.getOut()).isEmpty();
}
@Test
void shouldRetrospectivePrintStatusOnStartAndDebugIsEnabled(CapturedOutput output) {
this.statusManager.add(new ErrorStatus(TEST_MESSAGE, null));
this.statusManager.add(new WarnStatus(TEST_MESSAGE, null));
this.statusManager.add(new InfoStatus(TEST_MESSAGE, null));
addStatus(true, () -> new InfoStatus(TEST_MESSAGE, null));
assertThat(output.getErr()).isEmpty();
assertThat(output.getOut()).contains("WARN " + TEST_MESSAGE);
assertThat(output.getOut()).contains("ERROR " + TEST_MESSAGE);
assertThat(output.getOut()).contains("INFO " + TEST_MESSAGE);
}
@Test
void shouldNotRetrospectivePrintWhenStatusIsOutdated(CapturedOutput output) {
ErrorStatus outdatedStatus = new ErrorStatus(TEST_MESSAGE, null);
ReflectionTestUtils.setField(outdatedStatus, "timestamp", System.currentTimeMillis() - 300);
this.statusManager.add(outdatedStatus);
addStatus(false, () -> new InfoStatus(TEST_MESSAGE, null));
assertThat(output.getOut()).isEmpty();
assertThat(output.getErr()).isEmpty();
}
private void addStatus(boolean debug, Supplier<Status> statusFactory) {
SystemStatusListener.addTo(this.loggerContext, debug);
StatusListener listener = this.statusManager.getCopyOfStatusListenerList().get(0);
assertThat(listener).extracting("context").isSameAs(this.loggerContext);
listener.addStatusEvent(statusFactory.get());
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free