1 /* 2 * Copyright (C) 2020 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.security; 18 19 import static android.app.settings.SettingsEnums.CREDENTIAL_MANAGEMENT_APP; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import static org.mockito.Mockito.doReturn; 24 import static org.mockito.Mockito.spy; 25 26 import android.content.Context; 27 import android.provider.SearchIndexableResource; 28 29 import com.android.settings.R; 30 import com.android.settings.testutils.shadow.ShadowDashboardFragment; 31 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.MockitoAnnotations; 36 import org.robolectric.RobolectricTestRunner; 37 import org.robolectric.RuntimeEnvironment; 38 import org.robolectric.annotation.Config; 39 40 import java.util.List; 41 42 @RunWith(RobolectricTestRunner.class) 43 @Config(shadows = ShadowDashboardFragment.class) 44 public class CredentialManagementAppFragmentTest { 45 46 private CredentialManagementAppFragment mFragment; 47 private Context mContext; 48 49 @Before setUp()50 public void setUp() throws Exception { 51 MockitoAnnotations.initMocks(this); 52 mContext = spy(RuntimeEnvironment.application); 53 mFragment = spy(new CredentialManagementAppFragment()); 54 55 doReturn(mContext).when(mFragment).getContext(); 56 } 57 58 @Test searchIndexProvider_shouldIndexResource()59 public void searchIndexProvider_shouldIndexResource() { 60 final List<SearchIndexableResource> indexRes = 61 CredentialManagementAppFragment.SEARCH_INDEX_DATA_PROVIDER 62 .getXmlResourcesToIndex(mContext, true /* enabled */); 63 64 assertThat(indexRes).isNotNull(); 65 assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.credential_management_app_fragment); 66 } 67 68 @Test getMetricsCategory_shouldReturnInstallCertificateFromStorage()69 public void getMetricsCategory_shouldReturnInstallCertificateFromStorage() { 70 assertThat(mFragment.getMetricsCategory()).isEqualTo(CREDENTIAL_MANAGEMENT_APP); 71 } 72 } 73