1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.pattern;
15
16 import ch.qos.logback.classic.Level;
17 import ch.qos.logback.classic.Logger;
18 import ch.qos.logback.classic.LoggerContext;
19 import ch.qos.logback.classic.spi.LoggingEvent;
20 import org.junit.jupiter.api.AfterEach;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import org.slf4j.event.KeyValuePair;
24
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26
27 public class KeyValuePairConverterTest {
28 LoggerContext lc;
29 KeyValuePairConverter converter;
30 LoggingEvent event;
31
32 @BeforeEach
33 public void setUp() throws Exception {
34 lc = new LoggerContext();
35 converter = new KeyValuePairConverter();
36 converter.start();
37 event = createLoggingEvent();
38 }
39
40 @AfterEach
41 public void tearDown() throws Exception {
42 lc = null;
43 converter.stop();
44 converter = null;
45 }
46
47 @Test
48 public void testWithNullKVPList() {
49
50 String result = converter.convert(event);
51 assertEquals("", result);
52 }
53
54 @Test
55 public void testWithOnelKVP() {
56 event.addKeyValuePair(new KeyValuePair("k", "v"));
57 String result = converter.convert(event);
58 assertEquals("k=\"v\"", result);
59 }
60
61 private LoggingEvent createLoggingEvent() {
62 LoggingEvent le = new LoggingEvent(this.getClass().getName(), lc.getLogger(Logger.ROOT_LOGGER_NAME),
63 Level.DEBUG, "test message", null, null);
64 return le;
65 }
66 }