1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.boolex;
15
16 import org.junit.jupiter.api.BeforeEach;
17 import org.junit.jupiter.api.Test;
18 import org.slf4j.MarkerFactory;
19
20 import ch.qos.logback.classic.Level;
21 import ch.qos.logback.classic.LoggerContext;
22 import ch.qos.logback.classic.spi.LoggingEvent;
23 import ch.qos.logback.core.boolex.EvaluationException;
24
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27
28 public class OnMarkerEvaluatorTest {
29
30 LoggerContext lc = new LoggerContext();
31 LoggingEvent event = makeEvent();
32 OnMarkerEvaluator evaluator = new OnMarkerEvaluator();
33
34 @BeforeEach
35 public void before() {
36 evaluator.setContext(lc);
37 }
38
39 @Test
40 public void smoke() throws EvaluationException {
41 evaluator.addMarker("M");
42 evaluator.start();
43
44 event.addMarker(MarkerFactory.getMarker("M"));
45 assertTrue(evaluator.evaluate(event));
46 }
47
48 @Test
49 public void nullMarkerInEvent() throws EvaluationException {
50 evaluator.addMarker("M");
51 evaluator.start();
52 assertFalse(evaluator.evaluate(event));
53 }
54
55 @Test
56 public void nullMarkerInEvaluator() throws EvaluationException {
57 evaluator.addMarker("M");
58 evaluator.start();
59 assertFalse(evaluator.evaluate(event));
60 }
61
62 LoggingEvent makeEvent() {
63 return new LoggingEvent("x", lc.getLogger("x"), Level.DEBUG, "msg", null, null);
64 }
65 }