Merge "Use SettingsLib's ActionButtonsPreference"
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
@@ -30,9 +32,8 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
|
||||
import com.android.settingslib.widget.ActionButtonsPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -46,7 +47,7 @@ public class AppStorageSettingsTest {
|
||||
|
||||
@Mock
|
||||
private AppStorageSizesController mSizesController;
|
||||
private ActionButtonPreference mButtonsPref;
|
||||
private ActionButtonsPreference mButtonsPref;
|
||||
private AppStorageSettings mSettings;
|
||||
private Button mLeftButton;
|
||||
private Button mRightButton;
|
||||
@@ -58,7 +59,7 @@ public class AppStorageSettingsTest {
|
||||
mRightButton = new Button(RuntimeEnvironment.application);
|
||||
mSettings = spy(new AppStorageSettings());
|
||||
mSettings.mSizeController = mSizesController;
|
||||
mButtonsPref = ActionButtonPreferenceTest.createMock();
|
||||
mButtonsPref = createMock();
|
||||
mSettings.mButtonsPref = mButtonsPref;
|
||||
|
||||
when(mButtonsPref.setButton1OnClickListener(any(View.OnClickListener.class)))
|
||||
@@ -103,5 +104,22 @@ public class AppStorageSettingsTest {
|
||||
verify(mSettings).handleClearDataClick();
|
||||
verify(mSettings).handleClearCacheClick();
|
||||
}
|
||||
|
||||
private ActionButtonsPreference createMock() {
|
||||
final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
|
||||
when(pref.setButton1Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
when(pref.setButton2Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
return pref;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.applications.appinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -42,18 +43,18 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserManager;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.ActionButtonsPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -99,7 +100,7 @@ public class AppButtonsPreferenceControllerTest {
|
||||
@Mock
|
||||
private PackageInfo mPackageInfo;
|
||||
|
||||
private ActionButtonPreference mButtonPrefs;
|
||||
private ActionButtonsPreference mButtonPrefs;
|
||||
|
||||
private Intent mUninstallIntent;
|
||||
private AppButtonsPreferenceController mController;
|
||||
@@ -127,7 +128,7 @@ public class AppButtonsPreferenceControllerTest {
|
||||
mPackageInfo.packageName = PACKAGE_NAME;
|
||||
mPackageInfo.applicationInfo = mAppInfo;
|
||||
|
||||
mButtonPrefs = ActionButtonPreferenceTest.createMock();
|
||||
mButtonPrefs = createMock();
|
||||
mController.mButtonsPref = mButtonPrefs;
|
||||
mController.mPackageInfo = mPackageInfo;
|
||||
|
||||
@@ -390,4 +391,15 @@ public class AppButtonsPreferenceControllerTest {
|
||||
return SettingsEnums.PAGE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private ActionButtonsPreference createMock() {
|
||||
final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
|
||||
when(pref.setButton1Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
return pref;
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,8 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -34,8 +36,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settingslib.widget.ActionButtonsPreference;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -47,7 +48,7 @@ import org.robolectric.annotation.Config;
|
||||
@Config(shadows = SettingsShadowBluetoothDevice.class)
|
||||
public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsControllerTestBase {
|
||||
private BluetoothDetailsButtonsController mController;
|
||||
private ActionButtonPreference mButtonsPref;
|
||||
private ActionButtonsPreference mButtonsPref;
|
||||
private Button mConnectButton;
|
||||
private Button mForgetButton;
|
||||
|
||||
@@ -60,8 +61,9 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
mConnectButton = buttons.findViewById(R.id.button2);
|
||||
mForgetButton = buttons.findViewById(R.id.button1);
|
||||
mController =
|
||||
new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice, mLifecycle);
|
||||
mButtonsPref = ActionButtonPreferenceTest.createMock();
|
||||
new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle);
|
||||
mButtonsPref = createMock();
|
||||
when(mButtonsPref.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
when(mButtonsPref.setButton2OnClickListener(any(View.OnClickListener.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
@@ -186,4 +188,21 @@ public class BluetoothDetailsButtonsControllerTest extends BluetoothDetailsContr
|
||||
|
||||
verify(mButtonsPref).setButton2Enabled(false);
|
||||
}
|
||||
|
||||
private ActionButtonsPreference createMock() {
|
||||
final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
|
||||
when(pref.setButton1Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
when(pref.setButton2Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
return pref;
|
||||
}
|
||||
}
|
||||
|
@@ -83,6 +83,8 @@ public class SettingsRobolectricTestRunner extends RobolectricTestRunner {
|
||||
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/RestrictedLockUtils/res/")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/SearchWidget/res/")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/ActionButtonsPreference/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/SettingsLayoutPreference/res")), null));
|
||||
paths.add(new ResourcePath(null,
|
||||
|
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ActionButtonPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private View mRootView;
|
||||
private ActionButtonPreference mPref;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mRootView = View.inflate(mContext, R.layout.settings_action_buttons, null /* parent */);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
|
||||
mPref = new ActionButtonPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setTitle_shouldShowButtonByDefault() {
|
||||
mPref.setButton1Text(R.string.settings_label);
|
||||
mPref.setButton2Text(R.string.settings_label);
|
||||
mPref.setButton3Text(R.string.settings_label);
|
||||
mPref.setButton4Text(R.string.settings_label);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button2).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button3).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button4).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setIcon_shouldShowButtonByDefault() {
|
||||
mPref.setButton1Icon(R.drawable.ic_settings);
|
||||
mPref.setButton2Icon(R.drawable.ic_settings);
|
||||
mPref.setButton3Icon(R.drawable.ic_settings);
|
||||
mPref.setButton4Icon(R.drawable.ic_settings);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button2).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button3).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button4).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_notSetTitleOrIcon_shouldNotShowButtonByDefault() {
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button2).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button3).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button4).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setVisibleIsGoneAndSetTitle_shouldNotShowButton() {
|
||||
mPref.setButton1Text(R.string.settings_label).setButton1Visible(false);
|
||||
mPref.setButton2Text(R.string.settings_label).setButton2Visible(false);
|
||||
mPref.setButton3Text(R.string.settings_label).setButton3Visible(false);
|
||||
mPref.setButton4Text(R.string.settings_label).setButton4Visible(false);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button2).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button3).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button4).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setVisibleIsGoneAndSetIcon_shouldNotShowButton() {
|
||||
mPref.setButton1Icon(R.drawable.ic_settings).setButton1Visible(false);
|
||||
mPref.setButton2Icon(R.drawable.ic_settings).setButton2Visible(false);
|
||||
mPref.setButton3Icon(R.drawable.ic_settings).setButton3Visible(false);
|
||||
mPref.setButton4Icon(R.drawable.ic_settings).setButton4Visible(false);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button2).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button3).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button4).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setVisibility_shouldUpdateButtonVisibility() {
|
||||
mPref.setButton1Text(R.string.settings_label).setButton1Visible(false);
|
||||
mPref.setButton2Text(R.string.settings_label).setButton2Visible(false);
|
||||
mPref.setButton3Text(R.string.settings_label).setButton3Visible(false);
|
||||
mPref.setButton4Text(R.string.settings_label).setButton4Visible(false);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button2).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button3).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
assertThat(mRootView.findViewById(R.id.button4).getVisibility())
|
||||
.isEqualTo(View.GONE);
|
||||
|
||||
mPref.setButton1Visible(true);
|
||||
mPref.setButton2Visible(true);
|
||||
mPref.setButton3Visible(true);
|
||||
mPref.setButton4Visible(true);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button2).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button3).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
assertThat(mRootView.findViewById(R.id.button4).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setEnabled_shouldEnableButton() {
|
||||
mPref.setButton1Enabled(true);
|
||||
mPref.setButton2Enabled(false);
|
||||
mPref.setButton3Enabled(true);
|
||||
mPref.setButton4Enabled(false);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mRootView.findViewById(R.id.button1).isEnabled()).isTrue();
|
||||
assertThat(mRootView.findViewById(R.id.button2).isEnabled()).isFalse();
|
||||
assertThat(mRootView.findViewById(R.id.button3).isEnabled()).isTrue();
|
||||
assertThat(mRootView.findViewById(R.id.button4).isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setText_shouldShowSameText() {
|
||||
mPref.setButton1Text(R.string.settings_label);
|
||||
mPref.setButton2Text(R.string.settings_label);
|
||||
mPref.setButton3Text(R.string.settings_label);
|
||||
mPref.setButton4Text(R.string.settings_label);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(((Button) mRootView.findViewById(R.id.button1)).getText())
|
||||
.isEqualTo(mContext.getText(R.string.settings_label));
|
||||
assertThat(((Button) mRootView.findViewById(R.id.button2)).getText())
|
||||
.isEqualTo(mContext.getText(R.string.settings_label));
|
||||
assertThat(((Button) mRootView.findViewById(R.id.button3)).getText())
|
||||
.isEqualTo(mContext.getText(R.string.settings_label));
|
||||
assertThat(((Button) mRootView.findViewById(R.id.button4)).getText())
|
||||
.isEqualTo(mContext.getText(R.string.settings_label));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setButtonIcon_iconMustDisplayAboveText() {
|
||||
mPref.setButton1Text(R.string.settings_label);
|
||||
mPref.setButton1Icon(R.drawable.ic_settings);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
final Drawable[] drawablesAroundText =
|
||||
((Button) mRootView.findViewById(R.id.button1))
|
||||
.getCompoundDrawables();
|
||||
|
||||
assertThat(drawablesAroundText[1 /* top */]).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setButtonIcon_iconResourceIdIsZero_shouldNotDisplayIcon() {
|
||||
mPref.setButton1Text(R.string.settings_label);
|
||||
mPref.setButton1Icon(0);
|
||||
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
final Drawable[] drawablesAroundText =
|
||||
((Button) mRootView.findViewById(R.id.button1))
|
||||
.getCompoundDrawables();
|
||||
|
||||
assertThat(drawablesAroundText[1 /* top */]).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setButtonIcon_iconResourceIdNotExisting_shouldNotDisplayIconAndCrash() {
|
||||
mPref.setButton1Text(R.string.settings_label);
|
||||
mPref.setButton1Icon(999999999 /* not existing id */);
|
||||
// Should not crash here
|
||||
mPref.onBindViewHolder(mHolder);
|
||||
final Drawable[] drawablesAroundText =
|
||||
((Button) mRootView.findViewById(R.id.button1))
|
||||
.getCompoundDrawables();
|
||||
|
||||
assertThat(drawablesAroundText[1 /* top */]).isNull();
|
||||
}
|
||||
|
||||
public static ActionButtonPreference createMock() {
|
||||
final ActionButtonPreference pref = mock(ActionButtonPreference.class);
|
||||
when(pref.setButton1Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
when(pref.setButton2Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
when(pref.setButton3Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton3Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton3Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton3Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton3OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
when(pref.setButton4Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton4Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton4Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton4Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton4OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
return pref;
|
||||
}
|
||||
}
|
@@ -17,12 +17,14 @@ package com.android.settings.wifi.details;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -67,11 +69,10 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowBidiFormatter;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.ActionButtonsPreference;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
@@ -142,7 +143,7 @@ public class WifiDetailPreferenceControllerTest {
|
||||
private ImageView mockHeaderIcon;
|
||||
|
||||
@Mock
|
||||
private ActionButtonPreference mockButtonsPref;
|
||||
private ActionButtonsPreference mockButtonsPref;
|
||||
@Mock
|
||||
private Preference mockSignalStrengthPref;
|
||||
@Mock
|
||||
@@ -247,7 +248,7 @@ public class WifiDetailPreferenceControllerTest {
|
||||
.thenReturn(mockNetworkInfo);
|
||||
doNothing().when(mockConnectivityManager).registerNetworkCallback(
|
||||
nullable(NetworkRequest.class), mCallbackCaptor.capture(), nullable(Handler.class));
|
||||
mockButtonsPref = ActionButtonPreferenceTest.createMock();
|
||||
mockButtonsPref = createMock();
|
||||
when(mockButtonsPref.setButton1OnClickListener(mForgetClickListener.capture()))
|
||||
.thenReturn(mockButtonsPref);
|
||||
|
||||
@@ -849,4 +850,21 @@ public class WifiDetailPreferenceControllerTest {
|
||||
verify(mockAccessPoint, times(2)).getLevel();
|
||||
verify(mockIconInjector, times(2)).getIcon(anyInt());
|
||||
}
|
||||
|
||||
private ActionButtonsPreference createMock() {
|
||||
final ActionButtonsPreference pref = mock(ActionButtonsPreference.class);
|
||||
when(pref.setButton1Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
when(pref.setButton2Text(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Icon(anyInt())).thenReturn(pref);
|
||||
when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
|
||||
when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
|
||||
|
||||
return pref;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user