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

Commit b88d7b2e authored by William Loh's avatar William Loh
Browse files

Clear inline mocks in MockSystemRule

Fix memory leaks in tests that use MockSystemRule. See
https://github.com/mockito/mockito/issues/1614 for more information on
what is causing the memory leaks.

This will not address all the memory leaks in
FrameworksMockingServicesTests since there are many other tests that
does not use MockSystemRule but does use ExtendedMockito that still
needs to be fixed.

Bug: 300996262
Test: atest
Change-Id: I6d78b677b52b1b9a07c95f73d9d393604b29f393
parent 44261334
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -505,8 +505,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
        pkg: ParsingPackage,
        applicationInfo: ApplicationInfo?,
        className: String?
    ):
            ActivityInfo {
    ): ActivityInfo {
        val activityInfo = ActivityInfo()
        activityInfo.applicationInfo = applicationInfo
        activityInfo.packageName = pkg.packageName
@@ -518,8 +517,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
        pkg: ParsingPackage,
        applicationInfo: ApplicationInfo?,
        className: String?
    ):
            ServiceInfo {
    ): ServiceInfo {
        val serviceInfo = ServiceInfo()
        serviceInfo.applicationInfo = applicationInfo
        serviceInfo.packageName = pkg.packageName
@@ -699,8 +697,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
    /** Override get*Folder methods to point to temporary local directories  */

    @Throws(IOException::class)
    private fun redirectScanPartitions(partitions: List<ScanPartition>):
            List<ScanPartition> {
    private fun redirectScanPartitions(partitions: List<ScanPartition>): List<ScanPartition> {
        val spiedPartitions: MutableList<ScanPartition> =
                ArrayList(partitions.size)
        for (partition: ScanPartition in partitions) {
@@ -732,6 +729,7 @@ class MockSystemRule : TestRule {
            } finally {
                mockSystem?.cleanup()
                mockSystem = null
                Mockito.framework().clearInlineMocks()
            }
        }
    }