use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.
the class SummaryLoaderTest method SetUp.
@Before
public void SetUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
mTile = new Tile();
mTile.summary = SUMMARY_1;
mCallbackInvoked = false;
final Activity activity = Robolectric.buildActivity(Activity.class).get();
final List<DashboardCategory> categories = new ArrayList<>();
mSummaryLoader = new SummaryLoader(activity, categories);
mSummaryLoader.setSummaryConsumer(new SummaryLoader.SummaryConsumer() {
@Override
public void notifySummaryChanged(Tile tile) {
mCallbackInvoked = true;
}
});
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.
the class SummaryLoaderTest method testUpdateSummaryToCache_hasCache_shouldUpdate.
@Test
public void testUpdateSummaryToCache_hasCache_shouldUpdate() {
final String testSummary = "test_summary";
final DashboardCategory category = new DashboardCategory();
final Tile tile = new Tile();
tile.key = "123";
tile.intent = new Intent();
category.addTile(tile);
when(mFeatureFactory.dashboardFeatureProvider.getDashboardKeyForTile(tile)).thenReturn(tile.key);
mSummaryLoader.updateSummaryIfNeeded(tile, testSummary);
tile.summary = null;
mSummaryLoader.updateSummaryToCache(category);
assertThat(tile.summary).isEqualTo(testSummary);
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.
the class DashboardAdapterTest method makeSuggestions.
private List<Tile> makeSuggestions(String... pkgNames) {
final List<Tile> suggestions = new ArrayList<>();
for (String pkgName : pkgNames) {
Tile suggestion = new Tile();
suggestion.intent = new Intent("action");
suggestion.intent.setComponent(new ComponentName(pkgName, "cls"));
suggestions.add(suggestion);
}
return suggestions;
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.
the class DashboardAdapterTest method testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly.
@Test
public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, null, null, null));
final List<Tile> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3");
adapter.setCategoriesAndSuggestions(null, /* category */
suggestions);
final RecyclerView data = mock(RecyclerView.class);
when(data.getResources()).thenReturn(mResources);
when(data.getContext()).thenReturn(mContext);
when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
final View itemView = mock(View.class);
when(itemView.findViewById(R.id.data)).thenReturn(data);
final DashboardAdapter.SuggestionAndConditionContainerHolder holder = new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
adapter.onBindConditionAndSuggestion(holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
final DashboardData dashboardData = adapter.mDashboardData;
// clear interactions tracking
reset(adapter);
final Tile suggestionToRemove = suggestions.get(1);
adapter.onSuggestionDismissed(suggestionToRemove);
assertThat(adapter.mDashboardData).isEqualTo(dashboardData);
assertThat(suggestions.size()).isEqualTo(2);
assertThat(suggestions.contains(suggestionToRemove)).isFalse();
verify(adapter, never()).notifyDashboardDataChanged(any());
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.
the class DashboardAdapterTest method testSuggestionDismissed_moreThanTwoSuggestions_defaultMode_shouldNotCrash.
@Test
public void testSuggestionDismissed_moreThanTwoSuggestions_defaultMode_shouldNotCrash() {
final RecyclerView data = new RecyclerView(RuntimeEnvironment.application);
final View itemView = mock(View.class);
when(itemView.findViewById(R.id.data)).thenReturn(data);
final DashboardAdapter.SuggestionAndConditionContainerHolder holder = new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
final List<Tile> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4");
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, /*savedInstance */
null, /* conditions */
null, /* suggestionParser */
null));
adapter.setCategoriesAndSuggestions(null, /* category */
suggestions);
adapter.onBindConditionAndSuggestion(holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
// default mode, only displaying 2 suggestions
adapter.onSuggestionDismissed(suggestions.get(1));
// verify operations that access the lists will not cause ConcurrentModificationException
assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(1);
adapter.setCategoriesAndSuggestions(null, /* category */
suggestions);
// should not crash
}
Aggregations