View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 v1.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  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  }