Skip to content

Commit

Permalink
Merge pull request #55 from The-Huginn/issue-54
Browse files Browse the repository at this point in the history
Don't require components field in config file
  • Loading branch information
xstefank authored Feb 21, 2024
2 parents b1e818d + 369fa89 commit b2894e3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jboss/config/LotteryConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public record Project(
@JsonUnwrapped @JsonProperty(access = JsonProperty.Access.READ_ONLY) Participation participation) {
// https://stackoverflow.com/a/71539100/6692043
@JsonCreator
public Project(@JsonProperty(required = true) String project, @JsonProperty(required = true) Set<String> components,
public Project(@JsonProperty(required = true) String project, Set<String> components,
@JsonProperty(required = true) int maxIssues) {
this(project, components, new Participation(maxIssues));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jboss/draw/Lottery.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public void run(EveryIssueState collectedIssues) {

private boolean isAssignable(Issue issue, Participant participant) {
Tuple2<Integer, Set<String>> issuesComponentsKey = participant.getProjectComponents(issue.getProject());
return issuesComponentsKey.getItem1() != 0 &&
boolean betweenComponents = issuesComponentsKey.getItem2() == null ||
issuesComponentsKey.getItem2().containsAll(issue.getComponents());
return issuesComponentsKey.getItem1() != 0 && betweenComponents;
}

public static String createEmailText(String email, List<Issue> issues) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/jboss/set/draw/LotteryDrawingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ public void testAssigningOneIssue() throws Exception {
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(0))), sent.get(0).getText());
}

@Test
public void testAssigningOneIssueOnlyProjectDefined() throws Exception {
String email = "[email protected]";
String configFile = """
delay: P14D
participants:
- email: [email protected]
days: [MONDAY]
projects:
- project: WFLY
maxIssues: 5""";

LotteryConfig testLotteryConfig = objectMapper.readValue(configFile, LotteryConfig.class);
when(lotteryConfigProducer.getLotteryConfig()).thenReturn(testLotteryConfig);

StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));

int exitCode = cmd.execute();
assertEquals(0, exitCode);

List<Mail> sent = mailbox.getMailsSentTo(email);
assertEquals(1, sent.size());
assertEquals(Lottery.EMAIL_SUBJECT, sent.get(0).getSubject());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(0))), sent.get(0).getText());
}

@Test
public void testAssigningAllIssues() throws Exception {
String email = "[email protected]";
Expand Down

0 comments on commit b2894e3

Please sign in to comment.