Modify topKEqualsToSort test to cover more cases.
Modify the test to cover k greater than or equals to input size cases. Bug: 143076068, 142558305 Test: this is the test. Change-Id: I52cccd60c1835720f848cdab54b6b09e43020281
This commit is contained in:
@@ -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<ResolvedComponentInfo> resolvedComponents = createResolvedComponentsForTest(15);
|
||||
List<ResolvedComponentInfo> 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<ResolvedComponentInfo> 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,
|
||||
|
||||
Reference in New Issue
Block a user