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.net.ssl.mock; 015 016import java.util.LinkedList; 017import java.util.List; 018 019import ch.qos.logback.core.spi.ContextAware; 020import ch.qos.logback.core.spi.ContextAwareBase; 021 022/** 023 * A {@link ContextAware} with instrumentation for unit testing. 024 * 025 * @author Carl Harris 026 */ 027public class MockContextAware extends ContextAwareBase implements ContextAware { 028 029 private final List<String> info = new LinkedList<String>(); 030 private final List<String> warn = new LinkedList<String>(); 031 private final List<String> error = new LinkedList<String>(); 032 033 @Override 034 public void addInfo(String msg) { 035 info.add(msg); 036 } 037 038 @Override 039 public void addWarn(String msg) { 040 warn.add(msg); 041 } 042 043 @Override 044 public void addError(String msg) { 045 error.add(msg); 046 } 047 048 public boolean hasInfoMatching(String regex) { 049 return hasMatching(info, regex); 050 } 051 052 public boolean hasWarnMatching(String regex) { 053 return hasMatching(info, regex); 054 } 055 056 public boolean hasErrorMatching(String regex) { 057 return hasMatching(info, regex); 058 } 059 060 private boolean hasMatching(List<String> messages, String regex) { 061 for (String message : messages) { 062 if (message.matches(regex)) 063 return true; 064 } 065 return false; 066 } 067 068}