diff --git a/core/tests/coretests/src/com/android/internal/app/ResolverListControllerTest.java b/core/tests/coretests/src/com/android/internal/app/ResolverListControllerTest.java index 6218fa9fbac88..5ac1489bcfefd 100644 --- a/core/tests/coretests/src/com/android/internal/app/ResolverListControllerTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ResolverListControllerTest.java @@ -16,6 +16,8 @@ package com.android.internal.app; +import static junit.framework.Assert.assertEquals; + import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.any; @@ -126,7 +128,7 @@ public class ResolverListControllerTest { String annotation = "test_annotation"; Intent sendIntent = createSendImageIntent(annotation); String refererPackage = "test_referer_package"; - List resolvedComponents = createResolvedComponentsForTest(15); + List resolvedComponents = createResolvedComponentsForTest(10); mUsm = new UsageStatsManager(mMockContext, mMockService); when(mMockContext.getSystemService(Context.USAGE_STATS_SERVICE)).thenReturn(mUsm); mController = new ResolverListController(mMockContext, mMockPackageManager, sendIntent, @@ -135,7 +137,18 @@ public class ResolverListControllerTest { mController.topK(topKList, 5); List sortList = new ArrayList<>(topKList); mController.sort(sortList); - assertThat(sortList.subList(0, 5), is(topKList.subList(0, 5))); + assertEquals("Top k elements should be sorted when input size greater than k.", + sortList.subList(0, 5), topKList.subList(0, 5)); + mController.topK(topKList, 10); + sortList = new ArrayList<>(topKList); + mController.sort(sortList); + assertEquals("All elements should be sorted when input size equals k.", + sortList, topKList); + mController.topK(topKList, 15); + sortList = new ArrayList<>(topKList); + mController.sort(sortList); + assertEquals("All elements should be sorted when input size less than k.", + sortList, topKList); } private UsageStats initStats(String packageName, String action,