• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.systemui;
18 
19 import static junit.framework.TestCase.assertFalse;
20 import static junit.framework.TestCase.assertTrue;
21 
22 import android.testing.AndroidTestingRunner;
23 import android.testing.TestableLooper;
24 
25 import androidx.test.filters.SmallTest;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 @SmallTest
31 @RunWith(AndroidTestingRunner.class)
32 @TestableLooper.RunWithLooper
33 public class InitControllerTest extends SysuiTestCase {
34 
35     private InitController mInitController = new InitController();
36 
37     @Test
testInitControllerExecutesTasks()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)
testInitControllerThrowsWhenTasksAreAddedAfterExecution()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 }
73