• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package com.android.settings.wifi;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.never;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24 
25 import android.content.Context;
26 import android.view.View;
27 
28 import com.android.settings.R;
29 import com.android.wifitrackerlib.WifiEntry;
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.RobolectricTestRunner;
37 import org.robolectric.RuntimeEnvironment;
38 
39 @RunWith(RobolectricTestRunner.class)
40 public class ConnectedWifiEntryPreferenceTest {
41 
42     @Mock
43     private WifiEntry mWifiEntry;
44     @Mock
45     private View mView;
46     @Mock
47     private ConnectedWifiEntryPreference.OnGearClickListener mOnGearClickListener;
48     private Context mContext;
49     private ConnectedWifiEntryPreference mConnectedWifiEntryPreference;
50 
51     @Before
setUp()52     public void setUp() {
53         MockitoAnnotations.initMocks(this);
54 
55         mContext = RuntimeEnvironment.application;
56         mConnectedWifiEntryPreference = new ConnectedWifiEntryPreference(mContext, mWifiEntry,
57                 null /* fragment */);
58         mConnectedWifiEntryPreference.setOnGearClickListener(mOnGearClickListener);
59     }
60 
61     @Test
testOnClick_gearClicked_listenerInvoked()62     public void testOnClick_gearClicked_listenerInvoked() {
63         when(mView.getId()).thenReturn(R.id.settings_button);
64 
65         mConnectedWifiEntryPreference.onClick(mView);
66 
67         verify(mOnGearClickListener).onGearClick(mConnectedWifiEntryPreference);
68     }
69 
70     @Test
testOnClick_gearNotClicked_listenerNotInvoked()71     public void testOnClick_gearNotClicked_listenerNotInvoked() {
72         mConnectedWifiEntryPreference.onClick(mView);
73 
74         verify(mOnGearClickListener, never()).onGearClick(mConnectedWifiEntryPreference);
75     }
76 
77     @Test
testWidgetLayoutPreference()78     public void testWidgetLayoutPreference() {
79         assertThat(mConnectedWifiEntryPreference.getWidgetLayoutResource())
80             .isEqualTo(R.layout.preference_widget_gear_optional_background);
81     }
82 }
83