Skip to content

Commit

Permalink
#1270 UpdateTaskEstimation implemented and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 31, 2021
1 parent 3edc272 commit eae5660
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
package com.selfxdsd.core.managers;

import com.selfxdsd.api.Event;
import com.selfxdsd.api.Issue;
import com.selfxdsd.api.Project;
import com.selfxdsd.api.Task;
import com.selfxdsd.api.pm.Intermediary;
import com.selfxdsd.api.pm.Step;
import org.slf4j.Logger;
Expand All @@ -33,8 +36,6 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.96
* @todo #1265:60min Implement and test the method perform from this class.
* It should simply update a task's estimation and forward to the next step.
*/
public final class UpdateTaskEstimation extends Intermediary {

Expand All @@ -55,6 +56,24 @@ public UpdateTaskEstimation(final Step next) {

@Override
public void perform(final Event event) {
throw new UnsupportedOperationException("Not yet implemented.");
final Issue issue = event.issue();
final String issueId = issue.issueId();
final Project project = event.project();
final Task task = project.tasks().getById(
issueId,
project.repoFullName(),
project.provider(),
issue.isPullRequest()
);
final int newEstimation = issue.estimation().minutes();
task.updateEstimation(newEstimation);
LOG.debug(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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core.managers;

import com.selfxdsd.api.*;
import com.selfxdsd.api.pm.Step;
import org.junit.Test;
import org.mockito.Mockito;

/**
* Unit tests for {@link UpdateTaskEstimation}.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.96
*/
public final class UpdateTaskEstimationTestCase {

/**
* UpdateTaskEstimation can update the Task's estimation.
*/
@Test
public void updatesTaskEstimation() {
final Task task = Mockito.mock(Task.class);

final Event event = Mockito.mock(Event.class);
final Issue issue = Mockito.mock(Issue.class);
Mockito.when(issue.issueId()).thenReturn("1");
final Estimation estimation = Mockito.mock(Estimation.class);
Mockito.when(estimation.minutes()).thenReturn(125);
Mockito.when(issue.estimation()).thenReturn(estimation);
Mockito.when(event.issue()).thenReturn(issue);

final Tasks tasks = Mockito.mock(Tasks.class);
Mockito.when(
tasks.getById("1", "john/test", "github", Boolean.FALSE)
).thenReturn(task);
final Project project = Mockito.mock(Project.class);
Mockito.when(project.repoFullName()).thenReturn("john/test");
Mockito.when(project.provider()).thenReturn("github");
Mockito.when(project.tasks()).thenReturn(tasks);
Mockito.when(event.project()).thenReturn(project);

final Step next = Mockito.mock(Step.class);
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);
}
}

2 comments on commit eae5660

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

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

@amihaiemil I've opened the Issues [#1273, #1274, #1275] for the newly added to-dos.

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

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

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

@amihaiemil I've closed the Issues [#1270] 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.