Merge "Misc fix on network & internet screen for developer preview"
diff --git a/res/layout/preference_master_switch.xml b/res/layout/preference_master_switch.xml
new file mode 100644
index 0000000..9f46d76
--- /dev/null
+++ b/res/layout/preference_master_switch.xml
@@ -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>
diff --git a/res/layout/preference_widget_master_switch.xml b/res/layout/preference_widget_master_switch.xml
index bca15f9..bc1cafd 100644
--- a/res/layout/preference_widget_master_switch.xml
+++ b/res/layout/preference_widget_master_switch.xml
@@ -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">
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9a729da..2711a28 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -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 &amp; portable hotspot</string>
+    <string name="tether_settings_title_all">Hotspot &amp; 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>
 
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index 7c41498..d7a6355 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -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
@@ -78,23 +78,8 @@
         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>
\ No newline at end of file
diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml
index ad5315d..e8c3171 100644
--- a/res/xml/wifi_configure_settings.xml
+++ b/res/xml/wifi_configure_settings.xml
@@ -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"
@@ -54,6 +56,12 @@
     </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">
         <intent android:targetPackage="com.android.settings"
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 6c613a5..910e1eb 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -23,7 +23,6 @@
 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.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.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 @@
     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 @@
         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 @@
         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 @@
 
                     new TetherPreferenceController(context).updateNonIndexableKeys(result);
                     new WifiCallingPreferenceController(context).updateNonIndexableKeys(result);
-                    new NetworkResetPreferenceController(context).updateNonIndexableKeys(result);
 
                     return result;
                 }
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 2d91414..d2b0621 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -20,6 +20,8 @@
 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 @@
 
     private static final String TAG = "NetworkDashboardFrag";
 
+    private NetworkResetActionMenuController mNetworkResetController;
+
     @Override
     public int getMetricsCategory() {
         return MetricsProto.MetricsEvent.SETTINGS_NETWORK_CATEGORY;
@@ -58,13 +62,25 @@
     }
 
     @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 =
                 new AirplaneModePreferenceController(context, this /* fragment */);
         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 @@
         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);
diff --git a/src/com/android/settings/network/NetworkResetActionMenuController.java b/src/com/android/settings/network/NetworkResetActionMenuController.java
new file mode 100644
index 0000000..67c37a4
--- /dev/null
+++ b/src/com/android/settings/network/NetworkResetActionMenuController.java
@@ -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());
+    }
+}
diff --git a/src/com/android/settings/network/NetworkResetPreferenceController.java b/src/com/android/settings/network/NetworkResetPreferenceController.java
deleted file mode 100644
index e357fbe..0000000
--- a/src/com/android/settings/network/NetworkResetPreferenceController.java
+++ /dev/null
@@ -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;
-    }
-}
diff --git a/src/com/android/settings/widget/MasterSwitchPreference.java b/src/com/android/settings/widget/MasterSwitchPreference.java
index 4650730..94c429b 100644
--- a/src/com/android/settings/widget/MasterSwitchPreference.java
+++ b/src/com/android/settings/widget/MasterSwitchPreference.java
@@ -110,6 +110,7 @@
     }
 
     private void init() {
+        setLayoutResource(R.layout.preference_master_switch);
         setWidgetLayoutResource(R.layout.preference_widget_master_switch);
     }
 }
diff --git a/src/com/android/settings/wifi/ConfigureWifiSettings.java b/src/com/android/settings/wifi/ConfigureWifiSettings.java
index ce671fe..2916fb1 100644
--- a/src/com/android/settings/wifi/ConfigureWifiSettings.java
+++ b/src/com/android/settings/wifi/ConfigureWifiSettings.java
@@ -25,6 +25,7 @@
 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 @@
         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;
diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
index dc96ed6..7626ec4 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
@@ -17,13 +17,13 @@
 
 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.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 @@
         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));
+    }
+
 }
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
new file mode 100644
index 0000000..ba332b7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
@@ -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());
+    }
+}