• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.enterprise;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.when;
22 
23 import androidx.preference.Preference;
24 
25 import com.android.settings.R;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.robolectric.RobolectricTestRunner;
31 
32 @RunWith(RobolectricTestRunner.class)
33 public class CaCertsCurrentUserPreferenceControllerTest
34     extends CaCertsPreferenceControllerTestBase {
35 
36     private static final String CA_CERT_DEVICE = "CA certs";
37     private static final String CA_CERT_PERSONAL = "CA certs in personal profile";
38 
39     @Before
mockGetString()40     public void mockGetString() {
41         when(mContext.getString(R.string.enterprise_privacy_ca_certs_device))
42                 .thenReturn(CA_CERT_DEVICE);
43         when(mContext.getString(R.string.enterprise_privacy_ca_certs_personal))
44                 .thenReturn(CA_CERT_PERSONAL);
45     }
46 
47     @Test
testUpdateState_nonCompMode()48     public void testUpdateState_nonCompMode() {
49         assertUpdateState(false /* isCompMode */, CA_CERT_DEVICE);
50     }
51 
52     @Test
testUpdateState_compMode()53     public void testUpdateState_compMode() {
54         assertUpdateState(true /* isCompMode */, CA_CERT_PERSONAL);
55     }
56 
57     @Override
mockGetNumberOfCaCerts(int numOfCaCerts)58     void mockGetNumberOfCaCerts(int numOfCaCerts) {
59         when(mFeatureFactory.enterprisePrivacyFeatureProvider
60                 .getNumberOfOwnerInstalledCaCertsForCurrentUser()).thenReturn(numOfCaCerts);
61     }
62 
63     @Override
getPreferenceKey()64     String getPreferenceKey() {
65         return CaCertsCurrentUserPreferenceController.CA_CERTS_CURRENT_USER;
66     }
67 
68     @Override
createController()69     CaCertsPreferenceControllerBase createController() {
70         return new CaCertsCurrentUserPreferenceController(mContext);
71     }
72 
assertUpdateState(boolean isCompMode, String expectedTitle)73     private void assertUpdateState(boolean isCompMode, String expectedTitle) {
74         final Preference preference = new Preference(mContext, null, 0, 0);
75 
76         mockGetNumberOfCaCerts(2);
77         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode())
78                 .thenReturn(isCompMode);
79         mController.updateState(preference);
80         assertThat(preference.getTitle()).isEqualTo(expectedTitle);
81     }
82 }
83