Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f75009b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Modify topKEqualsToSort test to cover more cases."

parents fc17f8bf fc7b8aad
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -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,