1 /*
2  * Copyright (C) 2019 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 android.content.Context;
22 
23 import com.android.settings.R;
24 import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
25 import com.android.settings.wifi.WifiDialog2.WifiDialog2Listener;
26 import com.android.wifitrackerlib.WifiEntry;
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 import org.robolectric.RuntimeEnvironment;
35 import org.robolectric.annotation.Config;
36 
37 @RunWith(RobolectricTestRunner.class)
38 @Config(shadows = ShadowEntityHeaderController.class)
39 public class WifiDialog2Test {
40     @Mock private WifiEntry mMockWifiEntry;
41 
42     private Context mContext = RuntimeEnvironment.application;
43 
44     private WifiDialog2Listener mListener = new WifiDialog2Listener() {};
45 
46     @Before
setUp()47     public void setUp() {
48         MockitoAnnotations.initMocks(this);
49     }
50 
51     @Test
createModal_usesDefaultTheme()52     public void createModal_usesDefaultTheme() {
53         WifiDialog2 modal = WifiDialog2
54                 .createModal(mContext, mListener, mMockWifiEntry, WifiConfigUiBase2.MODE_CONNECT);
55 
56         WifiDialog2 wifiDialog2 = new WifiDialog2(mContext, mListener, mMockWifiEntry,
57                 WifiConfigUiBase2.MODE_CONNECT, 0 /* style */, false /* hideSubmitButton */);
58         assertThat(modal.getContext().getThemeResId())
59                 .isEqualTo(wifiDialog2.getContext().getThemeResId());
60     }
61 
62     @Test
createModal_whenSetTheme_shouldBeCustomizedTheme()63     public void createModal_whenSetTheme_shouldBeCustomizedTheme() {
64         WifiDialog2 modal = WifiDialog2.createModal(mContext, mListener, mMockWifiEntry,
65                 WifiConfigUiBase2.MODE_CONNECT, R.style.SuwAlertDialogThemeCompat_Light);
66 
67         WifiDialog2 wifiDialog2 = new WifiDialog2(mContext, mListener, mMockWifiEntry,
68                 WifiConfigUiBase2.MODE_CONNECT, R.style.SuwAlertDialogThemeCompat_Light,
69                         false /* hideSubmitButton */);
70         assertThat(modal.getContext().getThemeResId())
71                 .isEqualTo(wifiDialog2.getContext().getThemeResId());
72     }
73 }
74