1 /** 2 * Copyright (C) 2018 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 package com.android.settings.wifi; 17 18 import static com.google.common.truth.Truth.assertThat; 19 import static org.mockito.ArgumentMatchers.nullable; 20 import static org.mockito.Matchers.eq; 21 import static org.mockito.Mockito.verify; 22 import static org.mockito.Mockito.when; 23 24 import android.content.Context; 25 26 import com.android.internal.logging.nano.MetricsProto; 27 import com.android.settings.R; 28 import com.android.settings.testutils.FakeFeatureFactory; 29 import com.android.settings.testutils.SettingsRobolectricTestRunner; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.Mock; 35 import org.mockito.MockitoAnnotations; 36 import org.robolectric.RuntimeEnvironment; 37 38 @RunWith(SettingsRobolectricTestRunner.class) 39 public class ChangeWifiStateDetailsTest { 40 41 private static final String PACKAGE_NAME = "app"; 42 private FakeFeatureFactory mFeatureFactory; 43 private ChangeWifiStateDetails mFragment; 44 private Context mContext; 45 46 @Mock 47 private AppStateChangeWifiStateBridge.WifiSettingsState mState; 48 49 @Before setUp()50 public void setUp() { 51 MockitoAnnotations.initMocks(this); 52 53 mContext = RuntimeEnvironment.application; 54 mFeatureFactory = FakeFeatureFactory.setupForTest(); 55 mFragment = new ChangeWifiStateDetails(); 56 } 57 58 @Test testLogSpecialPermissionChange_setTrue_returnAllow()59 public void testLogSpecialPermissionChange_setTrue_returnAllow() { 60 mFragment.logSpecialPermissionChange(true /*newState*/, PACKAGE_NAME); 61 verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class), 62 eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_SETTINGS_CHANGE_ALLOW), 63 eq(PACKAGE_NAME)); 64 } 65 66 @Test testLogSpecialPermissionChange_setFalse_returnDeny()67 public void testLogSpecialPermissionChange_setFalse_returnDeny() { 68 mFragment.logSpecialPermissionChange(false /*newState*/, PACKAGE_NAME); 69 verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class), 70 eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_SETTINGS_CHANGE_DENY), 71 eq(PACKAGE_NAME)); 72 } 73 74 @Test testGetSummary_permissibleTrue_returnAllowed()75 public void testGetSummary_permissibleTrue_returnAllowed() { 76 when(mState.isPermissible()).thenReturn(true); 77 assertThat(ChangeWifiStateDetails.getSummary(mContext, mState)) 78 .isEqualTo(mContext.getString(R.string.app_permission_summary_allowed)); 79 } 80 81 @Test testGetSummary_permissibleFalse_returnNotAllowed()82 public void testGetSummary_permissibleFalse_returnNotAllowed() { 83 when(mState.isPermissible()).thenReturn(false); 84 assertThat(ChangeWifiStateDetails.getSummary(mContext, mState)) 85 .isEqualTo(mContext.getString(R.string.app_permission_summary_not_allowed)); 86 } 87 } 88