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

Commit e7a8dad0 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge "Prevent NPE in ControlsListingControllerImpl" into rvc-dev am: 976c089f am: eba46a76

Change-Id: I36a80f010012add7cb624713162603b64c65fe2d
parents a08b5b47 eba46a76
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
    )

    private var serviceListing = serviceListingBuilder(context)
    // All operations in background thread
    private val callbacks = mutableSetOf<ControlsListingController.ControlsListingCallback>()

    companion object {
        private const val TAG = "ControlsListingControllerImpl"
@@ -116,9 +118,6 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
        }
    }

    // All operations in background thread
    private val callbacks = mutableSetOf<ControlsListingController.ControlsListingCallback>()

    /**
     * Adds a callback to this controller.
     *
+17 −0
Original line number Diff line number Diff line
@@ -38,10 +38,12 @@ import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.mockito.Mockito.inOrder
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import java.util.concurrent.Executor

@SmallTest
@RunWith(AndroidTestingRunner::class)
@@ -103,6 +105,21 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
        verify(mockSL).reload()
    }

    @Test
    fun testImmediateListingReload_doesNotCrash() {
        val exec = Executor { it.run() }
        val mockServiceListing = mock(ServiceListing::class.java)
        var callback: ServiceListing.Callback? = null
        `when`(mockServiceListing.addCallback(any<ServiceListing.Callback>())).then {
            callback = it.getArgument(0)
            Unit
        }
        `when`(mockServiceListing.reload()).then {
            callback?.onServicesReloaded(listOf(serviceInfo))
        }
        ControlsListingControllerImpl(mContext, exec, { mockServiceListing })
    }

    @Test
    fun testStartsOnUser() {
        assertEquals(user, controller.currentUserId)