Skip to content

Commit 697c593

Browse files
committed
Fix cypress test and add tests for code coverage
1 parent aa1c2e7 commit 697c593

9 files changed

+305
-25
lines changed

config/report-config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ repos:
2222
author-git-author-name: Francis Hodianto
2323
author-emails:
2424
ignore-authors-list:
25+
- bot
26+
ignore-glob-list:
27+
- "**.md"
28+
file-size-limit: 2000000
+1-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1 @@
1-
title: RepoSense Report
2-
repos:
3-
- repo: https://github.com/reposense/testrepo-Delta.git
4-
groups:
5-
- group-name: code
6-
globs:
7-
- "**.java"
8-
- group-name: tests
9-
globs:
10-
- "src/test**"
11-
- group-name: docs
12-
globs:
13-
- "docs**"
14-
- "**.adoc"
15-
- "**.md"
16-
branches:
17-
- branch: master
18-
blurb: "My project"
19-
authors:
20-
- author-git-host-id: FH-30
21-
author-display-name: Francis Hodianto
22-
author-git-author-name: Francis Hodianto
23-
author-emails:
24-
ignore-authors-list:
1+
title: RepoSense Test Report
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package reposense.model;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
8+
9+
import reposense.model.reportconfig.ReportAuthorDetails;
10+
import reposense.model.reportconfig.ReportBranchData;
11+
import reposense.model.reportconfig.ReportConfiguration;
12+
import reposense.model.reportconfig.ReportGroupNameAndGlobs;
13+
import reposense.model.reportconfig.ReportRepoConfiguration;
14+
import reposense.parser.exceptions.InvalidLocationException;
15+
16+
class OneStopConfigRunConfigurationTest {
17+
18+
private static CliArguments testCliArguments;
19+
private static List<RepoConfiguration> expectedRepoConfigurations;
20+
21+
public static void setUpTestCliArguments() {
22+
CliArguments.Builder testCliBuilder = new CliArguments.Builder();
23+
24+
List<String> globPatterns = List.of("**.java");
25+
List<ReportGroupNameAndGlobs> groups = List.of(new ReportGroupNameAndGlobs("code", globPatterns));
26+
27+
List<String> emailList = List.of("[email protected]");
28+
ReportAuthorDetails author = new ReportAuthorDetails(emailList, "FH-30",
29+
"Francis Hodianto", "Francis Hodianto");
30+
31+
List<ReportAuthorDetails> authorList = List.of(author);
32+
List<String> ignoreGlobList = List.of("**.md");
33+
List<String> ignoreAuthorList = List.of("bot");
34+
ReportBranchData branch = new ReportBranchData("master", "My project", authorList,
35+
ignoreGlobList, ignoreAuthorList, 2000000L);
36+
37+
List<ReportBranchData> branches = List.of(branch);
38+
ReportRepoConfiguration repo = new ReportRepoConfiguration("https://github.com/reposense/testrepo-Delta.git",
39+
groups, branches);
40+
41+
List<ReportRepoConfiguration> repos = List.of(repo);
42+
ReportConfiguration expectedReportConfig = new ReportConfiguration("Test RepoSense Report", repos);
43+
testCliBuilder.reportConfiguration(expectedReportConfig);
44+
testCliArguments = testCliBuilder.build();
45+
}
46+
47+
public static void setUpExpectedRepoConfigurations() throws InvalidLocationException {
48+
expectedRepoConfigurations = new ArrayList<>();
49+
RepoLocation expectedRepoLocation = new RepoLocation("https://github.com/reposense/testrepo-Delta.git");
50+
List<AuthorConfiguration> authorConfigs = new ArrayList<>();
51+
List<GroupConfiguration> groupConfigs = new ArrayList<>();
52+
53+
RepoConfiguration.Builder builder = new RepoConfiguration.Builder()
54+
.location(expectedRepoLocation)
55+
.branch("master")
56+
.ignoreGlobList(List.of("**.md"))
57+
.ignoredAuthorsList(List.of("bot"))
58+
.fileSizeLimit(2000000L)
59+
// Needs to be removed this when we deprecate the standalone config
60+
.isStandaloneConfigIgnored(true);
61+
62+
expectedRepoConfigurations.add(builder.build());
63+
64+
GroupConfiguration groupConfiguration = new GroupConfiguration(expectedRepoLocation);
65+
groupConfiguration.addGroup(new FileType("code", List.of("**.java")));
66+
67+
groupConfigs.add(groupConfiguration);
68+
69+
Author author = new Author("FH-30");
70+
author.setEmails(List.of("[email protected]"));
71+
author.setDisplayName("Francis Hodianto");
72+
author.setAuthorAliases(List.of("Francis Hodianto"));
73+
74+
AuthorConfiguration authorConfiguration = new AuthorConfiguration(expectedRepoLocation, "master");
75+
authorConfiguration.addAuthor(author);
76+
authorConfigs.add(authorConfiguration);
77+
78+
RepoConfiguration.merge(expectedRepoConfigurations, authorConfigs);
79+
RepoConfiguration.setGroupConfigsToRepos(expectedRepoConfigurations, groupConfigs);
80+
}
81+
82+
@Test
83+
public void getRepoConfigurations_withValidInputs_returnsRepoConfigurations() throws InvalidLocationException {
84+
setUpTestCliArguments();
85+
setUpExpectedRepoConfigurations();
86+
87+
OneStopConfigRunConfiguration config = new OneStopConfigRunConfiguration(testCliArguments);
88+
List<RepoConfiguration> actualRepoConfigurations = config.getRepoConfigurations();
89+
Assertions.assertEquals(expectedRepoConfigurations, actualRepoConfigurations);
90+
}
91+
}

