View Javadoc
1   package org.exoplatform.wiki.jpa.migration.mock;
2   
3   import java.util.Collections;
4   import java.util.List;
5   import java.util.concurrent.AbstractExecutorService;
6   import java.util.concurrent.TimeUnit;
7   
8   /**
9    * Synchronous executor to run the task in the same thread than the caller.
10   * Necessary for unit tests.
11   */
12  public class SynchronousExecutorService extends AbstractExecutorService {
13    private boolean shutdown;
14  
15    @Override
16    public void shutdown() {
17      shutdown = true;
18    }
19  
20    @Override
21    public List<Runnable> shutdownNow() {
22      shutdown = true;
23      return Collections.emptyList();
24    }
25  
26    @Override
27    public boolean isShutdown() {
28      shutdown = true;
29      return shutdown;
30    }
31  
32    @Override
33    public boolean isTerminated() {
34      return shutdown;
35    }
36  
37    @Override
38    public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
39      return true;
40    }
41  
42    @Override
43    public void execute(Runnable command) {
44      command.run();
45    }
46  }