-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathChangelogSectionsTests.java
174 lines (157 loc) · 8.62 KB
/
ChangelogSectionsTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.githubchangeloggenerator;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import io.spring.githubchangeloggenerator.ApplicationProperties.IssueType;
import io.spring.githubchangeloggenerator.github.payload.Issue;
import io.spring.githubchangeloggenerator.github.payload.Label;
import io.spring.githubchangeloggenerator.github.service.Repository;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ChangelogSections}.
*
* @author Eleftheria Stein
* @author Phillip Webb
* @author Gary Russell
* @author Steven Sheehy
*/
class ChangelogSectionsTests {
private static final Repository REPO = Repository.of("org/name");
@Test
void collateWhenNoCustomSectionsUsesDefaultSections() {
Issue enhancement = createIssue("1", "enhancement");
Issue bug = createIssue("2", "bug");
Issue documentation = createIssue("3", "documentation");
Issue dependencyUpgrade = createIssue("4", "dependency-upgrade");
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.TITLE, null, null, null,
null, false);
ChangelogSections sections = new ChangelogSections(properties);
Map<ChangelogSection, List<Issue>> collated = sections
.collate(Arrays.asList(enhancement, bug, documentation, dependencyUpgrade));
Map<String, List<Issue>> bySection = getBySection(collated);
assertThat(bySection).containsOnlyKeys(":star: New Features", ":lady_beetle: Bug Fixes",
":notebook_with_decorative_cover: Documentation", ":hammer: Dependency Upgrades");
assertThat(bySection.get(":star: New Features")).containsExactly(enhancement);
assertThat(bySection.get(":lady_beetle: Bug Fixes")).containsExactly(bug);
assertThat(bySection.get(":notebook_with_decorative_cover: Documentation")).containsExactly(documentation);
assertThat(bySection.get(":hammer: Dependency Upgrades")).containsExactly(dependencyUpgrade);
}
@Test
void collateWhenHasCustomSectionsUsesDefinedSections() {
ApplicationProperties.Section breaksPassivitySection = new ApplicationProperties.Section(":rewind: Non-passive",
null, null, Collections.singleton("breaks-passivity"), IssueType.ANY);
ApplicationProperties.Section bugsSection = new ApplicationProperties.Section(":lady_beetle: Bug Fixes", null,
null, Collections.singleton("bug"), IssueType.ANY);
List<ApplicationProperties.Section> customSections = Arrays.asList(breaksPassivitySection, bugsSection);
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.TITLE, customSections,
null, null, null, false);
ChangelogSections sections = new ChangelogSections(properties);
Issue bug = createIssue("1", "bug");
Issue nonPassive = createIssue("1", "breaks-passivity");
Map<ChangelogSection, List<Issue>> collated = sections.collate(Arrays.asList(bug, nonPassive));
Map<String, List<Issue>> bySection = getBySection(collated);
assertThat(bySection).containsOnlyKeys(":lady_beetle: Bug Fixes", ":rewind: Non-passive");
}
@Test
void collateWhenHasCustomSectionsUsesDefinedSectionsAndDefault() {
ApplicationProperties.Section breaksPassivitySection = new ApplicationProperties.Section(":rewind: Non-passive",
null, null, Collections.singleton("breaks-passivity"), IssueType.ANY);
List<ApplicationProperties.Section> customSections = Arrays.asList(breaksPassivitySection);
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.TITLE, customSections,
null, null, null, true);
ChangelogSections sections = new ChangelogSections(properties);
Issue bug = createIssue("1", "bug");
Issue nonPassive = createIssue("1", "breaks-passivity");
Map<ChangelogSection, List<Issue>> collated = sections.collate(Arrays.asList(bug, nonPassive));
Map<String, List<Issue>> bySection = getBySection(collated);
assertThat(bySection).containsOnlyKeys(":lady_beetle: Bug Fixes", ":rewind: Non-passive");
}
@Test
void collateWhenNoIssuesInSectionExcludesSection() {
Issue bug = createIssue("1", "bug");
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.TITLE, null, null, null,
null, false);
ChangelogSections sections = new ChangelogSections(properties);
Map<ChangelogSection, List<Issue>> collated = sections.collate(Collections.singletonList(bug));
Map<String, List<Issue>> bySection = getBySection(collated);
assertThat(bySection.keySet()).containsExactly(":lady_beetle: Bug Fixes");
}
@Test
void collateWhenIssueDoesNotMatchAnySectionLabelThenExcludesIssue() {
Issue bug = createIssue("1", "bug");
Issue nonPassive = createIssue("2", "non-passive");
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.TITLE, null, null, null,
null, false);
ChangelogSections sections = new ChangelogSections(properties);
Map<ChangelogSection, List<Issue>> collated = sections.collate(Arrays.asList(bug, nonPassive));
Map<String, List<Issue>> bySection = getBySection(collated);
assertThat(bySection).containsOnlyKeys(":lady_beetle: Bug Fixes");
assertThat(bySection.get(":lady_beetle: Bug Fixes")).containsExactly(bug);
}
@Test
void collateWithDefaultsDoesNotAddIssueToMultipleSections() {
Issue bug = createIssue("1", "bug");
Issue highlight = createIssue("2", "highlight");
Issue bugAndHighlight = createIssue("3", "bug", "highlight");
ApplicationProperties.Section bugs = new ApplicationProperties.Section("Bugs", null, null,
Collections.singleton("bug"), IssueType.ANY);
ApplicationProperties.Section highlights = new ApplicationProperties.Section("Highlights", null, null,
Collections.singleton("highlight"), IssueType.ANY);
List<ApplicationProperties.Section> customSections = Arrays.asList(bugs, highlights);
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.TITLE, customSections,
null, null, null, false);
ChangelogSections sections = new ChangelogSections(properties);
Map<ChangelogSection, List<Issue>> collated = sections.collate(Arrays.asList(bug, highlight, bugAndHighlight));
Map<String, List<Issue>> bySection = getBySection(collated);
assertThat(bySection).containsOnlyKeys("Bugs", "Highlights");
assertThat(bySection.get("Bugs")).containsExactly(bug, bugAndHighlight);
assertThat(bySection.get("Highlights")).containsExactly(highlight);
}
@Test
void collateWithGroupsAddsIssuePerGroup() {
Issue bug = createIssue("1", "bug");
Issue highlight = createIssue("2", "highlight");
Issue bugAndHighlight = createIssue("3", "bug", "highlight");
ApplicationProperties.Section bugs = new ApplicationProperties.Section("Bugs", null, null,
Collections.singleton("bug"), IssueType.ANY);
ApplicationProperties.Section highlights = new ApplicationProperties.Section("Highlights", "highlights", null,
Collections.singleton("highlight"), IssueType.ANY);
List<ApplicationProperties.Section> customSections = Arrays.asList(bugs, highlights);
ApplicationProperties properties = new ApplicationProperties(REPO, MilestoneReference.TITLE, customSections,
null, null, null, false);
ChangelogSections sections = new ChangelogSections(properties);
Map<ChangelogSection, List<Issue>> collated = sections.collate(Arrays.asList(bug, highlight, bugAndHighlight));
Map<String, List<Issue>> bySection = getBySection(collated);
assertThat(bySection).containsOnlyKeys("Bugs", "Highlights");
assertThat(bySection.get("Bugs")).containsExactly(bug, bugAndHighlight);
assertThat(bySection.get("Highlights")).containsExactly(highlight, bugAndHighlight);
}
private Issue createIssue(String number, String... labels) {
return new Issue(number, "I am #" + number, null,
Arrays.stream(labels).map(Label::new).collect(Collectors.toList()), "https://example.com/" + number,
null, null);
}
private Map<String, List<Issue>> getBySection(Map<ChangelogSection, List<Issue>> collatedIssues) {
return collatedIssues.entrySet().stream()
.collect(Collectors.toMap((entry) -> entry.getKey().toString(), Entry::getValue));
}
}