@Test public void should_reload_issue_and_resolve_conflict() { DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setType(RuleType.CODE_SMELL) .setRuleKey(RuleKey.of("squid", "AvoidCycles")) .setComponentKey("struts:org.apache.struts.Action") .setNew(false) .setStatus(Issue.STATUS_OPEN); // Issue as seen and changed by end-user IssueMapper mapper = mock(IssueMapper.class); when(mapper.selectByKey("ABCDE")) .thenReturn( new IssueDto() .setKee("ABCDE") .setType(RuleType.CODE_SMELL) .setRuleId(10) .setRuleKey("squid", "AvoidCycles") .setComponentKey("struts:org.apache.struts.Action") .setLine(10) .setStatus(Issue.STATUS_OPEN) // field changed by user .setAssignee("arthur")); new UpdateConflictResolver().resolve(issue, mapper); ArgumentCaptor<IssueDto> argument = ArgumentCaptor.forClass(IssueDto.class); verify(mapper).update(argument.capture()); IssueDto updatedIssue = argument.getValue(); assertThat(updatedIssue.getKee()).isEqualTo("ABCDE"); assertThat(updatedIssue.getAssignee()).isEqualTo("arthur"); }
private void resolveAssignee(IssueDto dbIssue, DefaultIssue issue) { issue.setAssignee(dbIssue.getAssignee()); }