• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.settings.development;
18 
19 import static junit.framework.Assert.assertFalse;
20 import static junit.framework.Assert.assertTrue;
21 
22 import android.content.Context;
23 import android.os.SystemProperties;
24 
25 import androidx.test.core.app.ApplicationProvider;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.robolectric.RobolectricTestRunner;
33 import org.robolectric.annotation.Config;
34 import org.robolectric.shadows.ShadowSystemProperties;
35 
36 @RunWith(RobolectricTestRunner.class)
37 @Config(
38         shadows = {
39             ShadowSystemProperties.class,
40         })
41 public class RebootWithMtePreferenceControllerTest {
42     private Context mContext;
43     private RebootWithMtePreferenceController mController;
44     @Mock private DevelopmentSettingsDashboardFragment mSettings;
45 
46     @Before
setup()47     public void setup() throws Exception {
48         MockitoAnnotations.initMocks(this);
49 
50         mContext = ApplicationProvider.getApplicationContext();
51         mController = new RebootWithMtePreferenceController(mContext, mSettings);
52     }
53 
54     @Test
onAvailable_falseByDefault()55     public void onAvailable_falseByDefault() {
56         assertFalse(mController.isAvailable());
57     }
58 
59     @Test
onAvailable_sysPropEnabled()60     public void onAvailable_sysPropEnabled() {
61         SystemProperties.set("ro.arm64.memtag.bootctl_supported", "1");
62         assertTrue(mController.isAvailable());
63     }
64 }
65