From a83ec0e6cf1f9b33459f1d471284f141766f98d8 Mon Sep 17 00:00:00 2001 From: Nikita Evdokimov Date: Tue, 5 Nov 2024 13:08:49 +0300 Subject: [PATCH] TECH: Make language features customization easier --- .../kaspresso/device/languages/LanguageImpl.kt | 2 +- .../kaspersky/kaspresso/docloc/SystemLanguage.kt | 2 +- .../com/kaspersky/kaspresso/kaspresso/Kaspresso.kt | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt index 557961ade..76c9a9ad6 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/device/languages/LanguageImpl.kt @@ -16,7 +16,7 @@ import java.util.Locale /** * The implementation of [Language] */ -internal class LanguageImpl( +open class LanguageImpl( private val logger: UiTestLogger, private val instrumentation: Instrumentation, private val systemLanguage: SystemLanguage, diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/docloc/SystemLanguage.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/docloc/SystemLanguage.kt index 8eb4aaff9..c6f997715 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/docloc/SystemLanguage.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/docloc/SystemLanguage.kt @@ -10,7 +10,7 @@ import com.kaspersky.kaspresso.device.permissions.HackPermissions import com.kaspersky.kaspresso.logger.UiTestLogger import java.util.Locale -internal class SystemLanguage( +open class SystemLanguage( private val context: Context, private val logger: UiTestLogger, private val hackPermissions: HackPermissions diff --git a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/kaspresso/Kaspresso.kt b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/kaspresso/Kaspresso.kt index 9a17041db..dd139dcf9 100644 --- a/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/kaspresso/Kaspresso.kt +++ b/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/kaspresso/Kaspresso.kt @@ -426,6 +426,11 @@ data class Kaspresso( */ lateinit var exploit: Exploit + /** + * Holds an implementation of [SystemLanguage] interface. If it was not specified, the default implementation is used. + */ + lateinit var systemLanguage: SystemLanguage + /** * Holds an implementation of [Language] interface. If it was not specified, the default implementation is used. */ @@ -743,10 +748,10 @@ data class Kaspresso( instrumentalDependencyProviderFactory.getComponentProvider(instrumentation), adbServer ) - if (!::language.isInitialized) { - val systemLanguage = SystemLanguage(instrumentation.targetContext, testLogger, hackPermissions) - language = LanguageImpl(libLogger, instrumentation, systemLanguage) - } + + if (!::systemLanguage.isInitialized) systemLanguage = SystemLanguage(instrumentation.targetContext, testLogger, hackPermissions) + if (!::language.isInitialized) language = LanguageImpl(libLogger, instrumentation, systemLanguage) + if (!::logcat.isInitialized) logcat = LogcatImpl(libLogger, adbServer) if (!::flakySafetyParams.isInitialized) flakySafetyParams = FlakySafetyParams.default()