Skip to content

Commit

Permalink
Add tests to RepoConfiguration#merge (#279)
Browse files Browse the repository at this point in the history
AuthorConfigCsvParser#getRepoConfiguration should return existing
RepoConfiguration from a list of RepoConfigurations. Otherwise it adds
a newly created RepoConfiguration into the list and returns it.

However, due to a bug, any RepoConfigurations existing or not are added
to the list of RepoConfigurations causing duplicates.

Let's add test to RepoConfiguration#merge to prevent bugs.
  • Loading branch information
yong24s authored and eugenepeh committed Aug 3, 2018
1 parent 7b96c56 commit 939d9ba
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/reposense/parser/CsvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected List<String> getManyValueInElement(final String[] elements, int positi
}

String manyValue = getValueInElement(elements, position);
// Wrap with new ArrayList<> to make the created List is mutable.
// Wrap with new ArrayList<> to support all list functionalities.
return new ArrayList<>(Arrays.asList(manyValue.split(AUTHOR_ALIAS_AND_GLOB_SEPARATOR)));
}

Expand Down
67 changes: 67 additions & 0 deletions src/test/java/reposense/parser/CsvParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package reposense.parser;

import static org.apache.tools.ant.types.Commandline.translateCommandline;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

import reposense.model.Author;
import reposense.model.CliArguments;
import reposense.model.ConfigCliArguments;
import reposense.model.RepoConfiguration;

public class CsvParserTest {
private static final Path TEST_CONFIG_FOLDER = new File(CsvParserTest.class.getClassLoader()
.getResource("repoconfig_merge_test").getFile()).toPath();

private static final String TEST_REPO_BETA_LOCATION = "https://github.com/reposense/testrepo-Beta.git";
private static final String TEST_REPO_BETA_BRANCH = "master";

private static final Author FIRST_AUTHOR = new Author("nbriannl");
private static final Author SECOND_AUTHOR = new Author("zacharytang");

private static final List<String> REPO_LEVEL_GLOB_LIST = Arrays.asList("collated**");
private static final List<String> FIRST_AUTHOR_GLOB_LIST = Arrays.asList("collated**", "**.java");

@Test
public void merge_twoRepoConfigs_success() throws ParseException, IOException {
FIRST_AUTHOR.setIgnoreGlobList(FIRST_AUTHOR_GLOB_LIST);
SECOND_AUTHOR.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST);

List<Author> expectedAuthors = new ArrayList<>();
expectedAuthors.add(FIRST_AUTHOR);
expectedAuthors.add(SECOND_AUTHOR);

RepoConfiguration expectedConfig = new RepoConfiguration(TEST_REPO_BETA_LOCATION, TEST_REPO_BETA_BRANCH);
expectedConfig.setAuthorList(expectedAuthors);
expectedConfig.setAuthorDisplayName(FIRST_AUTHOR, "Nbr");
expectedConfig.setAuthorDisplayName(SECOND_AUTHOR, "Zac");
expectedConfig.addAuthorAliases(SECOND_AUTHOR, Arrays.asList("Zachary Tang"));
expectedConfig.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST);

String input = String.format("-config %s", TEST_CONFIG_FOLDER);
CliArguments cliArguments = ArgsParser.parse(translateCommandline(input));

List<RepoConfiguration> actualConfigs =
new RepoConfigCsvParser(((ConfigCliArguments) cliArguments).getRepoConfigFilePath()).parse();
List<RepoConfiguration> authorConfigs =
new AuthorConfigCsvParser(((ConfigCliArguments) cliArguments).getAuthorConfigFilePath()).parse();
RepoConfiguration.merge(actualConfigs, authorConfigs);

Assert.assertEquals(1, actualConfigs.size());
Assert.assertEquals(expectedConfig.getLocation(), actualConfigs.get(0).getLocation());
Assert.assertEquals(expectedConfig.getAuthorList().hashCode(), actualConfigs.get(0).getAuthorList().hashCode());
Assert.assertEquals(expectedConfig.getAuthorDisplayNameMap().hashCode(),
actualConfigs.get(0).getAuthorDisplayNameMap().hashCode());
Assert.assertEquals(expectedConfig.getAuthorAliasMap().hashCode(),
actualConfigs.get(0).getAuthorAliasMap().hashCode());
Assert.assertEquals(REPO_LEVEL_GLOB_LIST, actualConfigs.get(0).getIgnoreGlobList());
}
}
3 changes: 3 additions & 0 deletions src/test/resources/repoconfig_merge_test/author-config.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Repository's Location,Branch,Author's GitHub ID,Author's Display Name,Author's Git Author Name,Ignore Glob List
https://github.com/reposense/testrepo-Beta.git,master,nbriannl,Nbr,,**.java
https://github.com/reposense/testrepo-Beta.git,master,zacharytang,Zac,Zachary Tang,
2 changes: 2 additions & 0 deletions src/test/resources/repoconfig_merge_test/repo-config.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Repository's Location,Branch,Ignore Glob List
https://github.com/reposense/testrepo-Beta.git,master,collated**

0 comments on commit 939d9ba

Please sign in to comment.