Skip to content

[refactor] Find a better way for faking dependency injection #7

@b-pos465

Description

@b-pos465

jQAssistant does not have a mechanism for dependency injection. This can make testing difficult.

The JiraRestClientWrapper is an abstraction layer which helps to mock requests to Jira while testing. The corresponding class is named MockedJiraRestClientWrapper. Unfortunately, there is no dependency injection in jQAssistant. Therefore, we use ENV to decide which implementation shall be used:

 if (System.getenv(TEST_ENV) != null) {
            return (JiraRestClientWrapper) GraphBuilder.class
                    .getClassLoader()
                    .loadClass("org.jqassistant.contrib.plugin.jira.jjrc.MockedJiraRestClientWrapper")
                    .newInstance();
        } else {
            return new DefaultJiraRestClientWrapper(url, username, password);
        }

This is obviously a bad solution. The ENV is set inside the JVM by the EnvironmentOverrider. The code has been taken from https://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java.

Maybe using a system property could be a little bit cleaner. Maybe there is an even another solution which would be much better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions