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.Collections;
17  import java.util.List;
18  import java.util.concurrent.*;
19  
20  /**
21   * An {@link ScheduledExecutorService} with instrumentation for unit testing.
22   * <p>
23   * This service is synchronous; submitted jobs are run on the calling thread.
24   *
25   * @author Carl Harris
26   */
27  public class MockScheduledExecutorService extends AbstractExecutorService {
28  
29  
30      private Runnable lastCommand;
31  
32      public Runnable getLastCommand() {
33          return lastCommand;
34      }
35  
36      public void shutdown() {
37      }
38  
39      public List<Runnable> shutdownNow() {
40          return Collections.emptyList();
41      }
42  
43      public boolean isShutdown() {
44          return true;
45      }
46  
47      public boolean isTerminated() {
48          return true;
49      }
50  
51      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
52          return true;
53      }
54  
55      public void execute(Runnable command) {
56          command.run();
57          lastCommand = command;
58      }
59  
60  }