Merge "Migrate WifiDialog2 to Kotlin" into main
This commit is contained in:
@@ -482,8 +482,8 @@ public class NetworkProviderSettingsTest {
|
||||
when(mWifiEntry.canConnect()).thenReturn(true);
|
||||
final WifiConfigController2 controller = mock(WifiConfigController2.class);
|
||||
when(controller.getConfig()).thenReturn(config);
|
||||
final WifiDialog2 wifiDialog2 = spy(WifiDialog2.createModal(mContext, null /* listener */,
|
||||
mWifiEntry, mode));
|
||||
WifiDialog2.WifiDialog2Listener listener = mock(WifiDialog2.WifiDialog2Listener.class);
|
||||
final WifiDialog2 wifiDialog2 = spy(new WifiDialog2(mContext, listener, mWifiEntry, mode));
|
||||
when(wifiDialog2.getController()).thenReturn(controller);
|
||||
return wifiDialog2;
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.wifi.WifiDialog2.WifiDialog2Listener;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowEntityHeaderController.class)
|
||||
public class WifiDialog2Test {
|
||||
@Mock private WifiEntry mMockWifiEntry;
|
||||
|
||||
private Context mContext = RuntimeEnvironment.application;
|
||||
|
||||
private WifiDialog2Listener mListener = new WifiDialog2Listener() {};
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createModal_usesDefaultTheme() {
|
||||
WifiDialog2 modal = WifiDialog2
|
||||
.createModal(mContext, mListener, mMockWifiEntry, WifiConfigUiBase2.MODE_CONNECT);
|
||||
|
||||
WifiDialog2 wifiDialog2 = new WifiDialog2(mContext, mListener, mMockWifiEntry,
|
||||
WifiConfigUiBase2.MODE_CONNECT, 0 /* style */, false /* hideSubmitButton */);
|
||||
assertThat(modal.getContext().getThemeResId())
|
||||
.isEqualTo(wifiDialog2.getContext().getThemeResId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createModal_whenSetTheme_shouldBeCustomizedTheme() {
|
||||
WifiDialog2 modal = WifiDialog2.createModal(mContext, mListener, mMockWifiEntry,
|
||||
WifiConfigUiBase2.MODE_CONNECT, R.style.SuwAlertDialogThemeCompat_Light);
|
||||
|
||||
WifiDialog2 wifiDialog2 = new WifiDialog2(mContext, mListener, mMockWifiEntry,
|
||||
WifiConfigUiBase2.MODE_CONNECT, R.style.SuwAlertDialogThemeCompat_Light,
|
||||
false /* hideSubmitButton */);
|
||||
assertThat(modal.getContext().getThemeResId())
|
||||
.isEqualTo(wifiDialog2.getContext().getThemeResId());
|
||||
}
|
||||
}
|
||||
@@ -364,8 +364,8 @@ public class WifiSettingsTest {
|
||||
when(wifiEntry.canConnect()).thenReturn(true);
|
||||
final WifiConfigController2 controller = mock(WifiConfigController2.class);
|
||||
when(controller.getConfig()).thenReturn(config);
|
||||
final WifiDialog2 wifiDialog2 = spy(WifiDialog2.createModal(mContext, null /* listener */,
|
||||
wifiEntry, mode));
|
||||
WifiDialog2.WifiDialog2Listener listener = mock(WifiDialog2.WifiDialog2Listener.class);
|
||||
final WifiDialog2 wifiDialog2 = spy(new WifiDialog2(mContext, listener, wifiEntry, mode));
|
||||
when(wifiDialog2.getController()).thenReturn(controller);
|
||||
return wifiDialog2;
|
||||
}
|
||||
|
||||
92
tests/unit/src/com/android/settings/wifi/WifiDialog2Test.kt
Normal file
92
tests/unit/src/com/android/settings/wifi/WifiDialog2Test.kt
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.settings.R
|
||||
import com.android.settings.wifi.WifiDialog2.WifiDialog2Listener
|
||||
import com.android.wifitrackerlib.WifiEntry
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class WifiDialog2Test {
|
||||
@get:Rule
|
||||
val activityScenarioRule = ActivityScenarioRule(ComponentActivity::class.java)
|
||||
|
||||
@get:Rule
|
||||
val mockito: MockitoRule = MockitoJUnit.rule()
|
||||
|
||||
@Mock
|
||||
private lateinit var mockWifiEntry: WifiEntry
|
||||
|
||||
private val listener = object : WifiDialog2Listener {}
|
||||
|
||||
@Test
|
||||
fun constructor_usesDefaultTheme() {
|
||||
activityScenarioRule.scenario.onActivity { activity ->
|
||||
val wifiDialog2 = WifiDialog2(
|
||||
context = activity,
|
||||
listener = listener,
|
||||
wifiEntry = mockWifiEntry,
|
||||
mode = WifiConfigUiBase2.MODE_CONNECT,
|
||||
style = 0,
|
||||
hideSubmitButton = false
|
||||
)
|
||||
|
||||
val modal = WifiDialog2(
|
||||
context = activity,
|
||||
listener = listener,
|
||||
wifiEntry = mockWifiEntry,
|
||||
mode = WifiConfigUiBase2.MODE_CONNECT,
|
||||
)
|
||||
|
||||
assertThat(modal.context.themeResId).isEqualTo(wifiDialog2.context.themeResId)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun constructor_whenSetTheme_shouldBeCustomizedTheme() {
|
||||
activityScenarioRule.scenario.onActivity { activity ->
|
||||
val wifiDialog2 = WifiDialog2(
|
||||
context = activity,
|
||||
listener = listener,
|
||||
wifiEntry = mockWifiEntry,
|
||||
mode = WifiConfigUiBase2.MODE_CONNECT,
|
||||
style = R.style.SuwAlertDialogThemeCompat_Light,
|
||||
hideSubmitButton = false,
|
||||
)
|
||||
|
||||
val modal = WifiDialog2(
|
||||
context = activity,
|
||||
listener = listener,
|
||||
wifiEntry = mockWifiEntry,
|
||||
mode = WifiConfigUiBase2.MODE_CONNECT,
|
||||
style = R.style.SuwAlertDialogThemeCompat_Light,
|
||||
)
|
||||
|
||||
assertThat(modal.context.themeResId).isEqualTo(wifiDialog2.context.themeResId)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user