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.Ignore;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.robolectric.RobolectricTestRunner;
32 
33 @RunWith(RobolectricTestRunner.class)
34 @Ignore
35 public class CaCertsCurrentUserPreferenceControllerTest
36     extends CaCertsPreferenceControllerTestBase {
37 
38     private static final String CA_CERT_DEVICE = "CA certs";
39     private static final String CA_CERT_PERSONAL = "CA certs in personal profile";
40 
41     @Before
mockGetString()42     public void mockGetString() {
43         when(mContext.getString(R.string.enterprise_privacy_ca_certs_device))
44                 .thenReturn(CA_CERT_DEVICE);
45         when(mContext.getString(R.string.enterprise_privacy_ca_certs_personal))
46                 .thenReturn(CA_CERT_PERSONAL);
47     }
48 
49     @Test
testUpdateState_nonCompMode()50     public void testUpdateState_nonCompMode() {
51         assertUpdateState(false /* isCompMode */, CA_CERT_DEVICE);
52     }
53 
54     @Test
testUpdateState_compMode()55     public void testUpdateState_compMode() {
56         assertUpdateState(true /* isCompMode */, CA_CERT_PERSONAL);
57     }
58 
59     @Override
mockGetNumberOfCaCerts(int numOfCaCerts)60     void mockGetNumberOfCaCerts(int numOfCaCerts) {
61         when(mFeatureFactory.enterprisePrivacyFeatureProvider
62                 .getNumberOfOwnerInstalledCaCertsForCurrentUser()).thenReturn(numOfCaCerts);
63     }
64 
65     @Override
getPreferenceKey()66     String getPreferenceKey() {
67         return CaCertsCurrentUserPreferenceController.CA_CERTS_CURRENT_USER;
68     }
69 
70     @Override
createController()71     CaCertsPreferenceControllerBase createController() {
72         return new CaCertsCurrentUserPreferenceController(mContext);
73     }
74 
assertUpdateState(boolean isCompMode, String expectedTitle)75     private void assertUpdateState(boolean isCompMode, String expectedTitle) {
76         final Preference preference = new Preference(mContext, null, 0, 0);
77 
78         mockGetNumberOfCaCerts(2);
79         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode())
80                 .thenReturn(isCompMode);
81         mController.updateState(preference);
82         assertThat(preference.getTitle()).isEqualTo(expectedTitle);
83     }
84 }
85