Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log contents capture test extension #4536

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
test for new extension
  • Loading branch information
michaelabuckley committed Feb 9, 2023
commit 435e18f6c8266cad356409dd99b181de125c1387
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ca.uhn.test.util;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

class LogContentsTestExtentionTest {
private static final Logger ourLog = LoggerFactory.getLogger(LogContentsTestExtentionTest.class);
@RegisterExtension
LogContentsTestExtention myExtention = new LogContentsTestExtention((ch.qos.logback.classic.Logger) ourLog);

@Test
void testExtensionCapturesMessage() {
ourLog.info("Hello hello");

assertThat(myExtention.getLogOutput(), containsString("Hello hello"));
}

@Test
void testExtensionCapturesStackTraceAndExceptionMessage() {
ourLog.info("Hello hello", new RuntimeException("exception message"));

assertThat(myExtention.getLogOutput(), containsString("exception message"));
assertThat(myExtention.getLogOutput(), containsString("testExtensionCapturesStackTraceAndExceptionMessage"));
}
}