blob: 4d33d437ff79f2d6cd39ef6425c547c68c873839 [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
22import android.support.test.filters.SmallTest;
23import android.testing.AndroidTestingRunner;
24import android.testing.TestableLooper;
25
26import org.junit.Test;
27import org.junit.runner.RunWith;
28
29@SmallTest
30@RunWith(AndroidTestingRunner.class)
31@TestableLooper.RunWithLooper
32public class InitControllerTest extends SysuiTestCase {
33
34 private InitController mInitController = new InitController();
35
36 @Test
37 public void testInitControllerExecutesTasks() {
38 boolean[] runs = {false, false, false};
39 mInitController.addPostInitTask(() -> {
40 runs[0] = true;
41 });
42 mInitController.addPostInitTask(() -> {
43 runs[1] = true;
44 });
45 mInitController.addPostInitTask(() -> {
46 runs[2] = true;
47 });
48 assertFalse(runs[0] || runs[1] || runs[2]);
49
50 mInitController.executePostInitTasks();
51 assertTrue(runs[0] && runs[1] && runs[2]);
52 }
53
54 @Test(expected = IllegalStateException.class)
55 public void testInitControllerThrowsWhenTasksAreAddedAfterExecution() {
56 boolean[] runs = {false, false, false};
57 mInitController.addPostInitTask(() -> {
58 runs[0] = true;
59 });
60 mInitController.addPostInitTask(() -> {
61 runs[1] = true;
62 });
63
64 mInitController.executePostInitTasks();
65
66 // Throws
67 mInitController.addPostInitTask(() -> {
68 runs[2] = true;
69 });
70 }
71}