// set estimate in issue
navigation.issue().setEstimates(ISSUE_KEY, "20", "20");
final WorklogInputBuilder worklogInputBuilder = createDefaulWorklogInputBuilder();
final IssueRestClient issueClient = client.getIssueClient();
// get issue
final Issue initialIssue = issueClient.getIssue(issueKey, pm);
// # First change - test auto
final WorklogInput worklogInput = worklogInputBuilder
.setIssueUri(initialIssue.getSelf())
.setMinutesSpent(2)
.build();
issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput, pm);
// check if estimate has changed
final Issue issueAfterFirstChange = issueClient.getIssue(issueKey, pm);
final Integer actualTimeSpentAfterChange = getTimeSpentMinutesNotNull(issueAfterFirstChange.getTimeTracking());
final Integer expectedTimeSpentAfterChange = getTimeSpentMinutesNotNull(initialIssue.getTimeTracking()) + worklogInput.getMinutesSpent();
assertEquals(expectedTimeSpentAfterChange, actualTimeSpentAfterChange);
final int actualRemainingEstimate = getRemainingEstimateMinutesNotNull(issueAfterFirstChange.getTimeTracking());
final int expectedRemaningEstimate = getRemainingEstimateMinutesNotNull(initialIssue.getTimeTracking()) - worklogInput.getMinutesSpent();
assertEquals(expectedRemaningEstimate, actualRemainingEstimate);
// # Second change - test new; also we want to be sure that logged time are added, and not set to given value
final Integer newEstimateValue = 15;
final WorklogInput worklogInput2 = worklogInputBuilder
.setIssueUri(initialIssue.getSelf())
.setMinutesSpent(2)
.setAdjustEstimateNew(newEstimateValue)
.build();
issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput2, pm);
// check if logged time has changed
final Issue issueAfterSecondChange = issueClient.getIssue(issueKey, pm);
final Integer actualTimeSpentAfterChange2 = getTimeSpentMinutesNotNull(issueAfterSecondChange.getTimeTracking());
final Integer expectedTimeSpentAfterChange2 = getTimeSpentMinutesNotNull(issueAfterFirstChange.getTimeTracking()) + worklogInput2.getMinutesSpent();
assertEquals(expectedTimeSpentAfterChange2, actualTimeSpentAfterChange2);
// check if estimate has changed
final Integer actualRemainingEstimate2 = getRemainingEstimateMinutesNotNull(issueAfterSecondChange.getTimeTracking());
assertEquals(newEstimateValue, actualRemainingEstimate2);
// # Third change - test leave
final WorklogInput worklogInput3 = worklogInputBuilder
.setIssueUri(initialIssue.getSelf())
.setMinutesSpent(2)
.setAdjustEstimateLeave()
.build();
issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput3, pm);
// check if logged time has changed
final Issue issueAfterThirdChange = issueClient.getIssue(issueKey, pm);
final Integer actualTimeSpentAfterChange3 = getTimeSpentMinutesNotNull(issueAfterThirdChange.getTimeTracking());
final Integer expectedTimeSpentAfterChange3 = getTimeSpentMinutesNotNull(issueAfterSecondChange.getTimeTracking()) + worklogInput3.getMinutesSpent();
assertEquals(expectedTimeSpentAfterChange3, actualTimeSpentAfterChange3);
// check if estimate has NOT changed
final Integer actualRemainingEstimate3 = getRemainingEstimateMinutesNotNull(issueAfterThirdChange.getTimeTracking());
final Integer expectedRemainingEstimate3 = getRemainingEstimateMinutesNotNull(issueAfterSecondChange.getTimeTracking());
assertEquals(expectedRemainingEstimate3, actualRemainingEstimate3);
// # Fourth change - test manual
final int reduceByValueManual = 7;
final WorklogInput worklogInput4 = worklogInputBuilder
.setIssueUri(initialIssue.getSelf())
.setMinutesSpent(2)
.setAdjustEstimateManual(reduceByValueManual)
.build();
issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput4, pm);
// check if logged time has changed
final Issue issueAfterFourthChange = issueClient.getIssue(issueKey, pm);
final Integer actualTimeSpentAfterChange4 = getTimeSpentMinutesNotNull(issueAfterFourthChange.getTimeTracking());
final Integer expectedTimeSpentAfterChange4 = getTimeSpentMinutesNotNull(issueAfterThirdChange.getTimeTracking()) + worklogInput4.getMinutesSpent();
assertEquals(expectedTimeSpentAfterChange4, actualTimeSpentAfterChange4);
// check if estimate has NOT changed