src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java

+38
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,42 @@ public void constructor_nullGitHostId_throwsIllegalArgumentException() {
3333
);
3434
});
3535
}
36+
37+
@Test
38+
public void equals_sameObject_success() {
39+
ReportAuthorDetails details1 = new ReportAuthorDetails(
40+
List.of("[email protected]"),
41+
"gitHostId",
42+
"Display Name",
43+
"Git Author"
44+
);
45+
46+
ReportAuthorDetails details2 = new ReportAuthorDetails(
47+
List.of("[email protected]"),
48+
"gitHostId",
49+
"Display Name",
50+
"Git Author"
51+
);
52+
53+
Assertions.assertEquals(details1, details2);
54+
}
55+
56+
@Test
57+
public void equals_differentObject_failure() {
58+
ReportAuthorDetails details1 = new ReportAuthorDetails(
59+
List.of("[email protected]"),
60+
"gitHostId",
61+
"Display Name",
62+
"Git Author"
63+
);
64+
65+
ReportAuthorDetails details2 = new ReportAuthorDetails(
66+
List.of("[email protected]"),
67+
"gitHostId",
68+
"Display Name",
69+
"Git Author"
70+
);
71+
72+
Assertions.assertNotEquals(details1, details2);
73+
}
3674
}

src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java

+46
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,50 @@ public void constructor_withNullInputs_shouldUseDefaultValues() {
3737
Assertions.assertEquals(new ArrayList<>(), data.getIgnoreAuthorList());
3838
Assertions.assertEquals(ReportBranchData.DEFAULT_FILE_SIZE_LIMIT, data.getFileSizeLimit());
3939
}
40+
41+
@Test
42+
public void equals_sameObject_success() {
43+
ReportBranchData data1 = new ReportBranchData(
44+
"main",
45+
"Test blurb",
46+
null,
47+
List.of("*.log"),
48+
List.of("bot"),
49+
2000000L
50+
);
51+
52+
ReportBranchData data2 = new ReportBranchData(
53+
"main",
54+
"Test blurb",
55+
null,
56+
List.of("*.log"),
57+
List.of("bot"),
58+
2000000L
59+
);
60+
61+
Assertions.assertEquals(data1, data2);
62+
}
63+
64+
@Test
65+
public void equals_differentObject_failure() {
66+
ReportBranchData data1 = new ReportBranchData(
67+
"main",
68+
"Test blurb",
69+
null,
70+
List.of("*.log"),
71+
List.of("bot"),
72+
2000000L
73+
);
74+
75+
ReportBranchData data2 = new ReportBranchData(
76+
"master",
77+
"Test blurb",
78+
null,
79+
List.of("*.log"),
80+
List.of("bot"),
81+
2000000L
82+
);
83+
84+
Assertions.assertNotEquals(data1, data2);
85+
}
4086
}

src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
package reposense.model.reportconfig;
22

