Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ void StatusData_getFormattedStatus_should_be_used() {
}

@Test
void level_and_stream_should_be_honored() throws Exception {
void stream_should_be_honored() throws Exception {

// Create the listener.
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final String encoding = "UTF-8";
final PrintStream printStream = new PrintStream(outputStream, false, encoding);
final StatusConsoleListener listener = new StatusConsoleListener(Level.WARN, printStream);

// First, log a message that is expected to be logged.
// log a message that is expected to be logged.
final RuntimeException expectedThrowable = new RuntimeException("expectedThrowable");
expectedThrowable.setStackTrace(new StackTraceElement[] {
new StackTraceElement("expectedThrowableClass", "expectedThrowableMethod", "expectedThrowableFile", 1)
Expand All @@ -71,29 +71,12 @@ void level_and_stream_should_be_honored() throws Exception {
expectedThrowable,
null)); // as set by `StatusLogger` itself

// Second, log a message that is expected to be discarded due to its insufficient level.
final RuntimeException discardedThrowable = new RuntimeException("discardedThrowable");
discardedThrowable.setStackTrace(new StackTraceElement[] {
new StackTraceElement("discardedThrowableClass", "discardedThrowableMethod", "discardedThrowableFile", 2)
});
final Message discardedMessage = MESSAGE_FACTORY.newMessage("discardedMessage");
listener.log(new StatusData(
null, // since ignored by `SimpleLogger`
Level.INFO,
discardedMessage,
discardedThrowable,
null)); // as set by `StatusLogger` itself

// Collect the output.
printStream.flush();
final String output = outputStream.toString(encoding);

// Verify the output.
assertThat(output)
.contains(expectedThrowable.getMessage())
.contains(expectedMessage.getFormattedMessage())
.doesNotContain(discardedThrowable.getMessage())
.doesNotContain(discardedMessage.getFormattedMessage());
assertThat(output).contains(expectedThrowable.getMessage()).contains(expectedMessage.getFormattedMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ public Level getStatusLevel() {
@Override
public void log(final StatusData data) {
requireNonNull(data, "data");
if (level.isLessSpecificThan(data.getLevel())) {
final String formattedStatus = data.getFormattedStatus();
stream.println(formattedStatus);
}
final String formattedStatus = data.getFormattedStatus();
stream.println(formattedStatus);
}

/**
Expand Down