1 /*
2  * Copyright (C) 2023 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.globalactions;
18 
19 import static junit.framework.Assert.assertEquals;
20 import static junit.framework.Assert.assertNull;
21 
22 import android.os.PowerManager;
23 import android.testing.AndroidTestingRunner;
24 
25 import androidx.test.filters.SmallTest;
26 
27 import com.android.internal.R;
28 import com.android.systemui.SysuiTestCase;
29 import com.android.systemui.statusbar.BlurUtils;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 
36 
37 @SmallTest
38 @RunWith(AndroidTestingRunner.class)
39 public class ShutdownUiTest extends SysuiTestCase {
40 
41     ShutdownUi mShutdownUi;
42     @Mock
43     BlurUtils mBlurUtils;
44 
45     @Before
setUp()46     public void setUp() throws Exception {
47         mShutdownUi = new ShutdownUi(getContext(), mBlurUtils);
48     }
49 
50     @Test
getRebootMessage_update()51     public void getRebootMessage_update() {
52         int messageId = mShutdownUi.getRebootMessage(true, PowerManager.REBOOT_RECOVERY_UPDATE);
53         assertEquals(messageId, R.string.reboot_to_update_reboot);
54     }
55 
56     @Test
getRebootMessage_rebootDefault()57     public void getRebootMessage_rebootDefault() {
58         int messageId = mShutdownUi.getRebootMessage(true, "anything-else");
59         assertEquals(messageId, R.string.reboot_to_reset_message);
60     }
61 
62     @Test
getRebootMessage_shutdown()63     public void getRebootMessage_shutdown() {
64         int messageId = mShutdownUi.getRebootMessage(false, "anything-else");
65         assertEquals(messageId, R.string.shutdown_progress);
66     }
67 
68     @Test
getReasonMessage_update()69     public void getReasonMessage_update() {
70         String message = mShutdownUi.getReasonMessage(PowerManager.REBOOT_RECOVERY_UPDATE);
71         assertEquals(message, mContext.getString(R.string.reboot_to_update_title));
72     }
73 
74     @Test
getReasonMessage_rebootDefault()75     public void getReasonMessage_rebootDefault() {
76         String message = mShutdownUi.getReasonMessage(PowerManager.REBOOT_RECOVERY);
77         assertEquals(message, mContext.getString(R.string.reboot_to_reset_title));
78     }
79 
80     @Test
getRebootMessage_defaultToNone()81     public void getRebootMessage_defaultToNone() {
82         String message = mShutdownUi.getReasonMessage("anything-else");
83         assertNull(message);
84     }
85 }
86