Skip to content

Commit

Permalink
Merge pull request #1284 from criske/#1271
Browse files Browse the repository at this point in the history
#1271 Reply with estimation changed value.
  • Loading branch information
amihaiemil committed Nov 14, 2021
2 parents 0de74ab + f5303a9 commit 52f2e11
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
1 change: 0 additions & 1 deletion self-api/src/main/java/com/selfxdsd/api/pm/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ public interface Step {
* @param event Event that triggered everything.
*/
void perform(final Event event);

}
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,18 @@ 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.")
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 @@ -29,8 +29,8 @@
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.ArgumentCaptor;
import org.mockito.Mockito;

import java.math.BigDecimal;
Expand All @@ -45,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 @@ -319,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 @@ -332,7 +333,8 @@ public void pmUserReturnsRole() {
);
MatcherAssert.assertThat(
pmUser.role(),
Matchers.is("user"));
Matchers.is("user")
);
}

/**
Expand Down Expand Up @@ -477,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 @@ -637,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 @@ -803,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 @@ -924,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 @@ -1005,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 @@ -1223,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 @@ -1310,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 @@ -1361,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 @@ -1491,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 @@ -1531,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 @@ -1555,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 @@ -1669,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 @@ -1726,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 @@ -1829,11 +1832,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 +1846,31 @@ 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(project.language()).thenReturn(new English());

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 +1883,12 @@ public void handlesIssueLabelsChangesOfEstimation() {
manager.issueLabelsChanged(event);

Mockito.verify(task, Mockito.times(1)).updateEstimation(30);
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 @@ -37,6 +37,7 @@ public final class UpdateTaskEstimationTestCase {

/**
* UpdateTaskEstimation can update the Task's estimation.
* @checkstyle ExecutableStatementCount (50 lines)
*/
@Test
public void updatesTaskEstimation() {
Expand Down
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 52f2e11

Please sign in to comment.