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 static org.junit.Assert.assertFalse;
17  import static org.junit.Assert.assertTrue;
18  
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.slf4j.MarkerFactory;
22  
23  import ch.qos.logback.classic.Level;
24  import ch.qos.logback.classic.LoggerContext;
25  import ch.qos.logback.classic.spi.LoggingEvent;
26  import ch.qos.logback.core.boolex.EvaluationException;
27  
28  public class OnMarkerEvaluatorTest {
29  
30      LoggerContext lc = new LoggerContext();
31      LoggingEvent event = makeEvent();
32      OnMarkerEvaluator evaluator = new OnMarkerEvaluator();
33  
34      @Before
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.setMarker(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  }