Skip to content

Commit

Permalink
#1271 Replaced SendReply with lambda to comment.
Browse files Browse the repository at this point in the history
- reverted changes to Step API
  • Loading branch information
criske committed Nov 13, 2021
1 parent 1cd81b4 commit f5303a9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 62 deletions.
14 changes: 0 additions & 14 deletions self-api/src/main/java/com/selfxdsd/api/pm/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,4 @@ public interface Step {
* @param event Event that triggered everything.
*/
void perform(final Event event);


/**
* Creates a derived Step from "this" Step. The new Step may use additional
* data that's expected to come from the nearest previous step in chain.
* <br/>
* By default no new Step is created.
* @param data Data.
* @return Step.
*/
default Step derive(final Object data){
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,4 @@ public void perform(final Event event) {
LOG.debug("Reply sent successfully!");
this.next().perform(event);
}

@Override
public Step derive(final Object data) {
final Step derivedStep;
if (data instanceof String) {
final String extraInfo = data.toString();
derivedStep = new SendReply(
this.reply + "\n" + extraInfo,
this.next()
);
} else {
derivedStep = this;
}
return derivedStep;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,15 @@ public void issueLabelsChanged(final Event event) {
new TaskIsRegistered(
new IssueEstimationChanged(
new UpdateTaskEstimation(
new SendReply("Task estimation has been updated.")
changed -> changed
.issue()
.comments()
.post(String.format(
changed.project().language()
.reply("taskEstimationChanged.comment"),
changed.issue().estimation().minutes(),
LocalDateTime.now()
))
),
notChanged -> LOG.debug(
"Nothing to do on Issue label change."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ public void perform(final Event event) {
);
final int newEstimation = issue.estimation().minutes();
task.updateEstimation(newEstimation);
final String message = String.format(
LOG.debug(String.format(
"The estimation of Task [#%s-%s-%s] has been updated to %s min.",
issue.issueId(),
issue.repoFullName(),
issue.provider(),
newEstimation
);
LOG.debug(message);
this.next().derive(message).perform(event);
));
this.next().perform(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import java.math.BigDecimal;
Expand All @@ -44,9 +45,9 @@
*
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.1
* @checkstyle ExecutableStatementCount (2000 lines)
* @checkstyle ClassFanOutComplexity (2000 lines)
* @since 0.0.1
*/
public final class StoredProjectManagerTestCase {

Expand Down Expand Up @@ -318,7 +319,8 @@ public void pmUserReturnsUsername() {
final User pmUser = new StoredProjectManager.PmUser(manager);
MatcherAssert.assertThat(
pmUser.username(),
Matchers.is("zoeself"));
Matchers.is("zoeself")
);
}

/**
Expand All @@ -331,7 +333,8 @@ public void pmUserReturnsRole() {
);
MatcherAssert.assertThat(
pmUser.role(),
Matchers.is("user"));
Matchers.is("user")
);
}

/**
Expand Down Expand Up @@ -476,7 +479,7 @@ public Project project() {
Mockito.verify(comments, Mockito.times(1))
.post(
"@mihai thank you for reporting this. "
+ "I'll assign someone to take care of it soon."
+ "I'll assign someone to take care of it soon."
);
}

Expand Down Expand Up @@ -636,10 +639,10 @@ public Project project() {
Mockito.verify(comments, Mockito.times(1))
.post(
"@mihai thanks for reopening this, "
+ "I'll find someone to take a look at it. \n"
+ "However, please keep in mind that reopening tickets "
+ "is a bad practice. "
+ "Next time, please open a new ticket."
+ "I'll find someone to take a look at it. \n"
+ "However, please keep in mind that reopening tickets "
+ "is a bad practice. "
+ "Next time, please open a new ticket."
);
}

Expand Down Expand Up @@ -802,7 +805,7 @@ public Project project() {
Mockito.verify(comments, Mockito.times(1))
.post(
"@mihai thanks for reopening this PR, "
+ "I'll find someone to review it soon."
+ "I'll find someone to review it soon."
);
}

Expand Down Expand Up @@ -923,7 +926,7 @@ public void handlesReopenedIssueEventTaskOngoing() {
Mockito.when(all.register(issue)).thenThrow(
new IllegalStateException(
"There already is an ongoing task, "
+ "no new task should be registered!"
+ "no new task should be registered!"
)
);
final Project project = Mockito.mock(Project.class);
Expand Down Expand Up @@ -1004,7 +1007,7 @@ public void handlesReopenedIssueEventNoTaskLabel() {
.thenThrow(
new IllegalStateException(
"Issue has the 'no-task' label, Tasks.getById should not "
+ "be called!"
+ "be called!"
)
);
Mockito.when(all.register(issue)).thenThrow(
Expand Down Expand Up @@ -1222,7 +1225,7 @@ public void handlesUnassignedTasksEvent() {
* assignee if they have the appropriate Contract with the Project.
*/
@Test
public void handlesUnassignedTasksEventIssueAssigneeIsContributor(){
public void handlesUnassignedTasksEventIssueAssigneeIsContributor() {

final Contract contract = Mockito.mock(Contract.class);
final Contributor assignee = Mockito.mock(Contributor.class);
Expand Down Expand Up @@ -1309,7 +1312,7 @@ public void handlesUnassignedTasksEventIssueAssigneeIsContributor(){
* with the Project and elects new Contributor.
*/
@Test
public void handlesUnassignedTasksEventIssueAssigneeIsNotContributor(){
public void handlesUnassignedTasksEventIssueAssigneeIsNotContributor() {

final Contributor assignee = Mockito.mock(Contributor.class);
Mockito.when(assignee.username()).thenReturn("mihai");
Expand Down Expand Up @@ -1360,7 +1363,6 @@ public void handlesUnassignedTasksEventIssueAssigneeIsNotContributor(){
.thenReturn(assignee);



Mockito.when(project.contributors()).thenReturn(contributors);

final User owner = Mockito.mock(User.class);
Expand Down Expand Up @@ -1490,8 +1492,10 @@ public void verifiesStoredProjectManagerHashcode() {
5,
Mockito.mock(Storage.class)
);
MatcherAssert.assertThat(manager.hashCode(),
Matchers.equalTo(managerTwo.hashCode()));
MatcherAssert.assertThat(
manager.hashCode(),
Matchers.equalTo(managerTwo.hashCode())
);
}

/**
Expand Down Expand Up @@ -1530,7 +1534,7 @@ public void handlesAssignedTasksEventNoTasks() {
@Test
public void handlesAssignedTasksEventNoAssignedTasks() {
final List<Task> mocks = new ArrayList<>();
for(int idx = 0; idx<3; idx++) {
for (int idx = 0; idx < 3; idx++) {
final Task task = Mockito.mock(Task.class);
Mockito.when(task.assignee()).thenReturn(null);
mocks.add(task);
Expand All @@ -1554,7 +1558,7 @@ public void handlesAssignedTasksEventNoAssignedTasks() {
);
manager.assignedTasks(event);
Mockito.verify(project, Mockito.never()).language();
for(int idx = 0; idx<3; idx++) {
for (int idx = 0; idx < 3; idx++) {
final Task task = mocks.get(idx);
Mockito.verify(task, Mockito.times(1)).assignee();
Mockito.verify(task, Mockito.never()).issue();
Expand Down Expand Up @@ -1668,7 +1672,7 @@ public void handlesAssignedTasksEventDeadlineClosingReminder() {

final LocalDateTime assignmentDate = LocalDateTime.now();
final LocalDateTime deadlineDate = LocalDateTime.now().plusDays(10);
final Supplier<LocalDateTime> now = ()-> assignmentDate.plusDays(6);
final Supplier<LocalDateTime> now = () -> assignmentDate.plusDays(6);
Mockito.when(task.assignmentDate()).thenReturn(assignmentDate);
Mockito.when(task.deadline()).thenReturn(deadlineDate);

Expand Down Expand Up @@ -1725,7 +1729,7 @@ public void handlesAssignedTasksEventMissedDeadline() {

final LocalDateTime assignmentDate = LocalDateTime.now();
final LocalDateTime deadlineDate = LocalDateTime.now().plusDays(10);
final Supplier<LocalDateTime> now = ()-> deadlineDate.plusMinutes(1);
final Supplier<LocalDateTime> now = () -> deadlineDate.plusMinutes(1);
Mockito.when(task.assignmentDate()).thenReturn(assignmentDate);
Mockito.when(task.deadline()).thenReturn(deadlineDate);

Expand Down Expand Up @@ -1859,6 +1863,7 @@ public void handlesIssueLabelsChangesOfEstimation() {
Mockito.when(project.tasks()).thenReturn(tasks);
Mockito.when(project.repoFullName()).thenReturn("john/test");
Mockito.when(project.provider()).thenReturn(Provider.Names.GITHUB);
Mockito.when(project.language()).thenReturn(new English());

Mockito.when(issue.isClosed()).thenReturn(false);
Mockito.when(issue.issueId()).thenReturn("123");
Expand All @@ -1878,11 +1883,12 @@ public void handlesIssueLabelsChangesOfEstimation() {
manager.issueLabelsChanged(event);

Mockito.verify(task, Mockito.times(1)).updateEstimation(30);
final String reply = "> \n\n"
+ "Task estimation has been updated.\n"
+ "The estimation of Task [#123-john/test-github] has been updated "
+ "to 30 min.";
Mockito.verify(comments, Mockito.times(1)).post(reply);
final ArgumentCaptor<String> commentCaptor = ArgumentCaptor
.forClass(String.class);
Mockito.verify(comments, Mockito.times(1))
.post(commentCaptor.capture());
MatcherAssert.assertThat(commentCaptor.getValue(), Matchers
.startsWith("Estimation changed to ``30`` minutes at ``20"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ public void updatesTaskEstimation() {
Mockito.when(event.project()).thenReturn(project);

final Step next = Mockito.mock(Step.class);
final Step derived = Mockito.mock(Step.class);
Mockito.when(next.derive(Mockito.anyString())).thenReturn(derived);
final Step update = new UpdateTaskEstimation(next);
update.perform(event);

Mockito.verify(task, Mockito.times(1)).updateEstimation(125);
Mockito.verify(derived, Mockito.times(1)).perform(event);
Mockito.verify(next, Mockito.times(1)).perform(event);
}
}
1 change: 1 addition & 0 deletions self-core-impl/src/test/resources/responses_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ taskDeadlineReminder.comment=@%s Don't forget to close this ticket before the de
of the allowed period.
taskDeadlineMissed.comment=@%s Looks like you've missed the task deadline (%s). You are now resigned from this task.\n\n\
Please stop working on it, you will not be paid. I will assign it to someone else soon.
taskEstimationChanged.comment=Estimation changed to ``%s`` minutes at ``%s``.
issueClosed.comment=@%s this Issue is closed. If you want me to do anything with it, reopen it first.\n\n\
However, reopening issues is discouraged, please consider opening new tickets instead.
manualAssignment.comment=@%s please keep in mind that manual assignment of tickets is a bad practice \
Expand Down

0 comments on commit f5303a9

Please sign in to comment.