This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testInfo(TestInfo testInfo) { | |
assertAll(() -> throwerrors("Just throwing"), | |
() -> throwerrors("Some random"), | |
() -> throwerrors("errors")); | |
} | |
public void throwerrors(String message) { | |
throw new RuntimeException(message); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class SpringBootVersion implements InfoContributor { | |
@Override | |
public void contribute(Builder builder) { | |
try { | |
Manifest mf = new Manifest(); | |
mf.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/MANIFEST.MF")); | |
Attributes atts = mf.getMainAttributes(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LogProducingService { | |
private static final Logger LOGGER = LoggerFactory.getLogger(LogProducingService.class); | |
public void writeSomeLoggingStatements(String message) { | |
LOGGER.info("Let's assert some logs! " + message); | |
ExecutorService executor = Executors.newSingleThreadExecutor(); | |
Future<?> future = executor.submit(() -> LOGGER.info("This message is in a separate thread")); | |
do { | |
// wait for future to complete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StaticAppender extends AppenderBase<ILoggingEvent> { | |
static List<ILoggingEvent> events = new ArrayList<>(); | |
@Override | |
public void append(ILoggingEvent e) { | |
events.add(e); | |
} | |
public static List<ILoggingEvent> getEvents() { | |
return events; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<appender name="static-appender" class="com.bk.logging.StaticAppender" /> | |
<root level="trace"> | |
<appender-ref ref="static-appender" /> | |
</root> | |
</configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestStaticAppender { | |
@BeforeEach | |
public void clearLoggingStatements() { | |
StaticAppender.clearEvents(); | |
} | |
@Test | |
public void testAssertingLoggingStatementsA() { | |
LogProducingService service = new LogProducingService(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreadSafeAppender extends AppenderBase<ILoggingEvent> { | |
static ThreadLocal<List<ILoggingEvent>> threadLocal = new ThreadLocal<>(); | |
@Override | |
public void append(ILoggingEvent e) { | |
List<ILoggingEvent> events = threadLocal.get(); | |
if (events == null) { | |
events = new ArrayList<>(); | |
threadLocal.set(events); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<appender name="threadsafe-appender" class="com.bk.logging.ThreadSafeAppender" /> | |
<root level="trace"> | |
<appender-ref ref="threadsafe-appender" /> | |
</root> | |
</configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
... | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-surefire-plugin</artifactId> | |
<version>2.22.0</version> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestThreadSafeAppender { | |
@BeforeEach | |
public void clearLoggingStatements() { | |
ThreadSafeAppender.clearEvents(); | |
} | |
@Test | |
public void testAssertingLoggingStatementsA() { | |
LogProducingService service = new LogProducingService(); | |
service.writeSomeLoggingStatements("A"); |
OlderNewer