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.Collections;
017import java.util.List;
018import java.util.concurrent.AbstractExecutorService;
019import java.util.concurrent.Callable;
020import java.util.concurrent.ScheduledExecutorService;
021import java.util.concurrent.ScheduledFuture;
022import java.util.concurrent.TimeUnit;
023
024/**
025 * An {@link ScheduledExecutorService} with instrumentation for unit testing.
026 * <p>
027 * This service is synchronous; submitted jobs are run on the calling thread.
028 *
029 * @author Carl Harris
030 */
031public class MockScheduledExecutorService extends AbstractExecutorService implements ScheduledExecutorService {
032
033    private Runnable lastCommand;
034
035    public Runnable getLastCommand() {
036        return lastCommand;
037    }
038
039    public void shutdown() {
040    }
041
042    public List<Runnable> shutdownNow() {
043        return Collections.emptyList();
044    }
045
046    public boolean isShutdown() {
047        return true;
048    }
049
050    public boolean isTerminated() {
051        return true;
052    }
053
054    public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
055        return true;
056    }
057
058    public void execute(Runnable command) {
059        command.run();
060        lastCommand = command;
061    }
062
063    @Override
064    public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
065        throw new UnsupportedOperationException();
066    }
067
068    @Override
069    public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
070        throw new UnsupportedOperationException();
071    }
072
073    @Override
074    public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
075        throw new UnsupportedOperationException();
076    }
077
078    @Override
079    public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
080        throw new UnsupportedOperationException();
081    }
082
083}