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