-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to RepoConfiguration#merge (#279)
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
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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** |