| :
* Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.applications.specialaccess.notificationaccess; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.NotificationManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.UserHandle; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; @RunWith(SettingsRobolectricTestRunner.class) public class NotificationAccessPreferenceControllerTest { private static final String TEST_PACKAGE_NAME = "test.package.name"; @Mock private PackageManager mPackageManager; @Mock private NotificationManager mNotificationManager; @Mock private ApplicationInfo mApplicationInfo; private Context mContext; private NotificationAccessPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn( mNotificationManager); mController = new NotificationAccessPreferenceController(mContext, TEST_PACKAGE_NAME); } @Test public void isChecked_notificationAccessGranted_shouldReturnTrue() { when(mNotificationManager.isNotificationPolicyAccessGrantedForPackage(TEST_PACKAGE_NAME)) .thenReturn(true); assertThat(mController.isChecked()).isTrue(); } @Test public void isChecked_notificationAccessNotGranted_shouldReturnFalse() { when(mNotificationManager.isNotificationPolicyAccessGrantedForPackage(TEST_PACKAGE_NAME)) .thenReturn(false); assertThat(mController.isChecked()).isFalse(); } @Test public void setChecked_grantNotificationAccess_shouldCallSetNotificationPolicyAccess() { mController.setChecked(true); verify(mNotificationManager).setNotificationPolicyAccessGranted(TEST_PACKAGE_NAME, true); } @Test public void setChecked_revokeNotificationAccess_shouldCallSetNotificationPolicyAccess() { mController.setChecked(false); verify(mNotificationManager).setNotificationPolicyAccessGranted(TEST_PACKAGE_NAME, false); } @Test public void getSummary_notificationAccessGranted_shouldReturnOn() { when(mNotificationManager.isNotificationPolicyAccessGrantedForPackage(TEST_PACKAGE_NAME)) .thenReturn(true); assertThat(mController.getSummary()).isEqualTo( mContext.getString(R.string.app_permission_summary_allowed)); } @Test public void getSummary_notificationAccessNotGranted_shouldReturnOff() { when(mNotificationManager.isNotificationPolicyAccessGrantedForPackage(TEST_PACKAGE_NAME)) .thenReturn(false); assertThat(mController.getSummary()).isEqualTo( mContext.getString(R.string.app_permission_summary_not_allowed)); } @Test public void getApplicationLabel_shouldReturnApplicationLabel() { final CharSequence label = "Test Label"; when(mPackageManager.getApplicationLabel(mApplicationInfo)).thenReturn(label); when(mPackageManager.getApplicationInfoAsUser(TEST_PACKAGE_NAME, 0, UserHandle.myUserId())).thenReturn(mApplicationInfo); assertThat(mController.getApplicationLabel()).isEqualTo(label); } }
ǸҳܰȨ۳ʱ踶ѹ
˴
ɨ븶Ѽɸ
SFNDLSCHSWITCH | NB的频段 | drop cable | 皮线光缆 | 光缆 | 马氏距离 | 千兆 | 兼容的 | 百兆 | 百兆: 千兆: 万兆: 兼容的 | fast connector | KML制作 |