1 /*
2  * Copyright (C) 2021 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.car.settings.qc;
18 
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.ArgumentMatchers.eq;
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.when;
23 
24 import android.app.admin.DevicePolicyManager;
25 import android.content.Context;
26 import android.os.UserManager;
27 
28 import androidx.test.core.app.ApplicationProvider;
29 
30 import org.junit.Before;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 
34 public abstract class BaseSettingsQCItemTestCase {
35     protected final Context mContext = spy(ApplicationProvider.getApplicationContext());
36 
37     @Mock
38     protected UserManager mUm;
39     @Mock
40     protected DevicePolicyManager mDpm;
41 
42     @Before
baseSetUp()43     public final void baseSetUp() throws Exception {
44         MockitoAnnotations.initMocks(this);
45         when(mContext.getSystemService(UserManager.class)).thenReturn(mUm);
46         when(mContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDpm);
47 
48         when(mUm.hasBaseUserRestriction(any(), any())).thenReturn(false);
49         when(mUm.hasUserRestriction(any())).thenReturn(false);
50         when(mDpm.isDeviceManaged()).thenReturn(false);
51     }
52 
setBaseUserRestriction(String restriction, boolean restricted)53     protected void setBaseUserRestriction(String restriction, boolean restricted) {
54         when(mUm.hasBaseUserRestriction(eq(restriction), any())).thenReturn(restricted);
55         when(mContext.getSystemService(UserManager.class)).thenReturn(mUm);
56     }
57 
setUserRestriction(String restriction, boolean restricted)58     protected void setUserRestriction(String restriction, boolean restricted) {
59         when(mUm.hasUserRestriction(restriction)).thenReturn(restricted);
60         when(mContext.getSystemService(UserManager.class)).thenReturn(mUm);
61     }
62 }
63