1 package ch.qos.logback.classic.layout; 2 3 4 import org.junit.jupiter.api.BeforeEach; 5 6 import ch.qos.logback.classic.Level; 7 import ch.qos.logback.classic.Logger; 8 import ch.qos.logback.classic.LoggerContext; 9 import ch.qos.logback.classic.spi.LoggingEvent; 10 import org.junit.jupiter.api.Test; 11 12 import static org.junit.jupiter.api.Assertions.assertTrue; 13 14 public class TTLLLayoutTest { 15 16 LoggerContext context = new LoggerContext(); 17 Logger logger = context.getLogger(TTLLLayoutTest.class); 18 TTLLLayout layout = new TTLLLayout(); 19 20 @BeforeEach 21 public void setUp() { 22 layout.setContext(context); 23 layout.start(); 24 } 25 26 @Test 27 public void nullMessage() { 28 LoggingEvent event = new LoggingEvent("", logger, Level.INFO, null, null, null); 29 event.setTimeStamp(0); 30 String result = layout.doLayout(event); 31 32 String resultSuffix = result.substring(13).trim(); 33 34 assertTrue(resultSuffix.matches("\\[.*\\] INFO ch.qos.logback.classic.layout.TTLLLayoutTest -- null"), 35 "[" + resultSuffix + "] did not match regex"); 36 } 37 }