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.core.appender;
15  
16  import ch.qos.logback.core.Appender;
17  import ch.qos.logback.core.Context;
18  import ch.qos.logback.core.ContextBase;
19  import ch.qos.logback.core.status.testUtil.StatusChecker;
20  import ch.qos.logback.core.util.StatusPrinter;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  
24  abstract public class AbstractAppenderTest<E> {
25  
26      abstract protected Appender<E> getAppender();
27  
28      abstract protected Appender<E> getConfiguredAppender();
29  
30      Context context = new ContextBase();
31  
32      @Test
33      public void testNewAppender() {
34          // new appenders should be inactive
35          Appender<E> appender = getAppender();
36          Assertions.assertFalse(appender.isStarted());
37      }
38  
39      @Test
40      public void testConfiguredAppender() {
41          Appender<E> appender = getConfiguredAppender();
42          appender.start();
43          Assertions.assertTrue(appender.isStarted());
44  
45          appender.stop();
46          Assertions.assertFalse(appender.isStarted());
47  
48      }
49  
50      @Test
51      public void testNoStart() {
52          Appender<E> appender = getAppender();
53          appender.setContext(context);
54          appender.setName("doh");
55          // is null OK?
56          appender.doAppend(null);
57          StatusChecker checker = new StatusChecker(context.getStatusManager());
58          StatusPrinter.print(context);
59          checker.assertContainsMatch("Attempted to append to non started appender \\[doh\\].");
60      }
61  }