1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.systemui.keyguard.domain.interactor 18 19 import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository 20 import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository 21 import com.android.systemui.util.mockito.mock 22 import dagger.Lazy 23 import kotlinx.coroutines.CoroutineScope 24 25 /** 26 * Helper to create a new KeyguardTransitionInteractor in a way that doesn't require modifying 20+ 27 * tests whenever we add a constructor param. 28 */ 29 object KeyguardTransitionInteractorFactory { 30 @JvmOverloads 31 @JvmStatic 32 fun create( 33 scope: CoroutineScope, 34 repository: KeyguardTransitionRepository = FakeKeyguardTransitionRepository(), 35 keyguardInteractor: KeyguardInteractor = 36 KeyguardInteractorFactory.create().keyguardInteractor, 37 fromLockscreenTransitionInteractor: Lazy<FromLockscreenTransitionInteractor> = Lazy { 38 mock<FromLockscreenTransitionInteractor>() 39 }, 40 fromPrimaryBouncerTransitionInteractor: Lazy<FromPrimaryBouncerTransitionInteractor> = 41 Lazy { 42 mock<FromPrimaryBouncerTransitionInteractor>() 43 }, 44 ): WithDependencies { 45 return WithDependencies( 46 repository = repository, 47 keyguardInteractor = keyguardInteractor, 48 fromLockscreenTransitionInteractor = fromLockscreenTransitionInteractor, 49 fromPrimaryBouncerTransitionInteractor = fromPrimaryBouncerTransitionInteractor, 50 KeyguardTransitionInteractor( 51 scope = scope, 52 repository = repository, 53 keyguardInteractor = { keyguardInteractor }, 54 fromLockscreenTransitionInteractor = fromLockscreenTransitionInteractor, 55 fromPrimaryBouncerTransitionInteractor = fromPrimaryBouncerTransitionInteractor, 56 ) 57 ) 58 } 59 60 data class WithDependencies( 61 val repository: KeyguardTransitionRepository, 62 val keyguardInteractor: KeyguardInteractor, 63 val fromLockscreenTransitionInteractor: Lazy<FromLockscreenTransitionInteractor>, 64 val fromPrimaryBouncerTransitionInteractor: Lazy<FromPrimaryBouncerTransitionInteractor>, 65 val keyguardTransitionInteractor: KeyguardTransitionInteractor, 66 ) 67 } 68