Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to lazy arguments in the components constructors #682

Open
Nikitae57 opened this issue Nov 6, 2024 · 0 comments
Open

Switch to lazy arguments in the components constructors #682

Nikitae57 opened this issue Nov 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Nikitae57
Copy link
Collaborator

Sometimes you have to manually instanciate a lot of components when you need to customize just one. For example, if you want to provide custom implementation of a systemLanguage parameter in the Kaspresso builder you have to instanciate several utility classes. Otherwise you get UninitializedPropertyException. Example below:

    Kaspresso.Builder.simple {
        testLogger = UiTestLoggerImpl(Kaspresso.DEFAULT_TEST_LOGGER_TAG)
        libLogger = UiTestLoggerImpl(Kaspresso.DEFAULT_LIB_LOGGER_TAG)
        adbServer = AdbServerImpl(LogLevel.WARN, libLogger)
        hackPermissions = HackPermissionsImpl(
            libLogger,
            instrumentalDependencyProviderFactory.getComponentProvider<HackPermissionsImpl>(instrumentation),
            adbServer
        )
        systemLanguage = SystemLanguage(instrumentation.context, testLogger, hackPermissions)
    }

Here both loggers, adbServer and hackPermissions get the default implementation - the same they would've got if we didn't customize systemLanguage value. It would be better if at least core components had the lazy arguments in their constructors so we could pass the properties without UninitializedPropertyException e.g.

open class SystemLanguage(
    private val context: Lazy<Context>,
    private val logger: Lazy<UiTestLogger>,
    private val hackPermissions: Lazy<HackPermissions>,
)

instead of the current

open class SystemLanguage(
    private val context: Context,
    private val logger: UiTestLogger,
    private val hackPermissions: HackPermissions
)

so the customization would look as follows:

    Kaspresso.Builder.simple {
        systemLanguage = SystemLanguage(
                { instrumentation.context }, 
                { testLogger }, 
                { hackPermissions },
        )
    }
@Nikitae57 Nikitae57 added the enhancement New feature or request label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant