1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  
15  package ch.qos.logback.classic.layout;
16  
17  
18  import org.junit.jupiter.api.BeforeEach;
19  
20  import ch.qos.logback.classic.Level;
21  import ch.qos.logback.classic.Logger;
22  import ch.qos.logback.classic.LoggerContext;
23  import ch.qos.logback.classic.spi.LoggingEvent;
24  import org.junit.jupiter.api.Test;
25  
26  import static org.junit.jupiter.api.Assertions.assertTrue;
27  
28  public class TTLLLayoutTest {
29  
30      LoggerContext context = new LoggerContext();
31      Logger logger = context.getLogger(TTLLLayoutTest.class);
32      TTLLLayout layout = new TTLLLayout();
33  
34      @BeforeEach
35      public void setUp() {
36          layout.setContext(context);
37          layout.start();
38      }
39  
40      @Test
41      public void nullMessage() {
42          LoggingEvent event = new LoggingEvent("", logger, Level.INFO, null, null, null);
43          event.setTimeStamp(0);
44          String result = layout.doLayout(event);
45  
46          String resultSuffix = result.substring(13).trim();
47  
48          assertTrue(resultSuffix.matches("\\[.*\\] INFO ch.qos.logback.classic.layout.TTLLLayoutTest -- null"),
49                  "[" + resultSuffix + "] did not match regex");
50      }
51  }