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 17package com.android.settings.applications.defaultapps; 18 19 20import static com.google.common.truth.Truth.assertThat; 21import static org.mockito.Mockito.verify; 22import static org.mockito.Mockito.when; 23 24import android.content.ComponentName; 25import android.content.pm.PackageItemInfo; 26import android.content.pm.PackageManager; 27 28import com.android.settings.testutils.SettingsRobolectricTestRunner; 29import com.android.settings.TestConfig; 30import com.android.settings.applications.PackageManagerWrapper; 31 32import org.junit.Before; 33import org.junit.Test; 34import org.junit.runner.RunWith; 35import org.mockito.Mock; 36import org.mockito.MockitoAnnotations; 37import org.robolectric.annotation.Config; 38 39@RunWith(SettingsRobolectricTestRunner.class) 40@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 41public class DefaultAppInfoTest { 42 43 @Mock 44 private PackageItemInfo mPackageItemInfo; 45 @Mock 46 private ComponentName mComponentName; 47 @Mock 48 private PackageManager mPackageManager; 49 @Mock 50 private PackageManagerWrapper mPackageManagerWrapper; 51 52 private DefaultAppInfo mInfo; 53 54 @Before 55 public void setUp() { 56 MockitoAnnotations.initMocks(this); 57 when(mPackageManagerWrapper.getPackageManager()).thenReturn(mPackageManager); 58 } 59 60 @Test 61 public void initInfoWithActivityInfo_shouldLoadInfo() { 62 mPackageItemInfo.packageName = "test"; 63 mInfo = new DefaultAppInfo(mPackageManagerWrapper, mPackageItemInfo); 64 mInfo.loadLabel(); 65 mInfo.loadIcon(); 66 67 assertThat(mInfo.getKey()).isEqualTo(mPackageItemInfo.packageName); 68 verify(mPackageItemInfo).loadLabel(mPackageManager); 69 verify(mPackageItemInfo).loadIcon(mPackageManager); 70 } 71 72 @Test 73 public void initInfoWithComponent_shouldLoadInfo() { 74 when(mComponentName.getPackageName()).thenReturn("com.android.settings"); 75 76 mInfo = new DefaultAppInfo(mPackageManagerWrapper, 0 /* uid */, mComponentName); 77 mInfo.getKey(); 78 79 verify(mComponentName).flattenToString(); 80 } 81} 82