Skip to content

Commit

Permalink
#1271 Reply with estimation changed value.
Browse files Browse the repository at this point in the history
- Unignored test
- Updated Step api to be able to receive data from the previous Step in chain.
  • Loading branch information
criske committed Nov 12, 2021
1 parent 0de74ab commit 1cd81b4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
13 changes: 13 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/pm/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ public interface Step {
*/
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,4 +92,19 @@ 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 @@ -660,7 +660,7 @@ public void issueLabelsChanged(final Event event) {
isClosed -> LOG.debug(
"Can't handle labels changes on a closed issue."
),
isNotClosed -> new TaskIsRegistered(
new TaskIsRegistered(
new IssueEstimationChanged(
new UpdateTaskEstimation(
new SendReply("Task estimation has been updated.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ public void perform(final Event event) {
);
final int newEstimation = issue.estimation().minutes();
task.updateEstimation(newEstimation);
LOG.debug(String.format(
final String message = String.format(
"The estimation of Task [#%s-%s-%s] has been updated to %s min.",
issue.issueId(),
issue.repoFullName(),
issue.provider(),
newEstimation
));
this.next().perform(event);
);
LOG.debug(message);
this.next().derive(message).perform(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.selfxdsd.core.projects.English;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;

Expand Down Expand Up @@ -1829,11 +1828,8 @@ public void unableToRegisterToken() {

/**
* A PM can update a task estimation if issue estimation has changed.
* @todo #1265:60min Unignore/update this test once the whole functionality
* is refactored to use Steps.
*/
@Test
@Ignore
public void handlesIssueLabelsChangesOfEstimation() {
final ProjectManager manager = new StoredProjectManager(
1,
Expand All @@ -1846,19 +1842,30 @@ public void handlesIssueLabelsChangesOfEstimation() {
Mockito.mock(Storage.class)
);
final Event event = Mockito.mock(Event.class);
final Comment comment = Mockito.mock(Comment.class);
final Comments comments = Mockito.mock(Comments.class);
final Issue issue = Mockito.mock(Issue.class);
final Project project = Mockito.mock(Project.class);
final Tasks tasks = Mockito.mock(Tasks.class);
final Task task = Mockito.mock(Task.class);

Mockito.when(event.issue()).thenReturn(issue);
Mockito.when(event.project()).thenReturn(project);
Mockito.when(event.comment()).thenReturn(comment);

Mockito.when(comment.author()).thenReturn("john");
Mockito.when(comment.body()).thenReturn("");

Mockito.when(project.tasks()).thenReturn(tasks);
Mockito.when(project.repoFullName()).thenReturn("john/test");
Mockito.when(project.provider()).thenReturn(Provider.Names.GITHUB);

Mockito.when(issue.isClosed()).thenReturn(false);
Mockito.when(issue.issueId()).thenReturn("123");
Mockito.when(issue.provider()).thenReturn(Provider.Names.GITHUB);
Mockito.when(issue.repoFullName()).thenReturn("john/test");
Mockito.when(issue.estimation()).thenReturn(() -> 30);
Mockito.when(issue.comments()).thenReturn(comments);

Mockito.when(tasks.getById(
"123",
Expand All @@ -1871,6 +1878,11 @@ 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class UpdateTaskEstimationTestCase {

/**
* UpdateTaskEstimation can update the Task's estimation.
* @checkstyle ExecutableStatementCount (50 lines)
*/
@Test
public void updatesTaskEstimation() {
Expand All @@ -61,10 +62,12 @@ 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(next, Mockito.times(1)).perform(event);
Mockito.verify(derived, Mockito.times(1)).perform(event);
}
}

1 comment on commit 1cd81b4

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@criske I've closed the Issues [#1271] since their to-dos disappeared from the code.

The to-dos may have been removed in an earlier commit, but I've found it just now.

Please sign in to comment.