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.core.appender;
015
016import static org.junit.Assert.assertFalse;
017import static org.junit.Assert.assertTrue;
018
019import org.junit.Test;
020
021import ch.qos.logback.core.Appender;
022import ch.qos.logback.core.Context;
023import ch.qos.logback.core.ContextBase;
024import ch.qos.logback.core.testUtil.StatusChecker;
025import ch.qos.logback.core.util.StatusPrinter;
026
027abstract public class AbstractAppenderTest<E> {
028
029    abstract protected Appender<E> getAppender();
030
031    abstract protected Appender<E> getConfiguredAppender();
032
033    Context context = new ContextBase();
034
035    @Test
036    public void testNewAppender() {
037        // new appenders should be inactive
038        Appender<E> appender = getAppender();
039        assertFalse(appender.isStarted());
040    }
041
042    @Test
043    public void testConfiguredAppender() {
044        Appender<E> appender = getConfiguredAppender();
045        appender.start();
046        assertTrue(appender.isStarted());
047
048        appender.stop();
049        assertFalse(appender.isStarted());
050
051    }
052
053    @Test
054    public void testNoStart() {
055        Appender<E> appender = getAppender();
056        appender.setContext(context);
057        appender.setName("doh");
058        // is null OK?
059        appender.doAppend(null);
060        StatusChecker checker = new StatusChecker(context.getStatusManager());
061        StatusPrinter.print(context);
062        checker.assertContainsMatch("Attempted to append to non started appender \\[doh\\].");
063    }
064}