Merge changes I1c3620d3,Ic0bf23f6

* changes:
  Move some subsetting launch to SubSettingLauncher
  Migrate more subsetting launching to SubSettingLauncher
This commit is contained in:
Fan Zhang
2018-02-16 16:58:51 +00:00
committed by Android (Google) Code Review
18 changed files with 84 additions and 103 deletions

View File

@@ -101,6 +101,6 @@ public class BluetoothPairingPreferenceControllerTest {
mController.handlePreferenceTreeClick(mPreference);
verify(mSettingsActivity).startPreferencePanelAsUser(eq(mFragment), anyString(), any(),
anyInt(), any(), any());
anyInt(), any());
}
}

View File

@@ -28,6 +28,7 @@ import android.content.Intent;
import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
import org.junit.Before;
import org.junit.Test;
@@ -49,12 +50,28 @@ public class SubSettingLauncherTest {
@Test(expected = IllegalStateException.class)
public void cannotReuseLauncher() {
final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext));
final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext))
.setDestination(SubSettingLauncherTest.class.getName())
.setSourceMetricsCategory(123);
doNothing().when(launcher).launch(any(Intent.class));
launcher.launch();
launcher.launch();
}
@Test(expected = IllegalArgumentException.class)
public void launch_noSourceMetricsCategory_shouldCrash() {
final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext))
.setDestination(SubSettingLauncherTest.class.getName());
launcher.launch();
}
@Test(expected = IllegalArgumentException.class)
public void launch_noDestination_shouldCrash() {
final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext))
.setSourceMetricsCategory(123);
launcher.launch();
}
@Test
public void launch_shouldIncludeAllParams() {
final ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -62,6 +79,7 @@ public class SubSettingLauncherTest {
launcher.setTitle("123")
.setDestination(SubSettingLauncherTest.class.getName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setSourceMetricsCategory(123)
.launch();
doNothing().when(launcher).launch(any(Intent.class));
verify(launcher).launch(intentArgumentCaptor.capture());
@@ -72,5 +90,7 @@ public class SubSettingLauncherTest {
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
.isEqualTo(SubSettingLauncherTest.class.getName());
assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_NEW_TASK);
assertThat(intent.getIntExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY, -1))
.isEqualTo(123);
}
}

View File

@@ -210,7 +210,7 @@ public class AdvancedPowerUsageDetailTest {
};
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(
nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(),
nullable(CharSequence.class), nullable(UserHandle.class));
nullable(UserHandle.class));
mForegroundPreference = new Preference(mContext);
mBackgroundPreference = new Preference(mContext);
@@ -345,7 +345,7 @@ public class AdvancedPowerUsageDetailTest {
verify(mTestActivity).startPreferencePanelAsUser(
nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
nullable(CharSequence.class), eq(new UserHandle(10)));
eq(new UserHandle(10)));
}
@Test
@@ -361,7 +361,7 @@ public class AdvancedPowerUsageDetailTest {
verify(mTestActivity).startPreferencePanelAsUser(
nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
nullable(CharSequence.class), eq(new UserHandle(currentUser)));
eq(new UserHandle(currentUser)));
}
@Test
@@ -372,7 +372,7 @@ public class AdvancedPowerUsageDetailTest {
return null;
};
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(nullable(Fragment.class),
nullable(String.class), captor.capture(), anyInt(), nullable(CharSequence.class),
nullable(String.class), captor.capture(), anyInt(),
nullable(UserHandle.class));
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, PACKAGE_NAME[0]);

View File

@@ -17,8 +17,6 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -26,7 +24,6 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -40,9 +37,9 @@ import android.support.v7.preference.PreferenceManager;
import android.util.IconDrawableFactory;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.fuelgauge.anomaly.Anomaly;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
@@ -188,8 +185,7 @@ public class PowerUsageAnomalyDetailsTest {
}
};
doAnswer(bundleCallable).when(mSettingsActivity).startPreferencePanelAsUser(any(),
anyString(),
bundleCaptor.capture(), anyInt(), any(), any());
anyString(), bundleCaptor.capture(), anyInt(), any());
PowerUsageAnomalyDetails.startBatteryAbnormalPage(mSettingsActivity, mFragment,
mAnomalyList);

View File

@@ -17,7 +17,6 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -112,7 +111,7 @@ public class RestrictAppPreferenceControllerTest {
verify(mSettingsActivity).startPreferencePanelAsUser(eq(mFragment),
eq(RestrictedAppDetails.class.getName()), any(), eq(R.string.restricted_app_title),
any(), any());
any());
}
}

View File

@@ -178,7 +178,7 @@ public class RecentLocationRequestPreferenceControllerTest {
verify(activity).startPreferencePanelAsUser(any(),
eq(AppInfoDashboardFragment.class.getName()),
any(Bundle.class), anyInt(), any(), any());
any(Bundle.class), anyInt(), any());
}
private static ArgumentMatcher<Preference> titleMatches(String expected) {