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