Skip to content

Commit

Permalink
Use utils to build lottery report stubs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Dec 12, 2024
1 parent 062b95e commit 4218f20
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.quarkus.github.lottery;

import static io.quarkus.github.lottery.util.MockHelper.stubIssueList;
import static io.quarkus.github.lottery.util.MockHelper.stubReport;
import static io.quarkus.github.lottery.util.MockHelper.stubReportConfig;
import static io.quarkus.github.lottery.util.MockHelper.stubReportMaintenance;
import static io.quarkus.github.lottery.util.MockHelper.stubReportStewardship;
import static io.quarkus.github.lottery.util.MockHelper.stubReportTriage;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
Expand Down Expand Up @@ -296,11 +300,8 @@ void triage() throws IOException {

lotteryService.draw();

verify(notifierMock).send(new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 3, 2))),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty()));
verify(notifierMock).send(stubReportTriage(drawRef, "yrodiere", Optional.empty(),
stubIssueList(1, 3, 2)));

verify(historyServiceMock).append(drawRef, config, List.of(
new LotteryReport.Serialized(drawRef.instant(), "yrodiere",
Expand Down Expand Up @@ -341,11 +342,8 @@ void triage_issueAlreadyHasNonTimedOutNotification() throws IOException {

// Since the last notification for issue with number 3 didn't time out yet,
// it will be skipped and we'll notify about another issue.
verify(notifierMock).send(new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 2, 4))),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty()));
verify(notifierMock).send(stubReportTriage(drawRef, "yrodiere", Optional.empty(),
stubIssueList(1, 2, 4)));

