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.mock; 015 016import java.util.List; 017import java.util.concurrent.ScheduledExecutorService; 018 019import ch.qos.logback.core.Context; 020import ch.qos.logback.core.ContextBase; 021import ch.qos.logback.core.status.Status; 022import ch.qos.logback.core.status.StatusListener; 023import ch.qos.logback.core.status.StatusManager; 024 025/** 026 * A mock {@link Context} with instrumentation for unit testing. 027 * 028 * @author Carl Harris 029 */ 030public class MockContext extends ContextBase { 031 032 private final ScheduledExecutorService scheduledExecutorService; 033 034 private Status lastStatus; 035 036 public MockContext() { 037 this(new MockScheduledExecutorService()); 038 } 039 040 public MockContext(ScheduledExecutorService executorService) { 041 this.setStatusManager(new MockStatusManager()); 042 this.scheduledExecutorService = executorService; 043 } 044 045 @Override 046 public ScheduledExecutorService getScheduledExecutorService() { 047 return scheduledExecutorService; 048 } 049 050 public Status getLastStatus() { 051 return lastStatus; 052 } 053 054 public void setLastStatus(Status lastStatus) { 055 this.lastStatus = lastStatus; 056 } 057 058 private class MockStatusManager implements StatusManager { 059 060 public void add(Status status) { 061 lastStatus = status; 062 } 063 064 public List<Status> getCopyOfStatusList() { 065 throw new UnsupportedOperationException(); 066 } 067 068 public int getCount() { 069 throw new UnsupportedOperationException(); 070 } 071 072 public boolean add(StatusListener listener) { 073 throw new UnsupportedOperationException(); 074 } 075 076 public void remove(StatusListener listener) { 077 throw new UnsupportedOperationException(); 078 } 079 080 public void clear() { 081 throw new UnsupportedOperationException(); 082 } 083 084 public List<StatusListener> getCopyOfStatusListenerList() { 085 throw new UnsupportedOperationException(); 086 } 087 088 } 089 090}