1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.pattern;
15
16 import org.junit.jupiter.api.BeforeEach;
17
18 import ch.qos.logback.classic.Level;
19 import ch.qos.logback.classic.Logger;
20 import ch.qos.logback.classic.LoggerContext;
21 import ch.qos.logback.classic.PatternLayout;
22 import ch.qos.logback.classic.spi.ILoggingEvent;
23 import ch.qos.logback.classic.spi.LoggingEvent;
24 import org.junit.jupiter.api.Test;
25
26 public class EnsureExceptionHandlingTest {
27
28 private PatternLayout pl = new PatternLayout();
29 private LoggerContext lc = new LoggerContext();
30 Logger logger = lc.getLogger(this.getClass());
31
32 static final String XTH = "xth";
33 static final String XCC = "xcc";
34
35 @BeforeEach
36 public void setUp() {
37 pl.setContext(lc);
38 pl.getInstanceConverterMap().put(XTH, XThrowableHandlingConverter.class.getName());
39 pl.getInstanceConverterMap().put(XCC, XCompositeConverter.class.getName());
40 }
41
42 ILoggingEvent makeLoggingEvent(String msg, Exception ex) {
43 return new LoggingEvent(EnsureExceptionHandlingTest.class.getName(), logger, Level.INFO, msg, ex, null);
44 }
45
46 @Test
47 public void smoke() {
48 pl.setPattern("%m %" + XTH + ")");
49 pl.start();
50 ILoggingEvent le = makeLoggingEvent("assert", null);
51 pl.doLayout(le);
52 }
53
54 @Test
55 public void withinComposite() {
56 pl.setPattern("%m %" + XCC + "(%" + XTH + ")");
57 pl.start();
58 ILoggingEvent le = makeLoggingEvent("assert", null);
59 pl.doLayout(le);
60 }
61
62 }