• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 import static org.mockito.Mockito.mock;
21 
22 import android.Manifest;
23 import android.content.pm.PackageInfo;
24 
25 import com.android.settingslib.applications.ApplicationsState.AppEntry;
26 import com.android.settingslib.applications.ApplicationsState.AppFilter;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.robolectric.RobolectricTestRunner;
34 
35 @RunWith(RobolectricTestRunner.class)
36 public class AppStateChangeWifiStateBridgeTest {
37 
38     @Mock
39     private AppEntry mEntry;
40     @Mock
41     private AppStateChangeWifiStateBridge.WifiSettingsState mState;
42     private AppFilter mFilter;
43 
44     @Before
setUp()45     public void setUp() {
46         MockitoAnnotations.initMocks(this);
47         mFilter = AppStateChangeWifiStateBridge.FILTER_CHANGE_WIFI_STATE;
48     }
49 
50     @Test
testFilterApp_inputNull_returnFalse()51     public void testFilterApp_inputNull_returnFalse() {
52         assertThat(mFilter.filterApp(null)).isFalse();
53     }
54 
55     @Test
testFilterApp_extraInfoNull_returnFalse()56     public void testFilterApp_extraInfoNull_returnFalse() {
57         mEntry.extraInfo = null;
58         assertThat(mFilter.filterApp(mEntry)).isFalse();
59     }
60 
61     @Test
testFilterApp_permissionedDeclaredTrue_returnTrue()62     public void testFilterApp_permissionedDeclaredTrue_returnTrue() {
63         mState.permissionDeclared = true;
64         mEntry.extraInfo = mState;
65         assertThat(mFilter.filterApp(mEntry)).isTrue();
66     }
67 
68     @Test
testFilterApp_permissionedDeclaredFalse_returnFalse()69     public void testFilterApp_permissionedDeclaredFalse_returnFalse() {
70         mState.permissionDeclared = false;
71         mEntry.extraInfo = mState;
72         assertThat(mFilter.filterApp(mEntry)).isFalse();
73     }
74 
75     @Test
testFilterApp_networkSettingsGranted_returnFalse()76     public void testFilterApp_networkSettingsGranted_returnFalse() {
77         mState.permissionDeclared = true;
78         mState.packageInfo = mock(PackageInfo.class);
79         mState.packageInfo.requestedPermissions
80                 = new String[] { Manifest.permission.NETWORK_SETTINGS };
81         mEntry.extraInfo = mState;
82         assertThat(mFilter.filterApp(mEntry)).isFalse();
83     }
84 }
85