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.AbstractExecutorService;
19  import java.util.concurrent.Callable;
20  import java.util.concurrent.ScheduledExecutorService;
21  import java.util.concurrent.ScheduledFuture;
22  import java.util.concurrent.TimeUnit;
23  
24  /**
25   * An {@link ScheduledExecutorService} with instrumentation for unit testing.
26   * <p>
27   * This service is synchronous; submitted jobs are run on the calling thread.
28   *
29   * @author Carl Harris
30   */
31  public class MockScheduledExecutorService extends AbstractExecutorService implements ScheduledExecutorService {
32  
33      private Runnable lastCommand;
34  
35      public Runnable getLastCommand() {
36          return lastCommand;
37      }
38  
39      public void shutdown() {
40      }
41  
42      public List<Runnable> shutdownNow() {
43          return Collections.emptyList();
44      }
45  
46      public boolean isShutdown() {
47          return true;
48      }
49  
50      public boolean isTerminated() {
51          return true;
52      }
53  
54      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
55          return true;
56      }
57  
58      public void execute(Runnable command) {
59          command.run();
60          lastCommand = command;
61      }
62  
63      @Override
64      public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
65          throw new UnsupportedOperationException();
66      }
67  
68      @Override
69      public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
70          throw new UnsupportedOperationException();
71      }
72  
73      @Override
74      public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
75          throw new UnsupportedOperationException();
76      }
77  
78      @Override
79      public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
80          throw new UnsupportedOperationException();
81      }
82  
83  }