33
import java.util.ArrayList;
4+
import java.util.List;
45

56
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.BeforeAll;
68
import org.junit.jupiter.api.Test;
79

10+
import reposense.model.BlurbMap;
11+
812
public class ReportConfigurationTest {
13+
14+
private static ReportConfiguration expectedReportConfig;
15+
16+
@BeforeAll
17+
public static void setUp() {
18+
List<String> globPatterns = List.of("**.java");
19+
List<ReportGroupNameAndGlobs> groups = List.of(new ReportGroupNameAndGlobs("code", globPatterns));
20+
21+
List<String> emailList = List.of("[email protected]");
22+
ReportAuthorDetails author = new ReportAuthorDetails(emailList, "FH-30",
23+
"Francis Hodianto", "Francis Hodianto");
24+
25+
List<ReportAuthorDetails> authorList = List.of(author);
26+
List<String> ignoreGlobList = List.of("**.md");
27+
List<String> ignoreAuthorList = List.of("bot");
28+
ReportBranchData branch = new ReportBranchData("master", "My project", authorList,
29+
ignoreGlobList, ignoreAuthorList, 2000000L);
30+
31+
List<ReportBranchData> branches = List.of(branch);
32+
ReportRepoConfiguration repo = new ReportRepoConfiguration("https://github.com/reposense/testrepo-Delta.git",
33+
groups, branches);
34+
35+
List<ReportRepoConfiguration> repos = List.of(repo);
36+
expectedReportConfig = new ReportConfiguration("Test RepoSense Report", repos);
37+
}
38+
939
@Test
1040
public void constructor_withValidInputs_success() {
1141
ReportConfiguration reportConfiguration = new ReportConfiguration("My Report", new ArrayList<>());
@@ -15,6 +45,24 @@ public void constructor_withValidInputs_success() {
1545
@Test
1646
public void getTitle_equalsDefaultReturnValue_success() {
1747
Assertions.assertSame(ReportConfiguration.DEFAULT_TITLE,
18-
new ReportConfiguration(null, new ArrayList<>()).getTitle());
48+
new ReportConfiguration(null, null).getTitle());
49+
}
50+
51+
@Test
52+
public void getBlurbMap_withValidInputs_success() {
53+
BlurbMap expectedBlurbMap = new BlurbMap();
54+
expectedBlurbMap.withRecord("https://github.com/reposense/testrepo-Delta/tree/master", "My project");
55+
56+
Assertions.assertEquals(expectedBlurbMap, expectedReportConfig.getBlurbMap());
57+
}
58+
59+
@Test
60+
public void equals_withSameObject_success() {
61+
Assertions.assertEquals(expectedReportConfig, expectedReportConfig);
62+
}
63+
64+
@Test
65+
public void equals_withDifferentObject_failure() {
66+
Assertions.assertNotEquals(new ReportConfiguration(), expectedReportConfig);
1967
}
2068
}

src/test/java/reposense/model/reportconfig/ReportGroupNameAndGlobsTest.java

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.junit.jupiter.api.Assertions;
66
import org.junit.jupiter.api.Test;
77

8+
import reposense.model.FileType;
9+
810
public class ReportGroupNameAndGlobsTest {
911
@Test
1012
public void constructor_withValidInputs_success() {
@@ -27,4 +29,24 @@ public void constructor_nullGlobs_throwsIllegalArgumentException() {
2729
public void constructor_nullGroupNameAndNullGlobs_throwsIllegalArgumentException() {
2830
Assertions.assertThrows(IllegalArgumentException.class, () -> new ReportGroupNameAndGlobs(null, null));
2931
}
32+
33+
@Test
34+
public void toFileType_success() {
35+
ReportGroupNameAndGlobs reportGroupNameAndGlobs = new ReportGroupNameAndGlobs("My Group", List.of("code"));
36+
Assertions.assertEquals(new FileType("My Group", List.of("code")), reportGroupNameAndGlobs.toFileType());
37+
}
38+
39+
@Test
40+
public void equals_sameObject_success() {
41+
ReportGroupNameAndGlobs reportGroupNameAndGlobs1 = new ReportGroupNameAndGlobs("My Group", List.of("code"));
42+
ReportGroupNameAndGlobs reportGroupNameAndGlobs2 = new ReportGroupNameAndGlobs("My Group", List.of("code"));
43+
Assertions.assertEquals(reportGroupNameAndGlobs1, reportGroupNameAndGlobs2);
44+
}
45+
46+
@Test
47+
public void equals_differentObject_failure() {
48+
ReportGroupNameAndGlobs reportGroupNameAndGlobs1 = new ReportGroupNameAndGlobs("My Group", List.of("code"));
49+
ReportGroupNameAndGlobs reportGroupNameAndGlobs2 = new ReportGroupNameAndGlobs("My Group", List.of("test"));
50+
Assertions.assertNotEquals(reportGroupNameAndGlobs1, reportGroupNameAndGlobs2);
51+
}
3052
}

src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java

+49
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import org.junit.jupiter.api.Assertions;
77
import org.junit.jupiter.api.Test;
88

9+
import reposense.model.FileType;
10+
import reposense.model.GroupConfiguration;
11+
import reposense.model.RepoLocation;
12+
import reposense.parser.exceptions.InvalidLocationException;
13+
914
public class ReportRepoConfigurationTest {
1015
@Test
1116
void constructor_nullRepo_throwsIllegalArgumentException() {
@@ -54,4 +59,48 @@ void getFullyQualifiedRepoNamesWithBlurbs_invalidUrl_throwsIllegalArgumentExcept
5459

5560
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getFullyQualifiedRepoNamesWithBlurbs());
5661
}
62+
63+
@Test
64+
void getGroupConfiguration_validGroups_returnsCorrectMapping() throws InvalidLocationException {
65+
List<ReportGroupNameAndGlobs> groups = List.of(
66+
new ReportGroupNameAndGlobs("group1", List.of("glob1", "glob2")),
67+
new ReportGroupNameAndGlobs("group2", List.of("glob3", "glob4"))
68+
);
69+
ReportRepoConfiguration config = new ReportRepoConfiguration(
70+
"https://github.com/test/repo.git", groups, null);
71+
72+
RepoLocation repoLocation = new RepoLocation("https://github.com/test/repo.git");
73+
GroupConfiguration expectedGroupConfiguration = new GroupConfiguration(repoLocation);
74+
expectedGroupConfiguration.addGroup(new FileType("group1", List.of("glob1", "glob2")));
75+
expectedGroupConfiguration.addGroup(new FileType("group2", List.of("glob3", "glob4")));
76+
77+
Assertions.assertEquals(expectedGroupConfiguration,
78+
config.getGroupConfiguration(new RepoLocation("https://github.com/test/repo.git")));
79+
}
80+
81+
@Test
82+
void equals_sameObject_success() {
83+
List<ReportGroupNameAndGlobs> groups = List.of(
84+
new ReportGroupNameAndGlobs("group1", List.of("glob1", "glob2")),
85+
new ReportGroupNameAndGlobs("group2", List.of("glob3", "glob4"))
86+
);
87+
ReportRepoConfiguration config = new ReportRepoConfiguration(
88+
"https://github.com/test/repo.git", groups, null);
89+
90+
Assertions.assertEquals(config, config);
91+
}
92+
93+
@Test
94+
void equals_differentObject_failure() {
95+
List<ReportGroupNameAndGlobs> groups = List.of(
96+
new ReportGroupNameAndGlobs("group1", List.of("glob1", "glob2")),
97+
new ReportGroupNameAndGlobs("group2", List.of("glob3", "glob4"))
98+
);
99+
ReportRepoConfiguration config1 = new ReportRepoConfiguration(
100+
"https://github.com/dev/repo.git", groups, null);
101+
ReportRepoConfiguration config2 = new ReportRepoConfiguration(
102+
"https://github.com/test/repo.git", groups, null);
103+
104+
Assertions.assertNotEquals(config1, config2);
105+
}
57106
}

src/test/java/reposense/parser/ReportConfigYamlParserTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@ public void reportConfig_parseValidYamlFile_success() throws Exception {
7474
ReportConfiguration reportConfig = new ReportConfigYamlParser().parse(VALID_REPORT_CONFIG);
7575
Assertions.assertEquals(expectedReportConfig, reportConfig);
7676
}
77+
78+
@Test
79+
public void getType_validType_success() {
80+
Assertions.assertEquals(ReportConfiguration.class, new ReportConfigYamlParser().getType());
81+
}
7782
}

0 commit comments

Comments
 (0)