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

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

Open
b-pos465 opened this issue Aug 27, 2019 · 1 comment
Open

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

b-pos465 opened this issue Aug 27, 2019 · 1 comment

Comments

@b-pos465
Copy link
Member

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.

@DirkMahler
Copy link

DirkMahler commented Nov 2, 2019

#10 replaces this by a system property taking the class name of the JiraRestClientWrapper implementation to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants