diff --git a/src/main/java/reposense/model/RepoConfiguration.java b/src/main/java/reposense/model/RepoConfiguration.java index 29a10d60a7..abddab0c4c 100644 --- a/src/main/java/reposense/model/RepoConfiguration.java +++ b/src/main/java/reposense/model/RepoConfiguration.java @@ -35,8 +35,8 @@ public class RepoConfiguration { private transient String repoFolderName; private transient FileTypeManager fileTypeManager; - private transient List ignoreGlobList = new ArrayList<>(); - private transient List ignoredAuthorsList = new ArrayList<>(); + private transient List ignoreGlobList; + private transient List ignoredAuthorsList; private transient AuthorConfiguration authorConfig; private transient boolean isStandaloneConfigIgnored; private transient boolean isFileSizeLimitIgnored; @@ -88,8 +88,8 @@ private RepoConfiguration(RepoBuilder repoBuilder) { processAuthor(); processBranch(); - processNames(); - processOrganization(); + processNames(repoBuilder); + processOrganization(repoBuilder); } /** @@ -109,24 +109,36 @@ private void processBranch() { /** * Processes the relevant names of the repository configs. */ - private void processNames() { + private void processNames(RepoBuilder repoBuilder) { String repoName = this.location.getRepoName(); - this.displayName = repoName + "[" + this.branch + "]"; - this.outputFolderName = repoName + "_" + this.branch; - this.repoFolderName = repoName; + this.displayName = repoBuilder.displayName == null + ? repoName + "[" + this.branch + "]" + : repoBuilder.displayName; + this.outputFolderName = repoBuilder.outputFolderName == null + ? repoName + "_" + this.branch + : repoBuilder.outputFolderName; + this.repoFolderName = repoBuilder.repoFolderName == null + ? repoName + : repoBuilder.repoFolderName; } /** * Processes the organization name of the repository and updates the relevant * names of the repository configs. */ - private void processOrganization() { + private void processOrganization(RepoBuilder repoBuilder) { String org = location.getOrganization(); if (!org.isEmpty()) { - this.repoFolderName = org + "_" + this.repoFolderName; - this.displayName = org + "/" + this.displayName; - this.outputFolderName = org + "_" + this.outputFolderName; + this.repoFolderName = repoBuilder.repoFolderName == null + ? org + "_" + this.repoFolderName + : repoBuilder.repoFolderName; + this.displayName = repoBuilder.displayName == null + ? org + "/" + this.displayName + : repoBuilder.displayName; + this.outputFolderName = repoBuilder.outputFolderName == null + ? org + "_" + this.outputFolderName + : repoBuilder.outputFolderName; } } @@ -270,11 +282,11 @@ public RepoBuilder repoFolderName(String repoFolderName) { /** * Updates the {@code fileTypeManager} for {@code RepoConfiguration}. * - * @param fileTypeManager List of file types and groupings permitted. + * @param fileTypes List of file types and groupings permitted. * @return This builder object. */ - public RepoBuilder fileTypeManager(FileTypeManager fileTypeManager) { - this.fileTypeManager = fileTypeManager; + public RepoBuilder fileTypeManager(List fileTypes) { + this.fileTypeManager = new FileTypeManager(fileTypes); return this; } diff --git a/src/main/java/reposense/parser/RepoConfigCsvParser.java b/src/main/java/reposense/parser/RepoConfigCsvParser.java index 4a084d31a9..8d8e36b722 100644 --- a/src/main/java/reposense/parser/RepoConfigCsvParser.java +++ b/src/main/java/reposense/parser/RepoConfigCsvParser.java @@ -8,7 +8,6 @@ import reposense.model.CommitHash; import reposense.model.FileType; -import reposense.model.FileTypeManager; import reposense.model.RepoConfiguration; import reposense.model.RepoLocation; import reposense.util.FileUtil; @@ -175,7 +174,7 @@ private void addConfig(List results, RepoLocation location, S RepoConfiguration config = new RepoConfiguration.RepoBuilder() .location(location) .branch(branch) - .fileTypeManager(new FileTypeManager(formats)) + .fileTypeManager(formats) .ignoreGlobList(ignoreGlobList) .fileSizeLimit(fileSizeLimit) .isStandaloneConfigIgnored(isStandaloneConfigIgnored) diff --git a/src/test/java/reposense/model/RepoConfigurationTest.java b/src/test/java/reposense/model/RepoConfigurationTest.java index 768fdec902..fe7aa998b6 100644 --- a/src/test/java/reposense/model/RepoConfigurationTest.java +++ b/src/test/java/reposense/model/RepoConfigurationTest.java @@ -5,6 +5,8 @@ import java.lang.reflect.Method; import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -741,7 +743,7 @@ public void repoConfig_overrideStandaloneConfig_success() throws Exception { RepoConfiguration expectedConfig = new RepoConfiguration.RepoBuilder() .location(new RepoLocation(TEST_REPO_DELTA)) .branch("master") - .fileTypeManager(new FileTypeManager(Collections.emptyList())) + .fileTypeManager(Collections.emptyList()) .ignoreGlobList(Collections.emptyList()) .fileSizeLimit(RepoConfiguration.DEFAULT_FILE_SIZE_LIMIT) .isStandaloneConfigIgnored(false) @@ -858,4 +860,98 @@ public void repoConfig_removeIgnoredAuthors_success() throws Exception { TestUtil.compareRepoConfig(expectedConfig, actualConfig); } + + @Test + public void repoBuilder_displayName_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .displayName("CS3281") + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getDisplayName(), "CS3281"); + } + + @Test + public void repoBuilder_outputFolderName_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .outputFolderName("CS3281 Folder") + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getOutputFolderName(), "CS3281 Folder"); + } + + @Test + public void repoBuilder_repoFolderName_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .repoFolderName("CS3281 Folder") + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getRepoFolderName(), "CS3281 Folder"); + } + + @Test + public void repoBuilder_zoneID_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .zoneId(ZoneId.systemDefault()) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getZoneId(), ZoneId.systemDefault()); + } + + @Test + public void repoBuilder_sinceDate_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .sinceDate(LocalDateTime.of(2024, 1, 1, 12, 0, 0)) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getSinceDate(), + LocalDateTime.of(2024, 1, 1, 12, 0, 0)); + } + + @Test + public void repoBuilder_untilDate_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .untilDate(LocalDateTime.of(2024, 1, 1, 12, 0, 0)) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getUntilDate(), + LocalDateTime.of(2024, 1, 1, 12, 0, 0)); + } + + @Test + public void repoBuilder_authorConfig_success() throws Exception { + RepoLocation loc = new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG); + String branch = "master"; + + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .authorConfig(new AuthorConfiguration(loc, branch)) + .location(loc) + .branch(branch) + .build(); + + Assertions.assertEquals(actualConfig.getAuthorConfig(), + new AuthorConfiguration(loc, branch)); + } + + @Test + public void repoBuilder_isLastModifiedDateIncluded_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.RepoBuilder() + .isLastModifiedDateIncluded(true) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertTrue(actualConfig.isLastModifiedDateIncluded()); + } }