verify(historyServiceMock).append(drawRef, config, List.of(
new LotteryReport.Serialized(drawRef.instant(), "yrodiere",
Expand Down Expand Up @@ -412,13 +410,11 @@ void maintenance() throws IOException {

lotteryService.draw();

verify(notifierMock).send(new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig("area/hibernate-orm", "area/hibernate-search"),
Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(101, 401, 102, 402))),
Optional.of(new LotteryReport.Bucket(stubIssueList(201, 501))),
Optional.of(new LotteryReport.Bucket(stubIssueList(301, 601, 302, 602, 303))),
Optional.empty()));
verify(notifierMock).send(stubReportMaintenance(drawRef, "yrodiere", Optional.empty(),
List.of("area/hibernate-orm", "area/hibernate-search"),
stubIssueList(101, 401, 102, 402),
stubIssueList(201, 501),
stubIssueList(301, 601, 302, 602, 303)));

verify(historyServiceMock).append(drawRef, config, List.of(
new LotteryReport.Serialized(drawRef.instant(), "yrodiere",
Expand Down Expand Up @@ -492,13 +488,11 @@ void maintenance_issueAlreadyHasTimedOutNotification() throws IOException {

// Since the last notification for issues with number 401, 201, 302 didn't time out yet,
// they will be skipped and we'll notify about the next issues instead.
verify(notifierMock).send(new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig("area/hibernate-orm", "area/hibernate-search"),
Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(101, 402, 102, 403))),
Optional.of(new LotteryReport.Bucket(stubIssueList(202, 501))),
Optional.of(new LotteryReport.Bucket(stubIssueList(301, 601, 303, 602, 304))),
Optional.empty()));
verify(notifierMock).send(stubReportMaintenance(drawRef, "yrodiere", Optional.empty(),
List.of("area/hibernate-orm", "area/hibernate-search"),
stubIssueList(101, 402, 102, 403),
stubIssueList(202, 501),
stubIssueList(301, 601, 303, 602, 304)));

verify(historyServiceMock).append(drawRef, config, List.of(
new LotteryReport.Serialized(drawRef.instant(), "yrodiere",
Expand Down Expand Up @@ -538,11 +532,8 @@ void stewardship() throws IOException {

lotteryService.draw();

verify(notifierMock).send(new LotteryReport(drawRef, "geoand", Optional.empty(),
stubReportConfig(),
Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 3, 2)))));
verify(notifierMock).send(stubReportStewardship(drawRef, "geoand", Optional.empty(),
stubIssueList(1, 3, 2)));

verify(historyServiceMock).append(drawRef, config, List.of(
new LotteryReport.Serialized(drawRef.instant(), "geoand",
Expand Down Expand Up @@ -583,11 +574,8 @@ void stewardship_issueAlreadyHasNonTimedOutNotification() throws IOException {

// Since the last notification for issue with number 3 didn't time out yet,
// it will be skipped and we'll notify about another issue.
verify(notifierMock).send(new LotteryReport(drawRef, "geoand", Optional.empty(),
stubReportConfig(),
Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 2, 4)))));
verify(notifierMock).send(stubReportStewardship(drawRef, "geoand", Optional.empty(),
stubIssueList(1, 2, 4)));

verify(historyServiceMock).append(drawRef, config, List.of(
new LotteryReport.Serialized(drawRef.instant(), "geoand",
Expand Down Expand Up @@ -657,23 +645,23 @@ void stewardship_doesNotAffectMaintenance() throws IOException {

lotteryService.draw();

verify(notifierMock).send(new LotteryReport(drawRef, "yrodiere", Optional.empty(),
verify(notifierMock).send(stubReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig("area/hibernate-search"),
Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(401, 402, 403, 404))),
Optional.of(new LotteryReport.Bucket(stubIssueList(501, 502))),
Optional.of(stubIssueList(401, 402, 403, 404)),
Optional.of(stubIssueList(501, 502)),
// Notifications to stewards don't prevent notifications to maintainers
Optional.of(new LotteryReport.Bucket(stubIssueList(601, 602, 603, 604, 605))),
Optional.of(stubIssueList(601, 602, 603, 604, 605)),
Optional.empty()));

verify(notifierMock).send(new LotteryReport(drawRef, "gsmet", Optional.empty(),
verify(notifierMock).send(stubReport(drawRef, "gsmet", Optional.empty(),
stubReportConfig(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
// Notifications to maintainers don't prevent notifications to stewards
Optional.of(new LotteryReport.Bucket(stubIssueList(401, 501, 601, 701)))));
Optional.of(stubIssueList(401, 501, 601, 701))));

verify(historyServiceMock).append(drawRef, config, List.of(
new LotteryReport.Serialized(drawRef.instant(), "yrodiere",
Expand Down
86 changes: 36 additions & 50 deletions src/test/java/io/quarkus/github/lottery/MessageFormatterTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.quarkus.github.lottery;

import static io.quarkus.github.lottery.util.MockHelper.stubIssueList;
import static io.quarkus.github.lottery.util.MockHelper.stubReport;
import static io.quarkus.github.lottery.util.MockHelper.stubReportConfig;
import static io.quarkus.github.lottery.util.MockHelper.stubReportMaintenance;
import static io.quarkus.github.lottery.util.MockHelper.stubReportStewardship;
import static io.quarkus.github.lottery.util.MockHelper.stubReportTriage;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
Expand Down Expand Up @@ -71,7 +75,7 @@ void formatNotificationTopicText() {

@Test
void formatNotificationTopicSuffixText() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.empty(),
var lotteryReport = stubReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig(),
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty());
Expand All @@ -81,7 +85,7 @@ void formatNotificationTopicSuffixText() {

@Test
void formatNotificationTopicSuffixText_exoticTimezone() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.of(ZoneId.of("America/Los_Angeles")),
var lotteryReport = stubReport(drawRef, "yrodiere", Optional.of(ZoneId.of("America/Los_Angeles")),
stubReportConfig(),
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty());
Expand All @@ -91,11 +95,8 @@ void formatNotificationTopicSuffixText_exoticTimezone() {

@Test
void formatNotificationBodyMarkdown_triage_empty() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig(),
Optional.of(new LotteryReport.Bucket(List.of())),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty());
var lotteryReport = stubReportTriage(drawRef, "yrodiere", Optional.empty(),
List.of());
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand All @@ -114,11 +115,8 @@ void formatNotificationBodyMarkdown_triage_empty() {

@Test
void formatNotificationBodyMarkdown_triage_simple() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 3))),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty());
var lotteryReport = stubReportTriage(drawRef, "yrodiere", Optional.empty(),
stubIssueList(1, 3));
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand All @@ -140,13 +138,11 @@ void formatNotificationBodyMarkdown_triage_simple() {

@Test
void formatNotificationBodyMarkdown_maintenance_empty() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig("area/hibernate-orm", "area/hibernate-search"),
Optional.empty(),
Optional.of(new LotteryReport.Bucket(List.of())),
Optional.of(new LotteryReport.Bucket(List.of())),
Optional.of(new LotteryReport.Bucket(List.of())),
Optional.empty());
var lotteryReport = stubReportMaintenance(drawRef, "yrodiere", Optional.empty(),
List.of("area/hibernate-orm", "area/hibernate-search"),
List.of(),
List.of(),
List.of());
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand Down Expand Up @@ -175,13 +171,11 @@ void formatNotificationBodyMarkdown_maintenance_empty() {

@Test
void formatNotificationBodyMarkdown_maintenance_someEmpty() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig("area/hibernate-orm", "area/hibernate-search"),
Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 3))),
Optional.of(new LotteryReport.Bucket(List.of())),
Optional.of(new LotteryReport.Bucket(List.of())),
Optional.empty());
var lotteryReport = stubReportMaintenance(drawRef, "yrodiere", Optional.empty(),
List.of("area/hibernate-orm", "area/hibernate-search"),
stubIssueList(1, 3),
List.of(),
List.of());
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand Down Expand Up @@ -213,13 +207,11 @@ void formatNotificationBodyMarkdown_maintenance_someEmpty() {

@Test
void formatNotificationBodyMarkdown_maintenance_simple() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig("area/hibernate-orm", "area/hibernate-search"),
Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 3))),
Optional.of(new LotteryReport.Bucket(stubIssueList(4, 5))),
Optional.of(new LotteryReport.Bucket(stubIssueList(2, 7))),
Optional.empty());
var lotteryReport = stubReportMaintenance(drawRef, "yrodiere", Optional.empty(),
List.of("area/hibernate-orm", "area/hibernate-search"),
stubIssueList(1, 3),
stubIssueList(4, 5),
stubIssueList(2, 7));
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand Down Expand Up @@ -257,11 +249,8 @@ void formatNotificationBodyMarkdown_maintenance_simple() {

@Test
void formatNotificationBodyMarkdown_stewardship_empty() {
var lotteryReport = new LotteryReport(drawRef, "geoand", Optional.empty(),
stubReportConfig(),
Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.of(new LotteryReport.Bucket(List.of())));
var lotteryReport = stubReportStewardship(drawRef, "geoand", Optional.empty(),
List.of());
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand All @@ -280,11 +269,8 @@ void formatNotificationBodyMarkdown_stewardship_empty() {

@Test
void formatNotificationBodyMarkdown_stewardship_simple() {
var lotteryReport = new LotteryReport(drawRef, "geoand", Optional.empty(),
stubReportConfig(),
Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 3))));
var lotteryReport = stubReportStewardship(drawRef, "geoand", Optional.empty(),
stubIssueList(1, 3));
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand All @@ -306,13 +292,13 @@ void formatNotificationBodyMarkdown_stewardship_simple() {

@Test
void formatNotificationBodyMarkdown_all() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.empty(),
var lotteryReport = stubReport(drawRef, "yrodiere", Optional.empty(),
stubReportConfig(),
Optional.of(new LotteryReport.Bucket(stubIssueList(1, 3))),
Optional.of(new LotteryReport.Bucket(stubIssueList(4, 5))),
Optional.of(new LotteryReport.Bucket(stubIssueList(2, 7))),
Optional.of(new LotteryReport.Bucket(stubIssueList(8, 9))),
Optional.of(new LotteryReport.Bucket(stubIssueList(10, 11))));
Optional.of(stubIssueList(1, 3)),
Optional.of(stubIssueList(4, 5)),
Optional.of(stubIssueList(2, 7)),
Optional.of(stubIssueList(8, 9)),
Optional.of(stubIssueList(10, 11)));
assertThat(messageFormatter.formatNotificationBodyMarkdown(lotteryReport, notificationRepoRef))
.isEqualTo(
"""
Expand Down Expand Up @@ -362,7 +348,7 @@ void formatNotificationBodyMarkdown_all() {

@Test
void formatNotificationBodyMarkdown_exoticTimezone() {
var lotteryReport = new LotteryReport(drawRef, "yrodiere", Optional.of(ZoneId.of("America/Los_Angeles")),
var lotteryReport = stubReport(drawRef, "yrodiere", Optional.of(ZoneId.of("America/Los_Angeles")),
stubReportConfig(),
Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(),
Expand Down
Loading

0 comments on commit 4218f20

Please sign in to comment.