Skip to content

Instantly share code, notes, and snippets.

SLF4J: A number (4) of logging calls during the initialization phase have been intercepted and are
SLF4J: now being replayed. These are subject to the filtering rules of the underlying logging system.
SLF4J: See also http://www.slf4j.org/codes.html#replay
public class LogbackInitializerExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) throws Exception {
pauseTillLogbackReady();
}
private static void pauseTillLogbackReady() {
while(!isLogbackReady());
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@ExtendWith(LogbackInitializerExtension.class)
public @interface LogbackInitializer {
}
public class LocalAppender extends AppenderBase<ILoggingEvent> {
private List<ILoggingEvent> events = new ArrayList<>();
public LocalAppender() {
start();
}
public static LocalAppender initialize(String... loggers) {
LocalAppender localAppender = new LocalAppender();
for (String loggerName : loggers) {
@LogbackInitializer
public class TestLocalAppender {
@Test
@ResourceLock(value = "LOGGING", mode = ResourceAccessMode.READ_WRITE)
public void testLocalAppenderA() {
OtherLogProducingService service = new OtherLogProducingService();
LocalAppender localAppender = LocalAppender.initialize("com.bk.logging.OtherLogProducingService");
public class TestAcceptedMediaTypes {
private static final MediaType[] SUPPORTED_MEDIA_TYPES = new MediaType[] { MediaType.APPLICATION_JSON,
MediaType.APPLICATION_XML };
@TestFactory
Collection<DynamicTest> testAcceptedMediaTypes() throws Exception {
// Creating a classpath scanner to find all controller classes in project
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(new DefaultListableBeanFactory(),
public class TestAcceptedMediaTypes {
private static final MediaType[] SUPPORTED_MEDIA_TYPES = new MediaType[] { MediaType.APPLICATION_JSON_UTF8,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
@TestFactory
Collection<DynamicContainer> testAcceptedMediaTypes() throws Exception {
...
List<DynamicContainer> dynamicContainers = new ArrayList<>();
@TestFactory
public List<DynamicTest> exampleTestFactory() {
return Arrays.asList(
dynamicTest("Dynamic square " + 2, () -> assertEquals(4, 2 * 2)),//
dynamicTest("Dynamic true " + true, () -> assertTrue(true)));
}
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bk.booking</groupId>
<artifactId>spring-boot-simple-surefire-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit-platform.version}</version>
</dependency>