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

Commit b25e5b14 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Remove CommunalTutorialInteractorFactory" into main

parents b8e91f3d 5770e1f2
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -24,13 +24,17 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.data.repository.FakeCommunalRepository
import com.android.systemui.communal.data.repository.FakeCommunalTutorialRepository
import com.android.systemui.communal.data.repository.fakeCommunalRepository
import com.android.systemui.communal.data.repository.fakeCommunalTutorialRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.kosmos.testScope
import com.android.systemui.settings.UserTracker
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
@@ -41,10 +45,11 @@ import org.mockito.MockitoAnnotations
@SmallTest
@RunWith(AndroidJUnit4::class)
class CommunalTutorialInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

    @Mock private lateinit var userTracker: UserTracker

    private lateinit var testScope: TestScope
    private lateinit var underTest: CommunalTutorialInteractor
    private lateinit var keyguardRepository: FakeKeyguardRepository
    private lateinit var communalTutorialRepository: FakeCommunalTutorialRepository
@@ -54,14 +59,11 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)

        testScope = TestScope()
        keyguardRepository = kosmos.fakeKeyguardRepository
        communalTutorialRepository = kosmos.fakeCommunalTutorialRepository
        communalRepository = kosmos.fakeCommunalRepository

        val withDeps = CommunalTutorialInteractorFactory.create(testScope)
        keyguardRepository = withDeps.keyguardRepository
        communalTutorialRepository = withDeps.communalTutorialRepository
        communalRepository = withDeps.communalRepository

        underTest = withDeps.communalTutorialInteractor
        underTest = kosmos.communalTutorialInteractor

        whenever(userTracker.userHandle).thenReturn(mock())
    }
+16 −9
Original line number Diff line number Diff line
@@ -26,10 +26,12 @@ import com.android.systemui.communal.widgets.CommunalAppWidgetHost
import com.android.systemui.communal.widgets.EditWidgetsActivityStarter
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory
import com.android.systemui.smartspace.data.repository.FakeSmartspaceRepository
import com.android.systemui.util.mockito.mock
import kotlinx.coroutines.test.TestScope

// TODO(b/319335645): get rid of me and use kosmos.
object CommunalInteractorFactory {

    @JvmOverloads
@@ -38,6 +40,7 @@ object CommunalInteractorFactory {
        testScope: TestScope = TestScope(),
        communalRepository: FakeCommunalRepository =
            FakeCommunalRepository(testScope.backgroundScope),
        keyguardRepository: FakeKeyguardRepository = FakeKeyguardRepository(),
        widgetRepository: FakeCommunalWidgetRepository =
            FakeCommunalWidgetRepository(testScope.backgroundScope),
        mediaRepository: FakeCommunalMediaRepository = FakeCommunalMediaRepository(),
@@ -47,12 +50,16 @@ object CommunalInteractorFactory {
        appWidgetHost: CommunalAppWidgetHost = mock(),
        editWidgetsActivityStarter: EditWidgetsActivityStarter = mock(),
    ): WithDependencies {
        val withDeps =
            CommunalTutorialInteractorFactory.create(
                testScope = testScope,
                communalTutorialRepository = tutorialRepository,
                communalRepository = communalRepository,
        val keyguardInteractor =
            KeyguardInteractorFactory.create(repository = keyguardRepository).keyguardInteractor
        val communalTutorialInteractor =
            CommunalTutorialInteractor(
                testScope.backgroundScope,
                tutorialRepository,
                keyguardInteractor,
                communalRepository,
            )

        return WithDependencies(
            testScope,
            communalRepository,
@@ -61,9 +68,9 @@ object CommunalInteractorFactory {
            mediaRepository,
            smartspaceRepository,
            tutorialRepository,
            withDeps.keyguardRepository,
            withDeps.keyguardInteractor,
            withDeps.communalTutorialInteractor,
            keyguardRepository,
            keyguardInteractor,
            communalTutorialInteractor,
            appWidgetHost,
            editWidgetsActivityStarter,
            CommunalInteractor(
@@ -73,7 +80,7 @@ object CommunalInteractorFactory {
                communalPrefsRepository,
                mediaRepository,
                smartspaceRepository,
                withDeps.keyguardInteractor,
                keyguardInteractor,
                appWidgetHost,
                editWidgetsActivityStarter,
            ),
+0 −67
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.communal.domain.interactor

import com.android.systemui.communal.data.repository.FakeCommunalRepository
import com.android.systemui.communal.data.repository.FakeCommunalTutorialRepository
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory
import kotlinx.coroutines.test.TestScope

object CommunalTutorialInteractorFactory {

    @JvmOverloads
    @JvmStatic
    fun create(
        testScope: TestScope,
        communalTutorialRepository: FakeCommunalTutorialRepository =
            FakeCommunalTutorialRepository(),
        communalRepository: FakeCommunalRepository =
            FakeCommunalRepository(applicationScope = testScope.backgroundScope),
        keyguardRepository: FakeKeyguardRepository = FakeKeyguardRepository(),
        keyguardInteractor: KeyguardInteractor =
            KeyguardInteractorFactory.create(
                    repository = keyguardRepository,
                )
                .keyguardInteractor
    ): WithDependencies {
        return WithDependencies(
            testScope = testScope,
            communalRepository = communalRepository,
            communalTutorialRepository = communalTutorialRepository,
            keyguardRepository = keyguardRepository,
            keyguardInteractor = keyguardInteractor,
            communalTutorialInteractor =
                CommunalTutorialInteractor(
                    testScope.backgroundScope,
                    communalTutorialRepository,
                    keyguardInteractor,
                    communalRepository,
                )
        )
    }

    data class WithDependencies(
        val testScope: TestScope,
        val communalRepository: FakeCommunalRepository,
        val communalTutorialRepository: FakeCommunalTutorialRepository,
        val keyguardRepository: FakeKeyguardRepository,
        val keyguardInteractor: KeyguardInteractor,
        val communalTutorialInteractor: CommunalTutorialInteractor,
    )
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.communal.domain.interactor

import com.android.systemui.communal.data.repository.communalRepository
import com.android.systemui.communal.data.repository.communalTutorialRepository
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope

val Kosmos.communalTutorialInteractor by
    Kosmos.Fixture {
        CommunalTutorialInteractor(
            scope = applicationCoroutineScope,
            communalTutorialRepository = communalTutorialRepository,
            keyguardInteractor = keyguardInteractor,
            communalRepository = communalRepository,
        )
    }