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 
18 package com.android.systemui.keyguard.domain.interactor
19 
20 import com.android.systemui.bouncer.data.repository.FakeKeyguardBouncerRepository
21 import com.android.systemui.common.ui.data.repository.FakeConfigurationRepository
22 import com.android.systemui.flags.FakeFeatureFlags
23 import com.android.systemui.flags.Flags
24 import com.android.systemui.keyguard.data.repository.FakeCommandQueue
25 import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
26 
27 /**
28  * Simply put, I got tired of adding a constructor argument and then having to tweak dozens of
29  * files. This should alleviate some of the burden by providing defaults for testing.
30  */
31 object KeyguardInteractorFactory {
32 
33     @JvmOverloads
34     @JvmStatic
35     fun create(
36         featureFlags: FakeFeatureFlags = createFakeFeatureFlags(),
37         repository: FakeKeyguardRepository = FakeKeyguardRepository(),
38         commandQueue: FakeCommandQueue = FakeCommandQueue(),
39         bouncerRepository: FakeKeyguardBouncerRepository = FakeKeyguardBouncerRepository(),
40         configurationRepository: FakeConfigurationRepository = FakeConfigurationRepository(),
41     ): WithDependencies {
42         return WithDependencies(
43             repository = repository,
44             commandQueue = commandQueue,
45             featureFlags = featureFlags,
46             bouncerRepository = bouncerRepository,
47             configurationRepository = configurationRepository,
48             KeyguardInteractor(
49                 repository = repository,
50                 commandQueue = commandQueue,
51                 featureFlags = featureFlags,
52                 bouncerRepository = bouncerRepository,
53                 configurationRepository = configurationRepository,
54             )
55         )
56     }
57 
58     /** Provide defaults, otherwise tests will throw an error */
59     fun createFakeFeatureFlags(): FakeFeatureFlags {
60         return FakeFeatureFlags().apply { set(Flags.FACE_AUTH_REFACTOR, false) }
61     }
62 
63     data class WithDependencies(
64         val repository: FakeKeyguardRepository,
65         val commandQueue: FakeCommandQueue,
66         val featureFlags: FakeFeatureFlags,
67         val bouncerRepository: FakeKeyguardBouncerRepository,
68         val configurationRepository: FakeConfigurationRepository,
69         val keyguardInteractor: KeyguardInteractor,
70     )
71 }
72