Sundeep Ghuman | 7c32aa3 | 2017-06-26 17:13:00 -0700 | [diff] [blame] | 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 | package com.android.settingslib.wifi; |
| 17 | |
| 18 | import static com.google.common.truth.Truth.assertThat; |
Fan Zhang | 60b850d | 2017-07-18 15:59:06 -0700 | [diff] [blame] | 19 | import static org.mockito.Mockito.mock; |
| 20 | import static org.mockito.Mockito.when; |
Sundeep Ghuman | 7c32aa3 | 2017-06-26 17:13:00 -0700 | [diff] [blame] | 21 | |
| 22 | import android.content.Context; |
| 23 | |
| 24 | import com.android.settingslib.SettingLibRobolectricTestRunner; |
| 25 | import com.android.settingslib.TestConfig; |
| 26 | |
| 27 | import org.junit.Test; |
| 28 | import org.junit.runner.RunWith; |
| 29 | import org.robolectric.RuntimeEnvironment; |
| 30 | import org.robolectric.annotation.Config; |
| 31 | |
| 32 | @RunWith(SettingLibRobolectricTestRunner.class) |
| 33 | @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) |
| 34 | public class AccessPointPreferenceTest { |
| 35 | |
| 36 | private Context mContext = RuntimeEnvironment.application; |
| 37 | |
| 38 | @Test |
| 39 | public void generatePreferenceKey_shouldReturnSsidPlusSecurity() { |
| 40 | String ssid = "ssid"; |
| 41 | int security = AccessPoint.SECURITY_WEP; |
| 42 | String expectedKey = ssid + ',' + security; |
| 43 | |
| 44 | TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext); |
| 45 | builder.setSsid(ssid).setSecurity(security); |
| 46 | |
| 47 | assertThat(AccessPointPreference.generatePreferenceKey(builder.build())) |
| 48 | .isEqualTo(expectedKey); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void generatePreferenceKey_shouldReturnBssidPlusSecurity() { |
| 53 | String bssid = "bssid"; |
| 54 | int security = AccessPoint.SECURITY_WEP; |
| 55 | String expectedKey = bssid + ',' + security; |
| 56 | |
| 57 | TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext); |
| 58 | builder.setBssid(bssid).setSecurity(security); |
| 59 | |
| 60 | assertThat(AccessPointPreference.generatePreferenceKey(builder.build())) |
| 61 | .isEqualTo(expectedKey); |
| 62 | } |
Fan Zhang | 60b850d | 2017-07-18 15:59:06 -0700 | [diff] [blame] | 63 | |
| 64 | @Test |
| 65 | public void refresh_openNetwork_updateContentDescription() { |
| 66 | final String ssid = "ssid"; |
| 67 | final String summary = "connected"; |
| 68 | final int security = AccessPoint.SECURITY_WEP; |
| 69 | final AccessPoint ap = new TestAccessPointBuilder(mContext) |
| 70 | .setSsid(ssid) |
| 71 | .setSecurity(security) |
| 72 | .build(); |
| 73 | final AccessPointPreference pref = mock(AccessPointPreference.class); |
| 74 | when(pref.getTitle()).thenReturn(ssid); |
| 75 | when(pref.getSummary()).thenReturn(summary); |
| 76 | |
| 77 | assertThat(AccessPointPreference.buildContentDescription( |
| 78 | RuntimeEnvironment.application, pref, ap)) |
| 79 | .isEqualTo("ssid,connected,Wifi signal full.,Secure network"); |
| 80 | } |
Sundeep Ghuman | 7c32aa3 | 2017-06-26 17:13:00 -0700 | [diff] [blame] | 81 | } |