Skip to content

Commit

Permalink
Fix bugs and implement new unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
georgetayqy committed Jan 30, 2024
1 parent be1ef45 commit ae80634
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 18 deletions.
42 changes: 27 additions & 15 deletions src/main/java/reposense/model/RepoConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class RepoConfiguration {
private transient String repoFolderName;

private transient FileTypeManager fileTypeManager;
private transient List<String> ignoreGlobList = new ArrayList<>();
private transient List<String> ignoredAuthorsList = new ArrayList<>();
private transient List<String> ignoreGlobList;
private transient List<String> ignoredAuthorsList;
private transient AuthorConfiguration authorConfig;
private transient boolean isStandaloneConfigIgnored;
private transient boolean isFileSizeLimitIgnored;
Expand Down Expand Up @@ -88,8 +88,8 @@ private RepoConfiguration(RepoBuilder repoBuilder) {

processAuthor();
processBranch();
processNames();
processOrganization();
processNames(repoBuilder);
processOrganization(repoBuilder);
}

/**
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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<FileType> fileTypes) {
this.fileTypeManager = new FileTypeManager(fileTypes);
return this;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/reposense/parser/RepoConfigCsvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,7 +174,7 @@ private void addConfig(List<RepoConfiguration> 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)
Expand Down
98 changes: 97 additions & 1 deletion src/test/java/reposense/model/RepoConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
}
}

0 comments on commit ae80634

Please sign in to comment.