blob: e0ca87c0223d01ec74e6306437e36838a828e159 [file] [log] [blame]
Evan Laird03234502018-10-24 12:47:14 -04001/*
2 * Copyright (C) 2018 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
17package com.android.systemui;
18
19import static junit.framework.TestCase.assertFalse;
20import static junit.framework.TestCase.assertTrue;
21
Evan Laird03234502018-10-24 12:47:14 -040022import android.testing.AndroidTestingRunner;
23import android.testing.TestableLooper;
24
Brett Chabot84151d92019-02-27 15:37:59 -080025import androidx.test.filters.SmallTest;
26
Evan Laird03234502018-10-24 12:47:14 -040027import org.junit.Test;
28import org.junit.runner.RunWith;
29
30@SmallTest
31@RunWith(AndroidTestingRunner.class)
32@TestableLooper.RunWithLooper
33public class InitControllerTest extends SysuiTestCase {
34
35 private InitController mInitController = new InitController();
36
37 @Test
38 public void testInitControllerExecutesTasks() {
39 boolean[] runs = {false, false, false};
40 mInitController.addPostInitTask(() -> {
41 runs[0] = true;
42 });
43 mInitController.addPostInitTask(() -> {
44 runs[1] = true;
45 });
46 mInitController.addPostInitTask(() -> {
47 runs[2] = true;
48 });
49 assertFalse(runs[0] || runs[1] || runs[2]);
50
51 mInitController.executePostInitTasks();
52 assertTrue(runs[0] && runs[1] && runs[2]);
53 }
54
55 @Test(expected = IllegalStateException.class)
56 public void testInitControllerThrowsWhenTasksAreAddedAfterExecution() {
57 boolean[] runs = {false, false, false};
58 mInitController.addPostInitTask(() -> {
59 runs[0] = true;
60 });
61 mInitController.addPostInitTask(() -> {
62 runs[1] = true;
63 });
64
65 mInitController.executePostInitTasks();
66
67 // Throws
68 mInitController.addPostInitTask(() -> {
69 runs[2] = true;
70 });
71 }
72}