blob: 21aa526d758143f152334bce142a545356f7aea7 [file] [log] [blame]
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -07001/*
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 */
16package com.android.settingslib.wifi;
17
18import static com.google.common.truth.Truth.assertThat;
Fan Zhangf7802ea2018-08-28 15:15:19 -070019
Eric Schwarzenbach6efd09a2017-08-22 10:33:00 -070020import static org.mockito.ArgumentMatchers.anyInt;
Fan Zhang60b850d2017-07-18 15:59:06 -070021import static org.mockito.Mockito.mock;
Eric Schwarzenbach6efd09a2017-08-22 10:33:00 -070022import static org.mockito.Mockito.verify;
Fan Zhangb6cec0d2017-09-05 11:02:03 -070023import static org.mockito.Mockito.when;
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -070024
25import android.content.Context;
Eric Schwarzenbach6efd09a2017-08-22 10:33:00 -070026import android.graphics.drawable.ColorDrawable;
Fan Zhangb6cec0d2017-09-05 11:02:03 -070027
Eric Schwarzenbach6efd09a2017-08-22 10:33:00 -070028import org.junit.Before;
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -070029import org.junit.Test;
30import org.junit.runner.RunWith;
Eric Schwarzenbach6efd09a2017-08-22 10:33:00 -070031import org.mockito.Mock;
32import org.mockito.MockitoAnnotations;
James Lemieuxec3ad9e2018-11-28 17:49:14 -080033import org.robolectric.RobolectricTestRunner;
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -070034import org.robolectric.RuntimeEnvironment;
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -070035
James Lemieuxec3ad9e2018-11-28 17:49:14 -080036@RunWith(RobolectricTestRunner.class)
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -070037public class AccessPointPreferenceTest {
38
39 private Context mContext = RuntimeEnvironment.application;
40
Fan Zhangb6cec0d2017-09-05 11:02:03 -070041 @Mock
42 private AccessPoint mockAccessPoint;
43 @Mock
44 private AccessPointPreference.UserBadgeCache mockUserBadgeCache;
45 @Mock
46 private AccessPointPreference.IconInjector mockIconInjector;
Eric Schwarzenbach6efd09a2017-08-22 10:33:00 -070047
48 private AccessPointPreference createWithAccessPoint(AccessPoint accessPoint) {
49 return new AccessPointPreference(accessPoint, mContext, mockUserBadgeCache,
50 0, true, null, -1, mockIconInjector);
51 }
52
53 @Before
54 public void setUp() {
55 MockitoAnnotations.initMocks(this);
56
57 when(mockIconInjector.getIcon(anyInt())).thenReturn(new ColorDrawable());
58 }
59
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -070060 @Test
Fan Zhang60b850d2017-07-18 15:59:06 -070061 public void refresh_openNetwork_updateContentDescription() {
62 final String ssid = "ssid";
63 final String summary = "connected";
64 final int security = AccessPoint.SECURITY_WEP;
65 final AccessPoint ap = new TestAccessPointBuilder(mContext)
66 .setSsid(ssid)
67 .setSecurity(security)
68 .build();
69 final AccessPointPreference pref = mock(AccessPointPreference.class);
70 when(pref.getTitle()).thenReturn(ssid);
71 when(pref.getSummary()).thenReturn(summary);
72
73 assertThat(AccessPointPreference.buildContentDescription(
74 RuntimeEnvironment.application, pref, ap))
75 .isEqualTo("ssid,connected,Wifi signal full.,Secure network");
76 }
Eric Schwarzenbach6efd09a2017-08-22 10:33:00 -070077
78 @Test
79 public void refresh_shouldUpdateIcon() {
80 int level = 1;
81 when(mockAccessPoint.getSpeed()).thenReturn(0);
82 when(mockAccessPoint.getLevel()).thenReturn(level);
83
84 AccessPointPreference pref = createWithAccessPoint(mockAccessPoint);
85 pref.refresh();
86
87 verify(mockIconInjector).getIcon(level);
88 }
Fan Zhangb6cec0d2017-09-05 11:02:03 -070089
90 @Test
91 public void refresh_setTitle_shouldUseSsidString() {
92 final String ssid = "ssid";
93 final String summary = "connected";
94 final int security = AccessPoint.SECURITY_WEP;
95 final AccessPoint ap = new TestAccessPointBuilder(mContext)
96 .setSsid(ssid)
97 .setSecurity(security)
98 .build();
99 final AccessPointPreference preference = mock(AccessPointPreference.class);
100
Quang Luong19429e42019-02-20 17:10:51 -0800101 AccessPointPreference.setTitle(preference, ap);
Fan Zhangb6cec0d2017-09-05 11:02:03 -0700102 verify(preference).setTitle(ssid);
103 }
Sundeep Ghuman7c32aa32017-06-26 17:13:00 -0700104}