• 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.development;
18 
19 import static org.mockito.Mockito.doReturn;
20 import static org.mockito.Mockito.spy;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23 
24 import android.support.v7.preference.Preference;
25 import android.support.v7.preference.PreferenceScreen;
26 
27 import com.android.settings.R;
28 import com.android.settings.testutils.SettingsRobolectricTestRunner;
29 import com.android.settings.webview.WebViewUpdateServiceWrapper;
30 import com.android.settingslib.applications.DefaultAppInfo;
31 import com.android.settingslib.wrapper.PackageManagerWrapper;
32 
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.robolectric.RuntimeEnvironment;
39 import org.robolectric.util.ReflectionHelpers;
40 
41 @RunWith(SettingsRobolectricTestRunner.class)
42 public class WebViewAppPreferenceControllerTest {
43 
44     @Mock
45     private PreferenceScreen mPreferenceScreen;
46     @Mock
47     private PackageManagerWrapper mPackageManager;
48     @Mock
49     private WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
50     @Mock
51     private Preference mPreference;
52     @Mock
53     private DefaultAppInfo mAppInfo;
54 
55     private WebViewAppPreferenceController mController;
56 
57     @Before
setup()58     public void setup() {
59         MockitoAnnotations.initMocks(this);
60         mController = spy(new WebViewAppPreferenceController(RuntimeEnvironment.application));
61         ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
62         ReflectionHelpers
63             .setField(mController, "mWebViewUpdateServiceWrapper", mWebViewUpdateServiceWrapper);
64         doReturn(mAppInfo).when(mController).getDefaultAppInfo();
65         when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
66             .thenReturn(mPreference);
67         mController.displayPreference(mPreferenceScreen);
68     }
69 
70     @Test
updateState_hasAppLabel_shouldSetAppLabelAndIcon()71     public void updateState_hasAppLabel_shouldSetAppLabelAndIcon() {
72         when(mAppInfo.loadLabel()).thenReturn("SomeRandomAppLabel!!!");
73 
74         mController.updateState(mPreference);
75 
76         verify(mPreference).setSummary("SomeRandomAppLabel!!!");
77     }
78 
79     @Test
updateState_noAppLabel_shouldSetAppDefaultLabelAndNullIcon()80     public void updateState_noAppLabel_shouldSetAppDefaultLabelAndNullIcon() {
81         when(mAppInfo.loadLabel()).thenReturn(null);
82 
83         mController.updateState(mPreference);
84 
85         verify(mPreference).setSummary(R.string.app_list_preference_none);
86     }
87 }
88