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.spi.LoggingEvent;
17 import org.junit.jupiter.api.Test;
18
19 import java.time.Instant;
20 import java.util.Collections;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23
24 public class EpochConverterTest {
25 EpochConverter ec = new EpochConverter();
26
27 @Test
28 public void withDefaultConfiguration() {
29 ec.setOptionList(null);
30 ec.start();
31 LoggingEvent le = new LoggingEvent();
32 Instant instant = Instant.parse("2026-01-15T10:15:30Z");
33 instant = instant.plusMillis(321);
34 le.setInstant(instant);
35
36 String result = ec.convert(le);
37 assertEquals("1768472130321", result);
38 }
39
40 @Test
41 public void withSecondsConfiguration() {
42 ec.setOptionList(Collections.singletonList("seconds"));
43 ec.start();
44 LoggingEvent le = new LoggingEvent();
45 Instant instant = Instant.parse("2026-01-15T10:15:30Z");
46 instant = instant.plusMillis(321);
47 le.setInstant(instant);
48
49 String result = ec.convert(le);
50 assertEquals("1768472130", result);
51 }
52
53 @Test
54 public void withUnknownNonsenseConfiguration() {
55 ec.setOptionList(Collections.singletonList("nonsense"));
56 ec.start();
57 LoggingEvent le = new LoggingEvent();
58 Instant instant = Instant.parse("2026-01-15T10:15:30Z");
59 instant = instant.plusMillis(321);
60 le.setInstant(instant);
61
62 String result = ec.convert(le);
63 assertEquals("1768472130321", result);
64 }
65 }