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.net.ssl.mock;
15  
16  import java.util.LinkedList;
17  import java.util.List;
18  
19  import ch.qos.logback.core.spi.ContextAware;
20  import ch.qos.logback.core.spi.ContextAwareBase;
21  
22  /**
23   * A {@link ContextAware} with instrumentation for unit testing.
24   *
25   * @author Carl Harris
26   */
27  public class MockContextAware extends ContextAwareBase implements ContextAware {
28  
29      private final List<String> info = new LinkedList<String>();
30      private final List<String> warn = new LinkedList<String>();
31      private final List<String> error = new LinkedList<String>();
32  
33      @Override
34      public void addInfo(String msg) {
35          info.add(msg);
36      }
37  
38      @Override
39      public void addWarn(String msg) {
40          warn.add(msg);
41      }
42  
43      @Override
44      public void addError(String msg) {
45          error.add(msg);
46      }
47  
48      public boolean hasInfoMatching(String regex) {
49          return hasMatching(info, regex);
50      }
51  
52      public boolean hasWarnMatching(String regex) {
53          return hasMatching(info, regex);
54      }
55  
56      public boolean hasErrorMatching(String regex) {
57          return hasMatching(info, regex);
58      }
59  
60      private boolean hasMatching(List<String> messages, String regex) {
61          for (String message : messages) {
62              if (message.matches(regex))
63                  return true;
64          }
65          return false;
66      }
67  
68  }