1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wm.shell;
18 
19 import com.android.wm.shell.common.ShellExecutor;
20 
21 import java.util.ArrayList;
22 
23 /**
24  * Really basic test executor. It just gathers all events in a blob. The only option is to
25  * execute everything at once. If better control over delayed execution is needed, please add it.
26  */
27 public class TestShellExecutor implements ShellExecutor {
28     final ArrayList<Runnable> mRunnables = new ArrayList<>();
29 
30     @Override
execute(Runnable runnable)31     public void execute(Runnable runnable) {
32         mRunnables.add(runnable);
33     }
34 
35     @Override
executeDelayed(Runnable r, long delayMillis)36     public void executeDelayed(Runnable r, long delayMillis) {
37         mRunnables.add(r);
38     }
39 
40     @Override
removeCallbacks(Runnable r)41     public void removeCallbacks(Runnable r) {
42         mRunnables.remove(r);
43     }
44 
45     @Override
hasCallback(Runnable r)46     public boolean hasCallback(Runnable r) {
47         return mRunnables.contains(r);
48     }
49 
flushAll()50     public void flushAll() {
51         while (!mRunnables.isEmpty()) {
52             mRunnables.remove(0).run();
53         }
54     }
55 }
56