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.mock;
15  
16  import java.util.List;
17  import java.util.concurrent.ExecutorService;
18  import java.util.concurrent.ScheduledExecutorService;
19  import java.util.concurrent.ThreadPoolExecutor;
20  
21  import ch.qos.logback.core.Context;
22  import ch.qos.logback.core.ContextBase;
23  import ch.qos.logback.core.status.Status;
24  import ch.qos.logback.core.status.StatusListener;
25  import ch.qos.logback.core.status.StatusManager;
26  
27  /**
28   * A mock {@link Context} with instrumentation for unit testing.
29   *
30   * @author Carl Harris
31   */
32  public class MockContext extends ContextBase {
33  
34      private final ExecutorService executorService;
35  
36      private Status lastStatus;
37  
38      public MockContext() {
39          this(new MockScheduledExecutorService());
40      }
41  
42      public MockContext(ExecutorService executorService) {
43          this.setStatusManager(new MockStatusManager());
44          this.executorService = executorService;
45      }
46  
47      @Override
48      public ExecutorService getExecutorService() {
49          return executorService;
50      }
51  
52      public Status getLastStatus() {
53          return lastStatus;
54      }
55  
56      public void setLastStatus(Status lastStatus) {
57          this.lastStatus = lastStatus;
58      }
59  
60      private class MockStatusManager implements StatusManager {
61  
62          public void add(Status status) {
63              lastStatus = status;
64          }
65  
66          public List<Status> getCopyOfStatusList() {
67              throw new UnsupportedOperationException();
68          }
69  
70          public int getCount() {
71              throw new UnsupportedOperationException();
72          }
73  
74          public boolean add(StatusListener listener) {
75              throw new UnsupportedOperationException();
76          }
77  
78          public void remove(StatusListener listener) {
79              throw new UnsupportedOperationException();
80          }
81  
82          public void clear() {
83              throw new UnsupportedOperationException();
84          }
85  
86          public List<StatusListener> getCopyOfStatusListenerList() {
87              throw new UnsupportedOperationException();
88          }
89  
90      }
91  
92  }