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

RepoConfigurationTest: Simplify code in repoConfig_ignoresStandaloneConfig_success test case #962

Open
anubh-v opened this issue Dec 10, 2019 · 3 comments

Comments

@anubh-v
Copy link
Contributor

anubh-v commented Dec 10, 2019

The code snippet below shows the repoConfig_ignoresStandaloneConfig_success test case.
In lines 153 - 157, we parse some input to create a list of RepoConfiguration objects.

@Test
public void repoConfig_ignoresStandaloneConfig_success()
throws ParseException, GitCloneException, IOException, HelpScreenException {
List<Author> expectedAuthors = new ArrayList<>();
Author author = new Author(FIRST_AUTHOR);
author.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST);
expectedAuthors.add(author);
RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master");
expectedConfig.setAuthorList(expectedAuthors);
expectedConfig.addAuthorEmailsAndAliasesMapEntry(author, FIRST_AUTHOR_ALIASES);
expectedConfig.setAuthorDisplayName(author, "Ahm");
expectedConfig.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST);
expectedConfig.setFormats(CONFIG_FORMATS);
expectedConfig.setStandaloneConfigIgnored(true);
String formats = String.join(" ", CLI_FORMATS);
String input = new InputBuilder().addConfig(IGNORE_STANDALONE_TEST_CONFIG_FILES)
.addFormats(formats)
.build();
CliArguments cliArguments = ArgsParser.parse(translateCommandline(input));
List<RepoConfiguration> actualConfigs =
new RepoConfigCsvParser(((ConfigCliArguments) cliArguments).getRepoConfigFilePath()).parse();
List<AuthorConfiguration> authorConfigs =
new AuthorConfigCsvParser(((ConfigCliArguments) cliArguments).getAuthorConfigFilePath()).parse();
RepoConfiguration.merge(actualConfigs, authorConfigs);
RepoConfiguration actualConfig = actualConfigs.get(0);
GitClone.clone(actualConfig);
ReportGenerator.updateRepoConfig(actualConfig);
TestUtil.compareRepoConfig(expectedConfig, actualConfig);
}

The lines 153 - 157 can be replaced with the line below:

List<RepoConfiguration> actualConfigs = RepoSense.getRepoConfigurations((ConfigCliArguments) cliArguments);

It seems that the lines 153 - 157 are duplicating the same work done in the getRepoConfigurations method of the RepoSense class.

Please let me know if I'm misunderstanding something here.

@anubh-v anubh-v changed the title RepoConfigurationTest: Code in repoConfig_ignoresStandaloneConfig_success test case can be simplified RepoConfigurationTest: Simplify code in repoConfig_ignoresStandaloneConfig_success test case Dec 10, 2019
@fzdy1914
Copy link
Member

Yes, it is duplicating some parts of the method. However, I believe it is necessary.

  1. This is the unit test for RepoConfiguration. Apart from the method directly from the class itself, we should use the minimum outside method. Even if we have to use, we should use the lower abstraction one. So, the change of other classes and other methods will infect this unit test minimally. A unit test is meant to test the behavior of this specific class.
  2. Looking to the method itself, also it is longer than just use RepoSense::getRepoConfigurations, however, it only uses highly related one and the class method. RepoSense::getRepoConfigurations is an outsider method with high abstraction, we certainly do not want the change of this method will affect the unit test of other models.

@anubh-v
Copy link
Contributor Author

anubh-v commented Dec 12, 2019

Thanks for the response @fzdy1914.

It makes sense that it may not be a good idea to use RepoSense::getRepoConfigurations in a test because future changes to this method would affect the test.

In that case, perhaps we should edit the repoConfig_ignoresStandaloneConfigInCli_success test case, since it uses the RepoSense::getRepoConfigurations method ? (see line 179 in snippet below)

public void repoConfig_ignoresStandaloneConfigInCli_success()
throws ParseException, GitCloneException, HelpScreenException {
RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master");
expectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS));
expectedConfig.setStandaloneConfigIgnored(true);
String formats = String.join(" ", CLI_FORMATS);
String input = new InputBuilder().addRepos(TEST_REPO_DELTA)
.addFormats(formats)
.addIgnoreStandaloneConfig()
.build();
CliArguments cliArguments = ArgsParser.parse(translateCommandline(input));
List<RepoConfiguration> actualConfigs = RepoSense.getRepoConfigurations((LocationsCliArguments) cliArguments);
RepoConfiguration.setFormatsToRepoConfigs(actualConfigs, cliArguments.getFormats());
RepoConfiguration actualConfig = actualConfigs.get(0);
GitClone.clone(actualConfig);
ReportGenerator.updateRepoConfig(actualConfig);
TestUtil.compareRepoConfig(expectedConfig, actualConfig);
}

@fzdy1914
Copy link
Member

@anubh-v True, it is better not to use this method. When I wrote this method previously, I should forget to take it into account.

However, it may be an overkill to create a separate PR for just fixing this issue. Maybe you can consider sneaking in the code when toughing this file in other related PR.

@dcshzj dcshzj moved this to For existing developers in RepoSense Roadmap Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: For developers
Development

No branches or pull requests

2 participants