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

Commit 2317ac18 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

[res] Fix ResourcesManagerTest

1. Override the correct overload to mock the AssetManager
creation

2. Fix the test that checks for the cached resources object
(should be ResourcesImpl, not Resources)

Bug: 313502732
Test: atest ResourcesManagerTest
Change-Id: I0fd4fb75cbb7a01299b65600ebc295a97bfd5b15
parent 7a4bca8a
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -159,7 +159,8 @@ public class ResourcesManager {
     * Loads {@link ApkAssets} and caches them to prevent their garbage collection while the
     * Loads {@link ApkAssets} and caches them to prevent their garbage collection while the
     * instance is alive and reachable.
     * instance is alive and reachable.
     */
     */
    private class ApkAssetsSupplier {
    @VisibleForTesting
    protected class ApkAssetsSupplier {
        final ArrayMap<ApkKey, ApkAssets> mLocalCache = new ArrayMap<>();
        final ArrayMap<ApkKey, ApkAssets> mLocalCache = new ArrayMap<>();


        /**
        /**
@@ -544,7 +545,10 @@ public class ResourcesManager {
     * from an {@link ApkAssetsSupplier} if non-null; otherwise ApkAssets are loaded using
     * from an {@link ApkAssetsSupplier} if non-null; otherwise ApkAssets are loaded using
     * {@link #loadApkAssets(ApkKey)}.
     * {@link #loadApkAssets(ApkKey)}.
     */
     */
    private @Nullable AssetManager createAssetManager(@NonNull final ResourcesKey key,

    @VisibleForTesting
    @UnsupportedAppUsage
    protected @Nullable AssetManager createAssetManager(@NonNull final ResourcesKey key,
            @Nullable ApkAssetsSupplier apkSupplier) {
            @Nullable ApkAssetsSupplier apkSupplier) {
        final AssetManager.Builder builder = new AssetManager.Builder();
        final AssetManager.Builder builder = new AssetManager.Builder();


+7 −1
Original line number Original line Diff line number Diff line
@@ -82,6 +82,12 @@ public class ResourcesManagerTest extends TestCase {
                return new AssetManager();
                return new AssetManager();
            }
            }


            @Override
            protected AssetManager createAssetManager(@NonNull final ResourcesKey key,
                    ResourcesManager.ApkAssetsSupplier apkSupplier) {
                return createAssetManager(key);
            }

            @Override
            @Override
            protected DisplayMetrics getDisplayMetrics(int displayId, DisplayAdjustments daj) {
            protected DisplayMetrics getDisplayMetrics(int displayId, DisplayAdjustments daj) {
                return mDisplayMetricsMap.get(displayId);
                return mDisplayMetricsMap.get(displayId);
@@ -100,7 +106,7 @@ public class ResourcesManagerTest extends TestCase {
                null, APP_ONE_RES_DIR, null, null, null, null, null, null,
                null, APP_ONE_RES_DIR, null, null, null, null, null, null,
                CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null, null);
                CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null, null);
        assertNotNull(newResources);
        assertNotNull(newResources);
        assertSame(resources, newResources);
        assertSame(resources.getImpl(), newResources.getImpl());
    }
    }


    @SmallTest
    @SmallTest