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