001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.boolex;
015
016import static org.junit.Assert.assertFalse;
017import static org.junit.Assert.assertTrue;
018
019import org.junit.Before;
020import org.junit.Test;
021import org.slf4j.MarkerFactory;
022
023import ch.qos.logback.classic.Level;
024import ch.qos.logback.classic.LoggerContext;
025import ch.qos.logback.classic.spi.LoggingEvent;
026import ch.qos.logback.core.boolex.EvaluationException;
027
028public class OnMarkerEvaluatorTest {
029
030    LoggerContext lc = new LoggerContext();
031    LoggingEvent event = makeEvent();
032    OnMarkerEvaluator evaluator = new OnMarkerEvaluator();
033
034    @Before
035    public void before() {
036        evaluator.setContext(lc);
037    }
038
039    @Test
040    public void smoke() throws EvaluationException {
041        evaluator.addMarker("M");
042        evaluator.start();
043
044        event.setMarker(MarkerFactory.getMarker("M"));
045        assertTrue(evaluator.evaluate(event));
046    }
047
048    @Test
049    public void nullMarkerInEvent() throws EvaluationException {
050        evaluator.addMarker("M");
051        evaluator.start();
052        assertFalse(evaluator.evaluate(event));
053    }
054
055    @Test
056    public void nullMarkerInEvaluator() throws EvaluationException {
057        evaluator.addMarker("M");
058        evaluator.start();
059        assertFalse(evaluator.evaluate(event));
060    }
061
062    LoggingEvent makeEvent() {
063        return new LoggingEvent("x", lc.getLogger("x"), Level.DEBUG, "msg", null, null);
064    }
065}