Fix presubmit test

Change-Id: I8c1f35fc76ed153080655242943fdfa9c29cf5bb
Fix: 62913954
Test: robotests
This commit is contained in:
Fan Zhang
2017-06-22 15:51:54 -07:00
parent 9534677b9e
commit aedcd8b519

View File

@@ -22,6 +22,7 @@ import android.app.usage.UsageStatsManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
@@ -46,6 +47,7 @@ import org.robolectric.annotation.Config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
@@ -179,6 +181,9 @@ public class RecentAppsPreferenceControllerTest {
.thenReturn(new ResolveInfo()); .thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())) when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats); .thenReturn(stats);
final Configuration configuration = new Configuration();
configuration.locale = Locale.US;
when(mMockContext.getResources().getConfiguration()).thenReturn(configuration);
when(mMockContext.getString(eq(R.string.battery_history_minutes_no_seconds), anyInt())) when(mMockContext.getString(eq(R.string.battery_history_minutes_no_seconds), anyInt()))
.thenReturn(mContext.getString(R.string.battery_history_minutes_no_seconds, 45)); .thenReturn(mContext.getString(R.string.battery_history_minutes_no_seconds, 45));
@@ -245,15 +250,17 @@ public class RecentAppsPreferenceControllerTest {
.thenReturn(new ResolveInfo()); .thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())) when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats); .thenReturn(stats);
when(mMockContext.getString(eq(R.string.battery_history_minutes_no_seconds), anyInt()))
.thenReturn(mContext.getString(R.string.battery_history_minutes_no_seconds, 35));
when(mMockContext.getResources().getText(eq(R.string.recent_app_summary))) when(mMockContext.getResources().getText(eq(R.string.recent_app_summary)))
.thenReturn(mContext.getResources().getText(R.string.recent_app_summary)); .thenReturn(mContext.getResources().getText(R.string.recent_app_summary));
final Configuration configuration = new Configuration();
configuration.locale = Locale.US;
when(mMockContext.getResources().getConfiguration()).thenReturn(configuration);
mController = new RecentAppsPreferenceController(mMockContext, mAppState, null); mController = new RecentAppsPreferenceController(mMockContext, mAppState, null);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
verify(mCategory).addPreference(argThat(summaryMatches("35m ago"))); verify(mCategory).addPreference(argThat(summaryMatches("0m ago")));
} }
private static ArgumentMatcher<Preference> summaryMatches(String expected) { private static ArgumentMatcher<Preference> summaryMatches(String expected) {