Merge "Misc fix on network & internet screen for developer preview"
This commit is contained in:
committed by
Android (Google) Code Review
commit
14c2050330
90
res/layout/preference_master_switch.xml
Normal file
90
res/layout/preference_master_switch.xml
Normal file
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<!-- Based off preference_material_settings.xml except that ripple on only on the left side. -->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="@android:color/transparent"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="60dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
<com.android.internal.widget.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="48dp"
|
||||
android:maxHeight="48dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:ellipsize="marquee"/>
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="10"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Preference should place its actual preference widget here. -->
|
||||
<LinearLayout
|
||||
android:id="@android:id/widget_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end|center_vertical"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
</LinearLayout>
|
@@ -24,7 +24,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
@@ -2943,7 +2943,7 @@
|
||||
<!-- Tethering controls, item title to go into the tethering settings when USB and Bluetooth tethering are available [CHAR LIMIT=25]-->
|
||||
<string name="tether_settings_title_usb_bluetooth">Tethering</string>
|
||||
<!-- Tethering controls, item title to go into the tethering settings when USB, Bluetooth and Wifi tethering are available [CHAR LIMIT=25]-->
|
||||
<string name="tether_settings_title_all">Tethering & portable hotspot</string>
|
||||
<string name="tether_settings_title_all">Hotspot & Tethering</string>
|
||||
<!-- Tethering controls, footer note displayed when tethering is disabled because Data Saver mode is on [CHAR LIMIT=none]-->
|
||||
<string name="tether_settings_disabled_on_data_saver">"Can\u2019t tether or use portable hotspots while Data Saver is on"</string>
|
||||
|
||||
|
@@ -26,8 +26,8 @@
|
||||
android:icon="@drawable/ic_settings_wireless"
|
||||
android:order="-30">
|
||||
<intent
|
||||
android:action="android.settings.WIFI_SETTINGS"
|
||||
android:targetClass="Settings$WifiSettingsActivity" />
|
||||
android:action="android.settings.WIFI_SETTINGS"
|
||||
android:targetClass="Settings$WifiSettingsActivity"/>
|
||||
</com.android.settings.widget.MasterSwitchPreference>
|
||||
|
||||
<SwitchPreference
|
||||
@@ -77,24 +77,9 @@
|
||||
settings:userRestriction="no_config_mobile_networks"
|
||||
settings:useAdminDisabledSummary="true"/>
|
||||
|
||||
<Preference
|
||||
android:key="wifi_calling_settings"
|
||||
android:title="@string/wifi_calling_settings_title"
|
||||
android:fragment="com.android.settings.WifiCallingSettings"
|
||||
settings:keywords="@string/keywords_wifi_calling"/>
|
||||
|
||||
<Preference
|
||||
android:fragment="com.android.settings.ProxySelector"
|
||||
android:key="proxy_settings"
|
||||
android:title="@string/proxy_settings_title"/>
|
||||
|
||||
<!-- Network reset -->
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="network_reset"
|
||||
android:title="@string/reset_network_title"
|
||||
android:icon="@drawable/ic_settings_backup_restore"
|
||||
settings:keywords="@string/keywords_network_reset"
|
||||
android:fragment="com.android.settings.ResetNetwork"
|
||||
settings:userRestriction="no_network_reset"
|
||||
settings:useAdminDisabledSummary="true"/>
|
||||
</PreferenceScreen>
|
@@ -14,8 +14,10 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/wifi_configure_titlebar">
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/wifi_configure_titlebar">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="enable_wifi_wakeup"
|
||||
@@ -53,6 +55,12 @@
|
||||
</intent>
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
android:key="wifi_calling_settings"
|
||||
android:title="@string/wifi_calling_settings_title"
|
||||
android:fragment="com.android.settings.WifiCallingSettings"
|
||||
settings:keywords="@string/keywords_wifi_calling"/>
|
||||
|
||||
<Preference
|
||||
android:key="wifi_direct"
|
||||
android:title="@string/wifi_menu_p2p">
|
||||
|
@@ -23,7 +23,6 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -31,14 +30,12 @@ import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.network.AirplaneModePreferenceController;
|
||||
import com.android.settings.network.MobileNetworkPreferenceController;
|
||||
import com.android.settings.network.MobilePlanPreferenceController;
|
||||
import com.android.settings.network.NetworkResetPreferenceController;
|
||||
import com.android.settings.network.ProxyPreferenceController;
|
||||
import com.android.settings.network.TetherPreferenceController;
|
||||
import com.android.settings.network.VpnPreferenceController;
|
||||
@@ -47,7 +44,6 @@ import com.android.settings.nfc.NfcPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -69,7 +65,6 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
|
||||
private TetherPreferenceController mTetherPreferenceController;
|
||||
private MobileNetworkPreferenceController mMobileNetworkPreferenceController;
|
||||
private VpnPreferenceController mVpnPreferenceController;
|
||||
private NetworkResetPreferenceController mNetworkResetPreferenceController;
|
||||
private WifiCallingPreferenceController mWifiCallingPreferenceController;
|
||||
private ProxyPreferenceController mProxyPreferenceController;
|
||||
private MobilePlanPreferenceController mMobilePlanPreferenceController;
|
||||
@@ -150,7 +145,6 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
|
||||
mMobileNetworkPreferenceController = new MobileNetworkPreferenceController(activity);
|
||||
mVpnPreferenceController = new VpnPreferenceController(activity);
|
||||
mWifiCallingPreferenceController = new WifiCallingPreferenceController(activity);
|
||||
mNetworkResetPreferenceController = new NetworkResetPreferenceController(activity);
|
||||
mProxyPreferenceController = new ProxyPreferenceController(activity);
|
||||
mMobilePlanPreferenceController = new MobilePlanPreferenceController(activity, this);
|
||||
mNfcPreferenceController = new NfcPreferenceController(activity);
|
||||
@@ -162,7 +156,6 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
|
||||
mMobileNetworkPreferenceController.displayPreference(screen);
|
||||
mVpnPreferenceController.displayPreference(screen);
|
||||
mWifiCallingPreferenceController.displayPreference(screen);
|
||||
mNetworkResetPreferenceController.displayPreference(screen);
|
||||
mProxyPreferenceController.displayPreference(screen);
|
||||
mMobilePlanPreferenceController.displayPreference(screen);
|
||||
mNfcPreferenceController.displayPreference(screen);
|
||||
@@ -270,7 +263,6 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
|
||||
|
||||
new TetherPreferenceController(context).updateNonIndexableKeys(result);
|
||||
new WifiCallingPreferenceController(context).updateNonIndexableKeys(result);
|
||||
new NetworkResetPreferenceController(context).updateNonIndexableKeys(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
@@ -42,6 +44,8 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
|
||||
private static final String TAG = "NetworkDashboardFrag";
|
||||
|
||||
private NetworkResetActionMenuController mNetworkResetController;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_NETWORK_CATEGORY;
|
||||
@@ -57,6 +61,18 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
return R.xml.network_and_internet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mNetworkResetController = new NetworkResetActionMenuController(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
mNetworkResetController.buildMenuItem(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final AirplaneModePreferenceController airplaneModePreferenceController =
|
||||
@@ -64,7 +80,7 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
final MobilePlanPreferenceController mobilePlanPreferenceController =
|
||||
new MobilePlanPreferenceController(context, this);
|
||||
final WifiMasterSwitchPreferenceController wifiPreferenceController =
|
||||
new WifiMasterSwitchPreferenceController(context, mMetricsFeatureProvider);
|
||||
new WifiMasterSwitchPreferenceController(context, mMetricsFeatureProvider);
|
||||
final Lifecycle lifecycle = getLifecycle();
|
||||
lifecycle.addObserver(airplaneModePreferenceController);
|
||||
lifecycle.addObserver(mobilePlanPreferenceController);
|
||||
@@ -75,8 +91,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
controllers.add(new MobileNetworkPreferenceController(context));
|
||||
controllers.add(new TetherPreferenceController(context));
|
||||
controllers.add(new VpnPreferenceController(context));
|
||||
controllers.add(new WifiCallingPreferenceController(context));
|
||||
controllers.add(new NetworkResetPreferenceController(context));
|
||||
controllers.add(new ProxyPreferenceController(context));
|
||||
controllers.add(mobilePlanPreferenceController);
|
||||
controllers.add(wifiPreferenceController);
|
||||
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.ResetNetwork;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
public class NetworkResetActionMenuController {
|
||||
|
||||
private static final int MENU_NETWORK_RESET = Menu.FIRST + 200;
|
||||
private final Context mContext;
|
||||
|
||||
public NetworkResetActionMenuController(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void buildMenuItem(Menu menu) {
|
||||
MenuItem item = null;
|
||||
if (isAvailable() && menu != null) {
|
||||
item = menu.add(0, MENU_NETWORK_RESET, 0, R.string.reset_network_title);
|
||||
}
|
||||
if (item != null) {
|
||||
item.setOnMenuItemClickListener(target -> {
|
||||
Utils.startWithFragment(mContext, ResetNetwork.class.getName(), null, null,
|
||||
0, R.string.reset_network_title, null);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
boolean isAvailable() {
|
||||
return !RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId());
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
public class NetworkResetPreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_NETWORK_RESET = "network_reset";
|
||||
|
||||
public NetworkResetPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_NETWORK_RESET;
|
||||
}
|
||||
}
|
@@ -110,6 +110,7 @@ public class MasterSwitchPreference extends Preference {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setLayoutResource(R.layout.preference_master_switch);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_master_switch);
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.network.WifiCallingPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.wifi.p2p.WifiP2pPreferenceController;
|
||||
@@ -71,6 +72,7 @@ public class ConfigureWifiSettings extends DashboardFragment {
|
||||
controllers.add(new WifiWakeupPreferenceController(context, getLifecycle()));
|
||||
controllers.add(new WifiSleepPolicyPreferenceController(context));
|
||||
controllers.add(new WifiP2pPreferenceController(context, getLifecycle(), mWifiManager));
|
||||
controllers.add(new WifiCallingPreferenceController(context));
|
||||
controllers.add(new WpsPreferenceController(
|
||||
context, getLifecycle(), mWifiManager, getFragmentManager()));
|
||||
return controllers;
|
||||
|
@@ -17,13 +17,13 @@ package com.android.settings.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.view.Menu;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.accounts.UserAndAccountDashboardFragment;
|
||||
import com.android.settings.dashboard.DashboardFragmentRegistry;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -32,10 +32,14 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -72,4 +76,16 @@ public class NetworkDashboardFragmentTest {
|
||||
assertThat(indexRes).isNotNull();
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareActionBar_networkResetShouldBeCreated() {
|
||||
final NetworkResetActionMenuController resetController =
|
||||
mock(NetworkResetActionMenuController.class);
|
||||
ReflectionHelpers.setField(mFragment, "mNetworkResetController", resetController);
|
||||
|
||||
mFragment.onCreateOptionsMenu(null, null);
|
||||
|
||||
verify(resetController).buildMenuItem(any(Menu.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.network;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class NetworkResetActionMenuControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private NetworkResetActionMenuController mController;
|
||||
@Mock
|
||||
private Menu mMenu;
|
||||
@Mock
|
||||
private MenuItem mMenuItem;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new NetworkResetActionMenuController(mContext));
|
||||
when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildMenuItem_available_shouldAddToMenu() {
|
||||
doReturn(true).when(mController).isAvailable();
|
||||
|
||||
mController.buildMenuItem(mMenu);
|
||||
|
||||
verify(mMenu).add(anyInt(), anyInt(), anyInt(), anyInt());
|
||||
verify(mMenuItem).setOnMenuItemClickListener(any(MenuItem.OnMenuItemClickListener.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildMenuItem_notAvailable_shouldNotAddToMenu() {
|
||||
doReturn(false).when(mController).isAvailable();
|
||||
|
||||
mController.buildMenuItem(mMenu);
|
||||
|
||||
verify(mMenu, never()).add(anyInt(), anyInt(), anyInt(), anyInt());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user